@daimo/pay 1.8.4 → 1.8.6

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.
package/build/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import React$1, { ReactNode, ReactElement } from 'react';
2
2
  export { version } from '../package.json';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
4
3
  import { CreateConfigParameters } from '@wagmi/core';
5
4
  import { CreateConnectorFn } from 'wagmi';
6
5
  import { CoinbaseWalletParameters } from 'wagmi/connectors';
7
- import { DaimoPayOrderView, PaymentStartedEvent, PaymentCompletedEvent, PaymentBouncedEvent, ExternalPaymentOptionsString, DaimoPayUserMetadata, DaimoPayIntentStatus, DaimoPayOrderMode, DepositAddressPaymentOptionMetadata, PlatformType, ExternalPaymentOptionMetadata, WalletPaymentOption, DaimoPayOrderWithOrg, ExternalPaymentOptions, DepositAddressPaymentOptions, DepositAddressPaymentOptionData, SolanaPublicKey } from '@daimo/pay-common';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
+ import { DaimoPayOrderView, PaymentStartedEvent, PaymentCompletedEvent, PaymentBouncedEvent, ExternalPaymentOptionsString, DaimoPayUserMetadata, DaimoPayOrderWithOrg, DaimoPayHydratedOrderWithOrg, DaimoPayOrder, DaimoPayOrderID, SolanaPublicKey, DaimoPayIntentStatus, DaimoPayOrderMode, DepositAddressPaymentOptionMetadata, PlatformType, ExternalPaymentOptionMetadata, WalletPaymentOption, ExternalPaymentOptions, DepositAddressPaymentOptions, DepositAddressPaymentOptionData } from '@daimo/pay-common';
8
8
  import { Address, Hex } from 'viem';
9
- import { WalletName } from '@solana/wallet-adapter-base';
10
9
  import { AppRouter } from '@daimo/pay-api';
11
10
  import { CreateTRPCClient } from '@trpc/client';
11
+ import { WalletName } from '@solana/wallet-adapter-base';
12
12
 
13
13
  type Hash = `0x${string}`;
14
14
  type CustomAvatarProps = {
@@ -69,6 +69,7 @@ type DaimoPayContextOptions = {
69
69
  type DaimoPayModalOptions = {
70
70
  closeOnSuccess?: boolean;
71
71
  resetOnSuccess?: boolean;
72
+ connectedWalletOnly?: boolean;
72
73
  };
73
74
 
74
75
  type types_All = All;
@@ -83,6 +84,22 @@ declare namespace types {
83
84
  export type { types_All as All, types_CustomAvatarProps as CustomAvatarProps, types_CustomTheme as CustomTheme, types_DaimoPayContextOptions as DaimoPayContextOptions, types_DaimoPayModalOptions as DaimoPayModalOptions, types_Languages as Languages, types_Mode as Mode, types_Theme as Theme };
84
85
  }
85
86
 
87
+ type DefaultConfigProps = {
88
+ appName: string;
89
+ appIcon?: string;
90
+ appDescription?: string;
91
+ appUrl?: string;
92
+ /**
93
+ * WC 2.0 Project ID (get one here: https://cloud.walletconnect.com/sign-in),
94
+ * it doesn't do much besides tracking. If not provided, use Daimo's
95
+ * WalletConnect project ID by default. */
96
+ walletConnectProjectId?: string;
97
+ coinbaseWalletPreference?: CoinbaseWalletParameters<"4">["preference"];
98
+ additionalConnectors?: CreateConnectorFn[];
99
+ } & Partial<CreateConfigParameters>;
100
+ /** Daimo Pay recommended config, for use with wagmi's createConfig(). */
101
+ declare const defaultConfig: ({ appName, appIcon, appDescription, appUrl, walletConnectProjectId, coinbaseWalletPreference, additionalConnectors, chains, client, ...props }: DefaultConfigProps) => CreateConfigParameters;
102
+
86
103
  type useConnectCallbackProps = {
87
104
  onConnect?: ({ address, connectorId, }: {
88
105
  address?: string;
@@ -112,22 +129,6 @@ type DaimoPayProviderProps = {
112
129
  */
113
130
  declare const DaimoPayProvider: (props: DaimoPayProviderProps) => react_jsx_runtime.JSX.Element;
114
131
 
115
- type DefaultConfigProps = {
116
- appName: string;
117
- appIcon?: string;
118
- appDescription?: string;
119
- appUrl?: string;
120
- /**
121
- * WC 2.0 Project ID (get one here: https://cloud.walletconnect.com/sign-in),
122
- * it doesn't do much besides tracking. If not provided, use Daimo's
123
- * WalletConnect project ID by default. */
124
- walletConnectProjectId?: string;
125
- coinbaseWalletPreference?: CoinbaseWalletParameters<"4">["preference"];
126
- additionalConnectors?: CreateConnectorFn[];
127
- } & Partial<CreateConfigParameters>;
128
- /** Daimo Pay recommended config, for use with wagmi's createConfig(). */
129
- declare const defaultConfig: ({ appName, appIcon, appDescription, appUrl, walletConnectProjectId, coinbaseWalletPreference, additionalConnectors, chains, client, ...props }: DefaultConfigProps) => CreateConfigParameters;
130
-
131
132
  /** Payment details and status. */
132
133
  type DaimoPayment = DaimoPayOrderView;
133
134
  /** Props for DaimoPayButton. */
@@ -196,9 +197,7 @@ type PayButtonPaymentProps = {
196
197
  } | {
197
198
  /** The payment ID, generated via the Daimo Pay API. Replaces params above. */
198
199
  payId: string;
199
- /**
200
- * Payment options. By default, all are enabled.
201
- */
200
+ /** Payment options. By default, all are enabled. */
202
201
  paymentOptions?: ExternalPaymentOptionsString[];
203
202
  };
204
203
  type PayButtonCommonProps = PayButtonPaymentProps & {
@@ -212,12 +211,15 @@ type PayButtonCommonProps = PayButtonPaymentProps & {
212
211
  onOpen?: () => void;
213
212
  /** Called when the modal is closed. */
214
213
  onClose?: () => void;
215
- /** Automatically close the modal after a successful payment. */
216
- closeOnSuccess?: boolean;
217
214
  /** Open the modal by default. */
218
215
  defaultOpen?: boolean;
216
+ /** Automatically close the modal after a successful payment. */
217
+ closeOnSuccess?: boolean;
219
218
  /** Reset the payment after a successful payment. */
220
219
  resetOnSuccess?: boolean;
220
+ /** Go directly to tokens in already-connected Ethereum and Solana wallet(s).
221
+ * Don't let the user pick any other payment method. Used in embedded flows.*/
222
+ connectedWalletOnly?: boolean;
221
223
  /** Custom message to display on confirmation page. */
222
224
  confirmationMessage?: string;
223
225
  /** Redirect URL to return to the app. E.g. after Coinbase, Binance, RampNetwork. */
@@ -254,6 +256,155 @@ declare namespace DaimoPayButtonCustom {
254
256
  var displayName: string;
255
257
  }
256
258
 
259
+ /** Payment parameters. The payment is created only after user taps pay. */
260
+ interface PayParams {
261
+ /** App ID, for authentication. */
262
+ appId: string;
263
+ /** Destination chain ID. */
264
+ toChain: number;
265
+ /** The destination token to send. */
266
+ toToken: Address;
267
+ /**
268
+ * The amount of the token to send.
269
+ * If not provided, the user will be prompted to enter an amount.
270
+ */
271
+ toUnits?: string;
272
+ /** The final address to transfer to or contract to call. */
273
+ toAddress: Address;
274
+ /** Calldata for final call, or empty data for transfer. */
275
+ toCallData?: Hex;
276
+ /** The intent verb, such as Pay, Deposit, or Purchase. Default: Pay */
277
+ intent?: string;
278
+ /** Payment options. By default, all are enabled. */
279
+ paymentOptions?: ExternalPaymentOptionsString[];
280
+ /** Preferred chain IDs. */
281
+ preferredChains?: number[];
282
+ /** Preferred tokens. These appear first in the token list. */
283
+ preferredTokens?: {
284
+ chain: number;
285
+ address: Address;
286
+ }[];
287
+ /** Only allow payments on these EVM chains. */
288
+ evmChains?: number[];
289
+ /** External ID. E.g. a correlation ID. */
290
+ externalId?: string;
291
+ /** Developer metadata. E.g. correlation ID. */
292
+ metadata?: DaimoPayUserMetadata;
293
+ /** The address to refund to if the payment bounces or a refund is requested. */
294
+ refundAddress?: Address;
295
+ }
296
+ type PaymentState$1 = {
297
+ type: "idle";
298
+ } | {
299
+ type: "preview";
300
+ order: DaimoPayOrderWithOrg;
301
+ payParamsData: PayParamsData;
302
+ } | {
303
+ type: "unhydrated";
304
+ order: DaimoPayOrderWithOrg;
305
+ } | {
306
+ type: "payment_unpaid";
307
+ order: DaimoPayHydratedOrderWithOrg;
308
+ } | {
309
+ type: "payment_started";
310
+ order: DaimoPayHydratedOrderWithOrg;
311
+ } | {
312
+ type: "payment_completed";
313
+ order: DaimoPayHydratedOrderWithOrg;
314
+ } | {
315
+ type: "payment_bounced";
316
+ order: DaimoPayHydratedOrderWithOrg;
317
+ } | {
318
+ type: "error";
319
+ order: DaimoPayOrder | undefined;
320
+ message: string;
321
+ };
322
+ type PayParamsData = {
323
+ appId: string;
324
+ };
325
+
326
+ type DaimoPayFunctions = {
327
+ /**
328
+ * Create a new Daimo Pay order preview with the given parameters.
329
+ * Call this to start a new payment flow.
330
+ *
331
+ * @param params - Parameters describing the payment to be created.
332
+ */
333
+ createPreviewOrder: (params: PayParams) => Promise<Extract<PaymentState$1, {
334
+ type: "preview";
335
+ }>>;
336
+ /**
337
+ * Set the order ID to fetch and manage an existing Daimo Pay order.
338
+ * Useful for resuming or referencing a previously created order.
339
+ *
340
+ * @param id - The Daimo Pay order ID to set.
341
+ */
342
+ setPayId: (id: DaimoPayOrderID) => Promise<Extract<PaymentState$1, {
343
+ type: "unhydrated" | "payment_unpaid" | "payment_started" | "payment_completed" | "payment_bounced";
344
+ }>>;
345
+ /**
346
+ * Hydrate the current order, locking in the payment intent details and
347
+ * token swap prices.
348
+ */
349
+ hydrateOrder: (refundAddress?: Address) => Promise<Extract<PaymentState$1, {
350
+ type: "payment_unpaid";
351
+ }>>;
352
+ /**
353
+ * Register an Ethereum payment source for the current order.
354
+ * Call this after the user has submitted an Ethereum payment transaction.
355
+ *
356
+ * @param args - Details about the Ethereum payment transaction.
357
+ */
358
+ payEthSource: (args: {
359
+ paymentTxHash: Hex;
360
+ sourceChainId: number;
361
+ payerAddress: Address;
362
+ sourceToken: Address;
363
+ sourceAmount: bigint;
364
+ }) => void;
365
+ /**
366
+ * Register a Solana payment source for the current order.
367
+ * Call this after the user has submitted a Solana payment transaction.
368
+ *
369
+ * @param args - Details about the Solana payment transaction.
370
+ */
371
+ paySolanaSource: (args: {
372
+ paymentTxHash: string;
373
+ sourceToken: SolanaPublicKey;
374
+ }) => void;
375
+ /**
376
+ * Reset the current payment state and clear the active order.
377
+ * Call this to start a new payment flow.
378
+ */
379
+ reset: () => void;
380
+ /**
381
+ * Update the user's chosen amount in USD. Applies only to deposit flow.
382
+ *
383
+ * @deprecated
384
+ */
385
+ setChosenUsd: (usd: number) => void;
386
+ };
387
+ type DaimoPayState = {
388
+ [S in PaymentState$1 as S["type"]]: {
389
+ paymentState: S["type"];
390
+ order: S extends {
391
+ order: infer O;
392
+ } ? O : null;
393
+ };
394
+ }[PaymentState$1["type"]];
395
+ type UseDaimoPay = DaimoPayFunctions & DaimoPayState;
396
+ /**
397
+ * React hook for interacting with Daimo Pay orders and payments. Use this hook
398
+ * to manage the lifecycle of a Daimo Pay payment in your application.
399
+ *
400
+ * This hook provides a simple interface to create, hydrate, pay, and reset
401
+ * Daimo Pay orders.
402
+ *
403
+ * @returns {UseDaimoPay} An object with current payment state and methods to
404
+ * manage Daimo Pay orders and payments.
405
+ */
406
+ declare function useDaimoPay(): UseDaimoPay;
407
+
257
408
  /** Returns the current payment, or undefined if there is none.
258
409
  *
259
410
  * Status values:
@@ -269,6 +420,11 @@ declare function useDaimoPayStatus(): {
269
420
  status: DaimoPayIntentStatus;
270
421
  } | undefined;
271
422
 
423
+ type UseDaimoPayUI = {
424
+ resetPayment: (payParams?: Partial<PayParams>) => Promise<void>;
425
+ };
426
+ declare function useDaimoPayUI(): UseDaimoPayUI;
427
+
272
428
  /** Icon for an EVM chain, given chain ID. No ID shows a loading spinner. */
273
429
  declare const Chain: React$1.FC<{
274
430
  id?: number;
@@ -284,8 +440,6 @@ declare const wallets: {
284
440
 
285
441
  declare const daimoPayVersion: string;
286
442
 
287
- type SolanaWalletName = WalletName<string>;
288
-
289
443
  declare enum ROUTES {
290
444
  SELECT_METHOD = "daimoPaySelectMethod",
291
445
  SELECT_TOKEN = "daimoPaySelectToken",
@@ -302,7 +456,6 @@ declare enum ROUTES {
302
456
  CONFIRMATION = "daimoPayConfirmation",
303
457
  SOLANA_CONNECT = "daimoPaySolanaConnect",
304
458
  SOLANA_CONNECTOR = "daimoPaySolanaConnector",
305
- SOLANA_SELECT_TOKEN = "daimoPaySolanaSelectToken",
306
459
  SOLANA_SELECT_AMOUNT = "daimoPaySolanaSelectAmount",
307
460
  SOLANA_PAY_WITH_TOKEN = "daimoPaySolanaPayWithToken",
308
461
  ONBOARDING = "onboarding",
@@ -314,6 +467,8 @@ declare enum ROUTES {
314
467
  SWITCHNETWORKS = "switchNetworks"
315
468
  }
316
469
 
470
+ type TrpcClient = CreateTRPCClient<AppRouter>;
471
+
317
472
  type WalletConfigProps = {
318
473
  name?: string;
319
474
  shortName?: string;
@@ -342,8 +497,6 @@ type WalletConfigProps = {
342
497
  isSolanaOnly?: boolean;
343
498
  };
344
499
 
345
- type TrpcClient = CreateTRPCClient<AppRouter>;
346
-
347
500
  declare function useDepositAddressOptions({ trpc, usdRequired, mode, }: {
348
501
  trpc: TrpcClient;
349
502
  usdRequired: number | undefined;
@@ -394,53 +547,14 @@ declare function useWalletPaymentOptions({ trpc, address, usdRequired, destChain
394
547
  isLoading: boolean;
395
548
  };
396
549
 
397
- /** Payment parameters. The payment is created only after user taps pay. */
398
- interface PayParams {
399
- /** App ID, for authentication. */
400
- appId: string;
401
- /** Destination chain ID. */
402
- toChain: number;
403
- /** The destination token to send. */
404
- toToken: Address;
405
- /**
406
- * The amount of the token to send.
407
- * If not provided, the user will be prompted to enter an amount.
408
- */
409
- toUnits?: string;
410
- /** The final address to transfer to or contract to call. */
411
- toAddress: Address;
412
- /** Calldata for final call, or empty data for transfer. */
413
- toCallData?: Hex;
414
- /** The intent verb, such as Pay, Deposit, or Purchase. Default: Pay */
415
- intent?: string;
416
- /** Payment options. By default, all are enabled. */
417
- paymentOptions?: ExternalPaymentOptionsString[];
418
- /** Preferred chain IDs. */
419
- preferredChains?: number[];
420
- /** Preferred tokens. These appear first in the token list. */
421
- preferredTokens?: {
422
- chain: number;
423
- address: Address;
424
- }[];
425
- /** Only allow payments on these EVM chains. */
426
- evmChains?: number[];
427
- /** External ID. E.g. a correlation ID. */
428
- externalId?: string;
429
- /** Developer metadata. E.g. correlation ID. */
430
- metadata?: DaimoPayUserMetadata;
431
- /** The address to refund to if the payment bounces or a refund is requested. */
432
- refundAddress?: Address;
433
- }
434
550
  /** Creates (or loads) a payment and manages the corresponding modal. */
435
551
  interface PaymentState {
436
- generatePreviewOrder: (payParams: PayParams) => void;
437
- resetOrder: () => void;
552
+ generatePreviewOrder: () => void;
553
+ resetOrder: (payParams?: Partial<PayParams>) => Promise<void>;
438
554
  buttonProps: PayButtonPaymentProps | undefined;
439
555
  setButtonProps: (props: PayButtonPaymentProps | undefined) => void;
440
556
  setPayId: (id: string | undefined) => void;
441
- payParams: PayParams | undefined;
442
- setPayParams: (payParams: PayParams | undefined) => void;
443
- daimoPayOrder: DaimoPayOrderWithOrg | undefined;
557
+ setPayParams: (payParams: PayParams | undefined) => Promise<void>;
444
558
  isDepositFlow: boolean;
445
559
  paymentWaitingMessage: string | undefined;
446
560
  externalPaymentOptions: ReturnType<typeof useExternalPaymentOptions>;
@@ -456,6 +570,8 @@ interface PaymentState {
456
570
  selectedDepositAddressOption: DepositAddressPaymentOptionMetadata | undefined;
457
571
  getOrderUsdLimit: () => number;
458
572
  setPaymentWaitingMessage: (message: string | undefined) => void;
573
+ tokenMode: "evm" | "solana" | "all";
574
+ setTokenMode: (mode: "evm" | "solana" | "all") => void;
459
575
  setSelectedWallet: (wallet: WalletConfigProps | undefined) => void;
460
576
  setSelectedWalletDeepLink: (deepLink: string | undefined) => void;
461
577
  setSelectedExternalOption: (option: ExternalPaymentOptionMetadata | undefined) => void;
@@ -467,13 +583,12 @@ interface PaymentState {
467
583
  payWithExternal: (option: ExternalPaymentOptions) => Promise<string>;
468
584
  payWithDepositAddress: (option: DepositAddressPaymentOptions) => Promise<DepositAddressPaymentOptionData | null>;
469
585
  payWithSolanaToken: (inputToken: SolanaPublicKey) => Promise<string | undefined>;
470
- payWithWallet: (wallet?: WalletConfigProps, amountUsd?: number) => Promise<void>;
471
- refreshOrder: () => Promise<void>;
586
+ openInWalletBrowser: (wallet: WalletConfigProps, amountUsd?: number) => void;
472
587
  senderEnsName: string | undefined;
473
588
  }
474
589
 
475
- /** Daimo Pay internal context. */
476
- declare const usePayContext: () => PayContextValue;
590
+ type SolanaWalletName = WalletName<string>;
591
+
477
592
  /** Meant for internal use. This will be non-exported in a future SDK version. */
478
593
  declare const PayContext: React$1.Context<PayContextValue | null>;
479
594
  type PayLogFn = (message: string, ...props: any[]) => void;
@@ -485,8 +600,8 @@ type PayContextValue = {
485
600
  setMode: React$1.Dispatch<React$1.SetStateAction<Mode>>;
486
601
  customTheme: CustomTheme | undefined;
487
602
  setCustomTheme: React$1.Dispatch<React$1.SetStateAction<CustomTheme | undefined>>;
488
- lang: Languages$1;
489
- setLang: React$1.Dispatch<React$1.SetStateAction<Languages$1>>;
603
+ lang: Languages;
604
+ setLang: React$1.Dispatch<React$1.SetStateAction<Languages>>;
490
605
  setOnOpen: (fn?: () => void) => void;
491
606
  setOnClose: (fn?: () => void) => void;
492
607
  open: boolean;
@@ -527,5 +642,8 @@ type PayContextValue = {
527
642
  setRedirectReturnUrl: React$1.Dispatch<React$1.SetStateAction<string | undefined>>;
528
643
  } & useConnectCallbackProps;
529
644
 
530
- export { Avatar, Chain as ChainIcon, DaimoPayButton, PayContext as DaimoPayContext, DaimoPayProvider, types as Types, daimoPayVersion, defaultConfig as getDefaultConfig, useDaimoPayStatus, usePayContext, wallets };
645
+ /** Daimo Pay internal context. */
646
+ declare const usePayContext: () => PayContextValue;
647
+
648
+ export { Avatar, Chain as ChainIcon, DaimoPayButton, PayContext as DaimoPayContext, DaimoPayProvider, types as Types, daimoPayVersion, defaultConfig as getDefaultConfig, useDaimoPay, useDaimoPayStatus, useDaimoPayUI, usePayContext, wallets };
531
649
  export type { All, CustomAvatarProps, CustomTheme, DaimoPayButtonCustomProps, DaimoPayButtonProps, DaimoPayContextOptions, DaimoPayModalOptions, DaimoPayment, Languages, Mode, Theme };