Skip to content

Commit

Permalink
PublicRequestTypes: rename PaymentMethod to PaymentType
Browse files Browse the repository at this point in the history
  • Loading branch information
danimoh committed Nov 30, 2019
1 parent cf662a5 commit 33e401f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
11 changes: 9 additions & 2 deletions client/HubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@ import {
ExportResult,
SignedMessage,
Currency,
PaymentMethod,
PaymentType,
} from '../src/lib/PublicRequestTypes';

export default class HubApi<DB extends BehaviorType = BehaviorType.POPUP> { // DB: Default Behavior
public static readonly RequestType = RequestType;
public static readonly RedirectRequestBehavior = RedirectRequestBehavior;
public static readonly Currency = Currency;
public static readonly PaymentMethod = PaymentMethod;
public static readonly PaymentType = PaymentType;
public static readonly MSG_PREFIX = '\x16Nimiq Signed Message:\n';

/** @deprecated */
public static get PaymentMethod() {
console.warn('PaymentMethod has been renamed to PaymentType. Access via HubApi.PaymentMethod will soon '
+ 'get disabled. Use HubApi.PaymentType instead.');
return PaymentType;
}

private static get DEFAULT_ENDPOINT() {
const originArray = location.origin.split('.');
originArray.shift();
Expand Down
8 changes: 4 additions & 4 deletions src/lib/PublicRequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface NimiqCheckoutRequest extends BasicRequest {
validityDuration?: number;
}

export enum PaymentMethod {
export enum PaymentType {
DIRECT,
OASIS,
}
Expand All @@ -78,7 +78,7 @@ export type ProtocolSpecificsForCurrency<C extends Currency> =
: C extends Currency.ETH ? EtherSpecifics
: undefined;

export interface PaymentOptions<C extends Currency, T extends PaymentMethod> {
export interface PaymentOptions<C extends Currency, T extends PaymentType> {
type: T;
currency: C;
expires?: number;
Expand All @@ -94,8 +94,8 @@ export type AvailablePaymentOptions = NimiqDirectPaymentOptions
| EtherDirectPaymentOptions
| BitcoinDirectPaymentOptions;

export type PaymentOptionsForCurrencyAndType<C extends Currency, T extends PaymentMethod> =
T extends PaymentMethod.DIRECT ?
export type PaymentOptionsForCurrencyAndType<C extends Currency, T extends PaymentType> =
T extends PaymentType.DIRECT ?
C extends Currency.NIM ? NimiqDirectPaymentOptions
: C extends Currency.BTC ? BitcoinDirectPaymentOptions
: C extends Currency.ETH ? EtherDirectPaymentOptions
Expand Down
10 changes: 5 additions & 5 deletions src/lib/RequestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ExportRequest,
RpcRequest,
Currency,
PaymentMethod,
PaymentType,
RequestType,
NimiqCheckoutRequest,
MultiCurrencyCheckoutRequest,
Expand Down Expand Up @@ -103,7 +103,7 @@ export class RequestParser {
time: Date.now(),
paymentOptions: [new ParsedNimiqDirectPaymentOptions({
currency: Currency.NIM,
type: PaymentMethod.DIRECT,
type: PaymentType.DIRECT,
amount: checkoutRequest.value.toString(),
expires: 0, // unused for NimiqCheckoutRequests
protocolSpecific: {
Expand Down Expand Up @@ -204,7 +204,7 @@ export class RequestParser {
currencies.add(option.currency);
}
switch (option.type) {
case PaymentMethod.DIRECT:
case PaymentType.DIRECT:
switch (option.currency) {
case Currency.NIM:
return new ParsedNimiqDirectPaymentOptions(option, data);
Expand All @@ -216,7 +216,7 @@ export class RequestParser {
throw new Error(`Currency ${(option as any).currency} not supported`);
}
default:
throw new Error(`PaymentMethod ${(option as any).type} not supported`);
throw new Error(`PaymentType ${(option as any).type} not supported`);
}
}),
} as ParsedCheckoutRequest;
Expand Down Expand Up @@ -342,7 +342,7 @@ export class RequestParser {
fiatCurrency: checkoutRequest.fiatCurrency || undefined,
paymentOptions: checkoutRequest.paymentOptions.map((option) => {
switch (option.type) {
case PaymentMethod.DIRECT:
case PaymentType.DIRECT:
return option.raw();
default:
throw new Error('paymentOption.type not supported');
Expand Down
10 changes: 5 additions & 5 deletions src/lib/RequestTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type BigInteger = import('big-integer').BigInteger; // imports only the type without bundling
import { FormattableNumber, toNonScientificNumberString } from '@nimiq/utils';
import { isMilliseconds } from './Helpers';
import { Currency, PaymentMethod, PaymentOptionsForCurrencyAndType, RequestType } from './PublicRequestTypes';
import { Currency, PaymentType, PaymentOptionsForCurrencyAndType, RequestType } from './PublicRequestTypes';
import { ParsedNimiqSpecifics, ParsedNimiqDirectPaymentOptions } from './paymentOptions/NimiqPaymentOptions';
import { ParsedEtherSpecifics, ParsedEtherDirectPaymentOptions } from './paymentOptions/EtherPaymentOptions';
import { ParsedBitcoinSpecifics, ParsedBitcoinDirectPaymentOptions } from './paymentOptions/BitcoinPaymentOptions';
Expand Down Expand Up @@ -36,7 +36,7 @@ export type ParsedProtocolSpecificsForCurrency<C extends Currency> =
: C extends Currency.ETH ? ParsedEtherSpecifics
: undefined;

export interface ParsedPaymentOptions<C extends Currency, T extends PaymentMethod> {
export interface ParsedPaymentOptions<C extends Currency, T extends PaymentType> {
readonly currency: C;
readonly type: T;
readonly decimals: number;
Expand All @@ -49,7 +49,7 @@ export interface ParsedPaymentOptions<C extends Currency, T extends PaymentMetho
raw(): PaymentOptionsForCurrencyAndType<C, T>;
}

export abstract class ParsedPaymentOptions<C extends Currency, T extends PaymentMethod>
export abstract class ParsedPaymentOptions<C extends Currency, T extends PaymentType>
implements ParsedPaymentOptions<C, T> {

protected constructor(options: PaymentOptionsForCurrencyAndType<C, T>) {
Expand Down Expand Up @@ -98,8 +98,8 @@ export type AvailableParsedPaymentOptions = ParsedNimiqDirectPaymentOptions
| ParsedEtherDirectPaymentOptions
| ParsedBitcoinDirectPaymentOptions;

export type ParsedPaymentOptionsForCurrencyAndType<C extends Currency, T extends PaymentMethod> =
T extends PaymentMethod.DIRECT ?
export type ParsedPaymentOptionsForCurrencyAndType<C extends Currency, T extends PaymentType> =
T extends PaymentType.DIRECT ?
C extends Currency.NIM ? ParsedNimiqDirectPaymentOptions
: C extends Currency.BTC ? ParsedBitcoinDirectPaymentOptions
: C extends Currency.ETH ? ParsedEtherDirectPaymentOptions
Expand Down
10 changes: 5 additions & 5 deletions src/lib/paymentOptions/BitcoinPaymentOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Currency, PaymentMethod, PaymentOptions } from '../PublicRequestTypes';
import { Currency, PaymentType, PaymentOptions } from '../PublicRequestTypes';
import { ParsedPaymentOptions } from '../RequestTypes';
import { toNonScientificNumberString } from '@nimiq/utils';

Expand All @@ -13,9 +13,9 @@ export type ParsedBitcoinSpecifics = Pick<BitcoinSpecifics, 'recipient'> & {
feePerByte?: number;
};

export type BitcoinDirectPaymentOptions = PaymentOptions<Currency.BTC, PaymentMethod.DIRECT>;
export type BitcoinDirectPaymentOptions = PaymentOptions<Currency.BTC, PaymentType.DIRECT>;

export class ParsedBitcoinDirectPaymentOptions extends ParsedPaymentOptions<Currency.BTC, PaymentMethod.DIRECT> {
export class ParsedBitcoinDirectPaymentOptions extends ParsedPaymentOptions<Currency.BTC, PaymentType.DIRECT> {
public amount: number;

public constructor(options: BitcoinDirectPaymentOptions) {
Expand Down Expand Up @@ -64,8 +64,8 @@ export class ParsedBitcoinDirectPaymentOptions extends ParsedPaymentOptions<Curr
return Currency.BTC;
}

public get type(): PaymentMethod.DIRECT {
return PaymentMethod.DIRECT;
public get type(): PaymentType.DIRECT {
return PaymentType.DIRECT;
}

public get decimals(): number {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/paymentOptions/EtherPaymentOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import bigInt from 'big-integer';
import { Currency, PaymentMethod, PaymentOptions } from '../PublicRequestTypes';
import { Currency, PaymentType, PaymentOptions } from '../PublicRequestTypes';
import { ParsedPaymentOptions } from '../RequestTypes';
import { toNonScientificNumberString } from '@nimiq/utils';

Expand All @@ -14,9 +14,9 @@ export type ParsedEtherSpecifics = Pick<EtherSpecifics, 'recipient'> & {
gasPrice?: bigInt.BigInteger;
};

export type EtherDirectPaymentOptions = PaymentOptions<Currency.ETH, PaymentMethod.DIRECT>;
export type EtherDirectPaymentOptions = PaymentOptions<Currency.ETH, PaymentType.DIRECT>;

export class ParsedEtherDirectPaymentOptions extends ParsedPaymentOptions<Currency.ETH, PaymentMethod.DIRECT> {
export class ParsedEtherDirectPaymentOptions extends ParsedPaymentOptions<Currency.ETH, PaymentType.DIRECT> {
public amount: bigInt.BigInteger;

public constructor(options: EtherDirectPaymentOptions) {
Expand Down Expand Up @@ -55,8 +55,8 @@ export class ParsedEtherDirectPaymentOptions extends ParsedPaymentOptions<Curren
return Currency.ETH;
}

public get type(): PaymentMethod.DIRECT {
return PaymentMethod.DIRECT;
public get type(): PaymentType.DIRECT {
return PaymentType.DIRECT;
}

public get decimals(): number {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/paymentOptions/NimiqPaymentOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TX_VALIDITY_WINDOW, TX_MIN_VALIDITY_DURATION } from '../Constants';
import { Currency, PaymentMethod, PaymentOptions } from '../PublicRequestTypes';
import { Currency, PaymentType, PaymentOptions } from '../PublicRequestTypes';
import { ParsedPaymentOptions } from '../RequestTypes';
import { toNonScientificNumberString } from '@nimiq/utils';

Expand All @@ -22,9 +22,9 @@ export type ParsedNimiqSpecifics = Omit<NimiqSpecifics, 'sender' | 'recipient' |
feePerByte: number,
};

export type NimiqDirectPaymentOptions = PaymentOptions<Currency.NIM, PaymentMethod.DIRECT>;
export type NimiqDirectPaymentOptions = PaymentOptions<Currency.NIM, PaymentType.DIRECT>;

export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions<Currency.NIM, PaymentMethod.DIRECT> {
export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions<Currency.NIM, PaymentType.DIRECT> {
public amount: number;
private extraData: Uint8Array;

Expand Down Expand Up @@ -130,8 +130,8 @@ export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions<Curren
return Currency.NIM;
}

public get type(): PaymentMethod.DIRECT {
return PaymentMethod.DIRECT;
public get type(): PaymentType.DIRECT {
return PaymentType.DIRECT;
}

public get decimals(): number {
Expand Down

0 comments on commit 33e401f

Please sign in to comment.