@daimo/pay 1.8.5 → 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
@@ -6,9 +6,9 @@ import { CoinbaseWalletParameters } from 'wagmi/connectors';
6
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
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 = {
@@ -420,6 +420,11 @@ declare function useDaimoPayStatus(): {
420
420
  status: DaimoPayIntentStatus;
421
421
  } | undefined;
422
422
 
423
+ type UseDaimoPayUI = {
424
+ resetPayment: (payParams?: Partial<PayParams>) => Promise<void>;
425
+ };
426
+ declare function useDaimoPayUI(): UseDaimoPayUI;
427
+
423
428
  /** Icon for an EVM chain, given chain ID. No ID shows a loading spinner. */
424
429
  declare const Chain: React$1.FC<{
425
430
  id?: number;
@@ -435,8 +440,6 @@ declare const wallets: {
435
440
 
436
441
  declare const daimoPayVersion: string;
437
442
 
438
- type SolanaWalletName = WalletName<string>;
439
-
440
443
  declare enum ROUTES {
441
444
  SELECT_METHOD = "daimoPaySelectMethod",
442
445
  SELECT_TOKEN = "daimoPaySelectToken",
@@ -464,6 +467,8 @@ declare enum ROUTES {
464
467
  SWITCHNETWORKS = "switchNetworks"
465
468
  }
466
469
 
470
+ type TrpcClient = CreateTRPCClient<AppRouter>;
471
+
467
472
  type WalletConfigProps = {
468
473
  name?: string;
469
474
  shortName?: string;
@@ -492,8 +497,6 @@ type WalletConfigProps = {
492
497
  isSolanaOnly?: boolean;
493
498
  };
494
499
 
495
- type TrpcClient = CreateTRPCClient<AppRouter>;
496
-
497
500
  declare function useDepositAddressOptions({ trpc, usdRequired, mode, }: {
498
501
  trpc: TrpcClient;
499
502
  usdRequired: number | undefined;
@@ -547,11 +550,11 @@ declare function useWalletPaymentOptions({ trpc, address, usdRequired, destChain
547
550
  /** Creates (or loads) a payment and manages the corresponding modal. */
548
551
  interface PaymentState {
549
552
  generatePreviewOrder: () => void;
550
- resetOrder: () => void;
553
+ resetOrder: (payParams?: Partial<PayParams>) => Promise<void>;
551
554
  buttonProps: PayButtonPaymentProps | undefined;
552
555
  setButtonProps: (props: PayButtonPaymentProps | undefined) => void;
553
556
  setPayId: (id: string | undefined) => void;
554
- setPayParams: (payParams: PayParams | undefined) => void;
557
+ setPayParams: (payParams: PayParams | undefined) => Promise<void>;
555
558
  isDepositFlow: boolean;
556
559
  paymentWaitingMessage: string | undefined;
557
560
  externalPaymentOptions: ReturnType<typeof useExternalPaymentOptions>;
@@ -584,8 +587,8 @@ interface PaymentState {
584
587
  senderEnsName: string | undefined;
585
588
  }
586
589
 
587
- /** Daimo Pay internal context. */
588
- declare const usePayContext: () => PayContextValue;
590
+ type SolanaWalletName = WalletName<string>;
591
+
589
592
  /** Meant for internal use. This will be non-exported in a future SDK version. */
590
593
  declare const PayContext: React$1.Context<PayContextValue | null>;
591
594
  type PayLogFn = (message: string, ...props: any[]) => void;
@@ -597,8 +600,8 @@ type PayContextValue = {
597
600
  setMode: React$1.Dispatch<React$1.SetStateAction<Mode>>;
598
601
  customTheme: CustomTheme | undefined;
599
602
  setCustomTheme: React$1.Dispatch<React$1.SetStateAction<CustomTheme | undefined>>;
600
- lang: Languages$1;
601
- setLang: React$1.Dispatch<React$1.SetStateAction<Languages$1>>;
603
+ lang: Languages;
604
+ setLang: React$1.Dispatch<React$1.SetStateAction<Languages>>;
602
605
  setOnOpen: (fn?: () => void) => void;
603
606
  setOnClose: (fn?: () => void) => void;
604
607
  open: boolean;
@@ -639,5 +642,8 @@ type PayContextValue = {
639
642
  setRedirectReturnUrl: React$1.Dispatch<React$1.SetStateAction<string | undefined>>;
640
643
  } & useConnectCallbackProps;
641
644
 
642
- export { Avatar, Chain as ChainIcon, DaimoPayButton, PayContext as DaimoPayContext, DaimoPayProvider, types as Types, daimoPayVersion, defaultConfig as getDefaultConfig, useDaimoPay, 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 };
643
649
  export type { All, CustomAvatarProps, CustomTheme, DaimoPayButtonCustomProps, DaimoPayButtonProps, DaimoPayContextOptions, DaimoPayModalOptions, DaimoPayment, Languages, Mode, Theme };
package/build/index.js CHANGED
@@ -22,7 +22,7 @@ import { VersionedTransaction } from '@solana/web3.js';
22
22
  import { normalize } from 'viem/ens';
23
23
 
24
24
  var name = "@daimo/pay";
25
- var version = "1.8.5";
25
+ var version = "1.8.6";
26
26
  var author = "Daimo";
27
27
  var homepage = "https://pay.daimo.com";
28
28
  var license = "BSD-2-Clause license";
@@ -61,7 +61,7 @@ var keywords = [
61
61
  "crypto"
62
62
  ];
63
63
  var dependencies = {
64
- "@daimo/pay-common": "1.8.5",
64
+ "@daimo/pay-common": "1.8.6",
65
65
  "@rollup/plugin-typescript": "^12.1.2",
66
66
  "@solana/wallet-adapter-base": "^0.9.23",
67
67
  "@solana/wallet-adapter-react": "^0.15.35",
@@ -247,6 +247,9 @@ var ROUTES;
247
247
  ROUTES["SWITCHNETWORKS"] = "switchNetworks";
248
248
  })(ROUTES || (ROUTES = {}));
249
249
 
250
+ /** Meant for internal use. This will be non-exported in a future SDK version. */
251
+ const PayContext = createContext(null);
252
+
250
253
  /** Daimo Pay internal context. */
251
254
  const usePayContext = () => {
252
255
  const context = React.useContext(PayContext);
@@ -254,8 +257,6 @@ const usePayContext = () => {
254
257
  throw Error("DaimoPay Hook must be inside a Provider.");
255
258
  return context;
256
259
  };
257
- /** Meant for internal use. This will be non-exported in a future SDK version. */
258
- const PayContext = createContext(null);
259
260
 
260
261
  const hexToP3 = (hex) => {
261
262
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
@@ -11899,10 +11900,6 @@ function usePaymentState({ trpc, lockPayParams, setRoute, log, redirectReturnUrl
11899
11900
  paymentOptions.includes(ExternalPaymentOptions.Solana)) &&
11900
11901
  pay.order != null &&
11901
11902
  isCCTPV1Chain(getOrderDestChainId(pay.order));
11902
- // Refs the survive re-renders and stores any updated param values while
11903
- // lockPayParams is true
11904
- const latestPayParamsRef = useRef();
11905
- const latestPayIdRef = useRef();
11906
11903
  // From DaimoPayButton props
11907
11904
  const [buttonProps, setButtonProps] = useState();
11908
11905
  const [currPayParams, setCurrPayParams] = useState();
@@ -12102,7 +12099,6 @@ function usePaymentState({ trpc, lockPayParams, setRoute, log, redirectReturnUrl
12102
12099
  pay.setChosenUsd(usd);
12103
12100
  };
12104
12101
  const setPayId = useCallback(async (payId) => {
12105
- latestPayIdRef.current = payId;
12106
12102
  if (lockPayParams || payId == null)
12107
12103
  return;
12108
12104
  const id = readDaimoPayOrderID(payId).toString();
@@ -12115,7 +12111,6 @@ function usePaymentState({ trpc, lockPayParams, setRoute, log, redirectReturnUrl
12115
12111
  }, [lockPayParams, pay]);
12116
12112
  /** Called whenever params change. */
12117
12113
  const setPayParams = async (payParams) => {
12118
- latestPayParamsRef.current = payParams;
12119
12114
  if (lockPayParams)
12120
12115
  return;
12121
12116
  assert(payParams != null, "[SET PAY PARAMS] payParams cannot be null");
@@ -12131,20 +12126,27 @@ function usePaymentState({ trpc, lockPayParams, setRoute, log, redirectReturnUrl
12131
12126
  pay.reset();
12132
12127
  await pay.createPreviewOrder(currPayParams);
12133
12128
  };
12134
- const resetOrder = useCallback(() => {
12135
- // Clear the old order & UI
12129
+ const resetOrder = useCallback(async (payParams) => {
12130
+ const mergedPayParams = payParams != null && currPayParams != null
12131
+ ? { ...currPayParams, ...payParams }
12132
+ : currPayParams;
12133
+ // Clear the old order & state
12136
12134
  pay.reset();
12137
- setRoute(ROUTES.SELECT_METHOD);
12138
- // Prefer an explicit payId, otherwise use the queued payParams
12139
- if (latestPayIdRef.current) {
12140
- pay.setPayId(latestPayIdRef.current);
12141
- latestPayIdRef.current = undefined;
12142
- }
12143
- else if (latestPayParamsRef.current) {
12144
- pay.createPreviewOrder(latestPayParamsRef.current);
12145
- latestPayParamsRef.current = undefined;
12135
+ setSelectedExternalOption(undefined);
12136
+ setSelectedTokenOption(undefined);
12137
+ setSelectedSolanaTokenOption(undefined);
12138
+ setSelectedDepositAddressOption(undefined);
12139
+ setSelectedWallet(undefined);
12140
+ setSelectedWalletDeepLink(undefined);
12141
+ setPaymentWaitingMessage(undefined);
12142
+ // Set the new payParams
12143
+ if (mergedPayParams) {
12144
+ await pay.createPreviewOrder(mergedPayParams);
12145
+ setCurrPayParams(mergedPayParams);
12146
+ setIsDepositFlow(mergedPayParams.toUnits == null);
12146
12147
  }
12147
- }, [setRoute, pay]);
12148
+ setRoute(ROUTES.SELECT_METHOD);
12149
+ }, [setRoute, pay, currPayParams]);
12148
12150
  const [tokenMode, setTokenMode] = useState("evm");
12149
12151
  return {
12150
12152
  buttonProps,
@@ -12938,6 +12940,16 @@ function useDaimoPayStatus() {
12938
12940
  return { paymentId, status: order.intentStatus };
12939
12941
  }
12940
12942
 
12943
+ function useDaimoPayUI() {
12944
+ const context = useContext(PayContext);
12945
+ if (!context) {
12946
+ throw new Error("useDaimoPayUI must be used within a DaimoPayUIProvider");
12947
+ }
12948
+ return {
12949
+ resetPayment: context.paymentState.resetOrder,
12950
+ };
12951
+ }
12952
+
12941
12953
  function addressToNumber(address) {
12942
12954
  return ((address
12943
12955
  .split("")
@@ -13193,5 +13205,5 @@ const wallets = Object.keys(walletConfigs).reduce((acc, key) => {
13193
13205
  return acc;
13194
13206
  }, {});
13195
13207
 
13196
- export { Avatar, Chain as ChainIcon, DaimoPayButton, PayContext as DaimoPayContext, DaimoPayProvider, daimoPayVersion, defaultConfig as getDefaultConfig, useDaimoPay, useDaimoPayStatus, usePayContext, version, wallets };
13208
+ export { Avatar, Chain as ChainIcon, DaimoPayButton, PayContext as DaimoPayContext, DaimoPayProvider, daimoPayVersion, defaultConfig as getDefaultConfig, useDaimoPay, useDaimoPayStatus, useDaimoPayUI, usePayContext, version, wallets };
13197
13209
  //# sourceMappingURL=index.js.map