diff --git a/client/HubApi.ts b/client/HubApi.ts index e11a1c1b3..a4a9dfe23 100644 --- a/client/HubApi.ts +++ b/client/HubApi.ts @@ -24,16 +24,23 @@ import { ExportResult, SignedMessage, Currency, - PaymentMethod, + PaymentType, } from '../src/lib/PublicRequestTypes'; export default class HubApi { // 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(); diff --git a/src/lib/PublicRequestTypes.ts b/src/lib/PublicRequestTypes.ts index a27eb28f9..ec26d94ce 100644 --- a/src/lib/PublicRequestTypes.ts +++ b/src/lib/PublicRequestTypes.ts @@ -61,7 +61,7 @@ export interface NimiqCheckoutRequest extends BasicRequest { validityDuration?: number; } -export enum PaymentMethod { +export enum PaymentType { DIRECT, OASIS, } @@ -78,7 +78,7 @@ export type ProtocolSpecificsForCurrency = : C extends Currency.ETH ? EtherSpecifics : undefined; -export interface PaymentOptions { +export interface PaymentOptions { type: T; currency: C; expires?: number; @@ -94,8 +94,8 @@ export type AvailablePaymentOptions = NimiqDirectPaymentOptions | EtherDirectPaymentOptions | BitcoinDirectPaymentOptions; -export type PaymentOptionsForCurrencyAndType = - T extends PaymentMethod.DIRECT ? +export type PaymentOptionsForCurrencyAndType = + T extends PaymentType.DIRECT ? C extends Currency.NIM ? NimiqDirectPaymentOptions : C extends Currency.BTC ? BitcoinDirectPaymentOptions : C extends Currency.ETH ? EtherDirectPaymentOptions diff --git a/src/lib/RequestParser.ts b/src/lib/RequestParser.ts index 9104844f9..38b936b87 100644 --- a/src/lib/RequestParser.ts +++ b/src/lib/RequestParser.ts @@ -11,7 +11,7 @@ import { ExportRequest, RpcRequest, Currency, - PaymentMethod, + PaymentType, RequestType, NimiqCheckoutRequest, MultiCurrencyCheckoutRequest, @@ -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: { @@ -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); @@ -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; @@ -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'); diff --git a/src/lib/RequestTypes.ts b/src/lib/RequestTypes.ts index cfa6b827e..d0e3901ad 100644 --- a/src/lib/RequestTypes.ts +++ b/src/lib/RequestTypes.ts @@ -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'; @@ -36,7 +36,7 @@ export type ParsedProtocolSpecificsForCurrency = : C extends Currency.ETH ? ParsedEtherSpecifics : undefined; -export interface ParsedPaymentOptions { +export interface ParsedPaymentOptions { readonly currency: C; readonly type: T; readonly decimals: number; @@ -49,7 +49,7 @@ export interface ParsedPaymentOptions; } -export abstract class ParsedPaymentOptions +export abstract class ParsedPaymentOptions implements ParsedPaymentOptions { protected constructor(options: PaymentOptionsForCurrencyAndType) { @@ -98,8 +98,8 @@ export type AvailableParsedPaymentOptions = ParsedNimiqDirectPaymentOptions | ParsedEtherDirectPaymentOptions | ParsedBitcoinDirectPaymentOptions; -export type ParsedPaymentOptionsForCurrencyAndType = - T extends PaymentMethod.DIRECT ? +export type ParsedPaymentOptionsForCurrencyAndType = + T extends PaymentType.DIRECT ? C extends Currency.NIM ? ParsedNimiqDirectPaymentOptions : C extends Currency.BTC ? ParsedBitcoinDirectPaymentOptions : C extends Currency.ETH ? ParsedEtherDirectPaymentOptions diff --git a/src/lib/paymentOptions/BitcoinPaymentOptions.ts b/src/lib/paymentOptions/BitcoinPaymentOptions.ts index f413692f1..faf12eb88 100644 --- a/src/lib/paymentOptions/BitcoinPaymentOptions.ts +++ b/src/lib/paymentOptions/BitcoinPaymentOptions.ts @@ -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'; @@ -13,9 +13,9 @@ export type ParsedBitcoinSpecifics = Pick & { feePerByte?: number; }; -export type BitcoinDirectPaymentOptions = PaymentOptions; +export type BitcoinDirectPaymentOptions = PaymentOptions; -export class ParsedBitcoinDirectPaymentOptions extends ParsedPaymentOptions { +export class ParsedBitcoinDirectPaymentOptions extends ParsedPaymentOptions { public amount: number; public constructor(options: BitcoinDirectPaymentOptions) { @@ -64,8 +64,8 @@ export class ParsedBitcoinDirectPaymentOptions extends ParsedPaymentOptions & { gasPrice?: bigInt.BigInteger; }; -export type EtherDirectPaymentOptions = PaymentOptions; +export type EtherDirectPaymentOptions = PaymentOptions; -export class ParsedEtherDirectPaymentOptions extends ParsedPaymentOptions { +export class ParsedEtherDirectPaymentOptions extends ParsedPaymentOptions { public amount: bigInt.BigInteger; public constructor(options: EtherDirectPaymentOptions) { @@ -55,8 +55,8 @@ export class ParsedEtherDirectPaymentOptions extends ParsedPaymentOptions; +export type NimiqDirectPaymentOptions = PaymentOptions; -export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions { +export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions { public amount: number; private extraData: Uint8Array; @@ -130,8 +130,8 @@ export class ParsedNimiqDirectPaymentOptions extends ParsedPaymentOptions