@coin-voyage/shared 2.4.2 → 2.4.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,4 @@
1
- import type { BitcoinPaymentData, CryptoPaymentData, EVMPaymentData, FiatPaymentData, PaymentDataBase, PaymentStep, SolanaPaymentData, SuiPaymentData } from "../types/model";
2
- export declare function getFiatPaymentStep(payment?: PaymentDataBase): PaymentStep | undefined;
1
+ import type { FiatPaymentData, PaymentDataBase, PaymentStep } from "../types/model";
3
2
  export declare function getFiatPaymentData(payment?: PaymentDataBase): FiatPaymentData | undefined;
4
- export declare function getCryptoDepositStep(payment?: PaymentDataBase): PaymentStep | undefined;
5
- export declare function getCryptoTransactionStep(payment?: PaymentDataBase): PaymentStep | undefined;
6
- export declare function getWalletPaymentStep(payment?: PaymentDataBase): PaymentStep | undefined;
7
- export declare function getWalletPaymentData(payment?: PaymentDataBase): CryptoPaymentData | undefined;
8
- export declare function getDepositAddress(payment?: PaymentDataBase): string | undefined;
9
- export declare function getEvmPaymentData(paymentData?: CryptoPaymentData): EVMPaymentData | undefined;
10
- export declare function getBitcoinPaymentData(paymentData?: CryptoPaymentData): BitcoinPaymentData | undefined;
11
- export declare function getSolanaPaymentData(paymentData?: CryptoPaymentData): SolanaPaymentData | undefined;
12
- export declare function getSuiPaymentData(paymentData?: CryptoPaymentData): SuiPaymentData | undefined;
3
+ export declare function getPaymentStep(payment?: PaymentDataBase, stepIndex?: number): PaymentStep | undefined;
4
+ export declare function getDepositAddress(payment?: PaymentDataBase, stepIndex?: number): string | undefined;
@@ -1,53 +1,24 @@
1
1
  import { PaymentRail, StepKind } from "../types/enums";
2
- export function getFiatPaymentStep(payment) {
3
- return payment?.steps.find((step) => {
4
- return (step.rail === PaymentRail.FIAT || step.kind === StepKind.KIND_STRIPE_ONRAMP) && step.data?.fiat;
5
- });
6
- }
7
2
  export function getFiatPaymentData(payment) {
8
- const data = getFiatPaymentStep(payment)?.data;
9
- return data?.fiat;
10
- }
11
- export function getCryptoDepositStep(payment) {
12
- return payment?.steps.find((step) => {
13
- return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_DEPOSIT;
14
- });
15
- }
16
- export function getCryptoTransactionStep(payment) {
17
- return payment?.steps.find((step) => {
18
- return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_TRANSACTION && step.data?.crypto;
19
- });
20
- }
21
- export function getWalletPaymentStep(payment) {
22
- return getCryptoTransactionStep(payment) ?? getCryptoDepositStep(payment);
3
+ const step = getPaymentStep(payment);
4
+ if (step?.rail !== PaymentRail.FIAT || step.kind !== StepKind.KIND_STRIPE_ONRAMP)
5
+ return undefined;
6
+ return step.data?.fiat;
23
7
  }
24
- export function getWalletPaymentData(payment) {
25
- const data = getCryptoTransactionStep(payment)?.data;
26
- return data?.crypto;
8
+ export function getPaymentStep(payment, stepIndex) {
9
+ const steps = payment?.steps ?? [];
10
+ if (stepIndex !== undefined) {
11
+ return steps[stepIndex];
12
+ }
13
+ return steps[0];
27
14
  }
28
- export function getDepositAddress(payment) {
29
- const depositStep = getCryptoDepositStep(payment);
30
- if (depositStep?.deposit_address) {
31
- return depositStep.deposit_address;
15
+ export function getDepositAddress(payment, stepIndex) {
16
+ const step = getPaymentStep(payment, stepIndex);
17
+ if (step?.kind === StepKind.KIND_DEPOSIT) {
18
+ return step.deposit_address;
32
19
  }
33
- if (getCryptoTransactionStep(payment)) {
20
+ if (step?.kind === StepKind.KIND_TRANSACTION) {
34
21
  return undefined;
35
22
  }
36
23
  return payment?.deposit_address;
37
24
  }
38
- export function getEvmPaymentData(paymentData) {
39
- const data = paymentData;
40
- return data?.evm;
41
- }
42
- export function getBitcoinPaymentData(paymentData) {
43
- const data = paymentData;
44
- return data?.bitcoin;
45
- }
46
- export function getSolanaPaymentData(paymentData) {
47
- const data = paymentData;
48
- return data?.solana;
49
- }
50
- export function getSuiPaymentData(paymentData) {
51
- const data = paymentData;
52
- return data?.sui;
53
- }
@@ -43,13 +43,15 @@ export const zPayOrderMetadata = z
43
43
  });
44
44
  // NOTE: be careful to modify this type only in backward-compatible ways.
45
45
  // Add OPTIONAL fields, etc. Anything else requires a migration.
46
- export const zPayOrderSettings = z.object({
46
+ export const zPayOrderSettings = z
47
+ .object({
47
48
  hide_footer: z.boolean().optional().describe("Hide the CoinVoyage footer in supported payment UIs."),
48
49
  card_payments: z
49
50
  .boolean()
50
51
  .optional()
51
52
  .describe("Whether to enable card payments for this order. Requires approval from CoinVoyage."),
52
- }).catchall(z.unknown());
53
+ })
54
+ .catchall(z.unknown());
53
55
  // also validate not both token_amount and fiat are present
54
56
  export const zPayOrder = z.object({
55
57
  metadata: zPayOrderMetadata.optional(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.4.2",
4
+ "version": "2.4.3-beta.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {