@daimo/sdk 1.0.0-rc.1
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/dist/client/createDaimoClient.d.ts +33 -0
- package/dist/client/createDaimoClient.d.ts.map +1 -0
- package/dist/client/createDaimoClient.js +79 -0
- package/dist/client/createDaimoClient.js.map +1 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +2 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/transport.d.ts +15 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +95 -0
- package/dist/client/transport.js.map +1 -0
- package/dist/common/api.d.ts +184 -0
- package/dist/common/api.d.ts.map +1 -0
- package/dist/common/api.js +40 -0
- package/dist/common/api.js.map +1 -0
- package/dist/common/chain.d.ts +35 -0
- package/dist/common/chain.d.ts.map +1 -0
- package/dist/common/chain.js +198 -0
- package/dist/common/chain.js.map +1 -0
- package/dist/common/errors.d.ts +29 -0
- package/dist/common/errors.d.ts.map +1 -0
- package/dist/common/errors.js +41 -0
- package/dist/common/errors.js.map +1 -0
- package/dist/common/index.d.ts +7 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +7 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/primitives.d.ts +13 -0
- package/dist/common/primitives.d.ts.map +1 -0
- package/dist/common/primitives.js +14 -0
- package/dist/common/primitives.js.map +1 -0
- package/dist/common/session.d.ts +140 -0
- package/dist/common/session.d.ts.map +1 -0
- package/dist/common/session.js +16 -0
- package/dist/common/session.js.map +1 -0
- package/dist/common/token.d.ts +130 -0
- package/dist/common/token.d.ts.map +1 -0
- package/dist/common/token.js +783 -0
- package/dist/common/token.js.map +1 -0
- package/dist/web/api/index.d.ts +3 -0
- package/dist/web/api/index.d.ts.map +1 -0
- package/dist/web/api/index.js +2 -0
- package/dist/web/api/index.js.map +1 -0
- package/dist/web/api/navTree.d.ts +52 -0
- package/dist/web/api/navTree.d.ts.map +1 -0
- package/dist/web/api/navTree.js +2 -0
- package/dist/web/api/navTree.js.map +1 -0
- package/dist/web/api/walletTypes.d.ts +25 -0
- package/dist/web/api/walletTypes.d.ts.map +1 -0
- package/dist/web/api/walletTypes.js +2 -0
- package/dist/web/api/walletTypes.js.map +1 -0
- package/dist/web/components/ChooseOptionPage.d.ts +9 -0
- package/dist/web/components/ChooseOptionPage.d.ts.map +1 -0
- package/dist/web/components/ChooseOptionPage.js +51 -0
- package/dist/web/components/ChooseOptionPage.js.map +1 -0
- package/dist/web/components/ConfirmationPage.d.ts +32 -0
- package/dist/web/components/ConfirmationPage.d.ts.map +1 -0
- package/dist/web/components/ConfirmationPage.js +72 -0
- package/dist/web/components/ConfirmationPage.js.map +1 -0
- package/dist/web/components/ConfirmationSpinner.d.ts +7 -0
- package/dist/web/components/ConfirmationSpinner.d.ts.map +1 -0
- package/dist/web/components/ConfirmationSpinner.js +20 -0
- package/dist/web/components/ConfirmationSpinner.js.map +1 -0
- package/dist/web/components/DaimoModal.d.ts +15 -0
- package/dist/web/components/DaimoModal.d.ts.map +1 -0
- package/dist/web/components/DaimoModal.js +314 -0
- package/dist/web/components/DaimoModal.js.map +1 -0
- package/dist/web/components/DeeplinkPage.d.ts +8 -0
- package/dist/web/components/DeeplinkPage.d.ts.map +1 -0
- package/dist/web/components/DeeplinkPage.js +13 -0
- package/dist/web/components/DeeplinkPage.js.map +1 -0
- package/dist/web/components/ErrorPage.d.ts +29 -0
- package/dist/web/components/ErrorPage.d.ts.map +1 -0
- package/dist/web/components/ErrorPage.js +47 -0
- package/dist/web/components/ErrorPage.js.map +1 -0
- package/dist/web/components/ExchangePage.d.ts +11 -0
- package/dist/web/components/ExchangePage.d.ts.map +1 -0
- package/dist/web/components/ExchangePage.js +13 -0
- package/dist/web/components/ExchangePage.js.map +1 -0
- package/dist/web/components/ExpiredPage.d.ts +9 -0
- package/dist/web/components/ExpiredPage.d.ts.map +1 -0
- package/dist/web/components/ExpiredPage.js +12 -0
- package/dist/web/components/ExpiredPage.js.map +1 -0
- package/dist/web/components/ModalSkeleton.d.ts +7 -0
- package/dist/web/components/ModalSkeleton.d.ts.map +1 -0
- package/dist/web/components/ModalSkeleton.js +13 -0
- package/dist/web/components/ModalSkeleton.js.map +1 -0
- package/dist/web/components/ProgressDots.d.ts +16 -0
- package/dist/web/components/ProgressDots.d.ts.map +1 -0
- package/dist/web/components/ProgressDots.js +55 -0
- package/dist/web/components/ProgressDots.js.map +1 -0
- package/dist/web/components/QRCode.d.ts +7 -0
- package/dist/web/components/QRCode.d.ts.map +1 -0
- package/dist/web/components/QRCode.js +69 -0
- package/dist/web/components/QRCode.js.map +1 -0
- package/dist/web/components/SelectAmountPage.d.ts +21 -0
- package/dist/web/components/SelectAmountPage.d.ts.map +1 -0
- package/dist/web/components/SelectAmountPage.js +27 -0
- package/dist/web/components/SelectAmountPage.js.map +1 -0
- package/dist/web/components/SelectTokenPage.d.ts +14 -0
- package/dist/web/components/SelectTokenPage.d.ts.map +1 -0
- package/dist/web/components/SelectTokenPage.js +71 -0
- package/dist/web/components/SelectTokenPage.js.map +1 -0
- package/dist/web/components/WaitingDepositAddressPage.d.ts +15 -0
- package/dist/web/components/WaitingDepositAddressPage.d.ts.map +1 -0
- package/dist/web/components/WaitingDepositAddressPage.js +126 -0
- package/dist/web/components/WaitingDepositAddressPage.js.map +1 -0
- package/dist/web/components/WalletAmountPage.d.ts +10 -0
- package/dist/web/components/WalletAmountPage.d.ts.map +1 -0
- package/dist/web/components/WalletAmountPage.js +158 -0
- package/dist/web/components/WalletAmountPage.js.map +1 -0
- package/dist/web/components/buttons.d.ts +15 -0
- package/dist/web/components/buttons.d.ts.map +1 -0
- package/dist/web/components/buttons.js +24 -0
- package/dist/web/components/buttons.js.map +1 -0
- package/dist/web/components/containers.d.ts +19 -0
- package/dist/web/components/containers.d.ts.map +1 -0
- package/dist/web/components/containers.js +77 -0
- package/dist/web/components/containers.js.map +1 -0
- package/dist/web/components/icons.d.ts +22 -0
- package/dist/web/components/icons.d.ts.map +1 -0
- package/dist/web/components/icons.js +33 -0
- package/dist/web/components/icons.js.map +1 -0
- package/dist/web/components/shared.d.ts +93 -0
- package/dist/web/components/shared.d.ts.map +1 -0
- package/dist/web/components/shared.js +202 -0
- package/dist/web/components/shared.js.map +1 -0
- package/dist/web/hooks/DaimoClientContext.d.ts +7 -0
- package/dist/web/hooks/DaimoClientContext.d.ts.map +1 -0
- package/dist/web/hooks/DaimoClientContext.js +15 -0
- package/dist/web/hooks/DaimoClientContext.js.map +1 -0
- package/dist/web/hooks/formatUserError.d.ts +3 -0
- package/dist/web/hooks/formatUserError.d.ts.map +1 -0
- package/dist/web/hooks/formatUserError.js +30 -0
- package/dist/web/hooks/formatUserError.js.map +1 -0
- package/dist/web/hooks/locale.d.ts +7 -0
- package/dist/web/hooks/locale.d.ts.map +1 -0
- package/dist/web/hooks/locale.js +15 -0
- package/dist/web/hooks/locale.js.map +1 -0
- package/dist/web/hooks/locales/en.d.ts +60 -0
- package/dist/web/hooks/locales/en.d.ts.map +1 -0
- package/dist/web/hooks/locales/en.js +76 -0
- package/dist/web/hooks/locales/en.js.map +1 -0
- package/dist/web/hooks/locales/es.d.ts +4 -0
- package/dist/web/hooks/locales/es.d.ts.map +1 -0
- package/dist/web/hooks/locales/es.js +60 -0
- package/dist/web/hooks/locales/es.js.map +1 -0
- package/dist/web/hooks/navEvent.d.ts +60 -0
- package/dist/web/hooks/navEvent.d.ts.map +1 -0
- package/dist/web/hooks/navEvent.js +12 -0
- package/dist/web/hooks/navEvent.js.map +1 -0
- package/dist/web/hooks/types.d.ts +72 -0
- package/dist/web/hooks/types.d.ts.map +1 -0
- package/dist/web/hooks/types.js +14 -0
- package/dist/web/hooks/types.js.map +1 -0
- package/dist/web/hooks/useCopyToClipboard.d.ts +6 -0
- package/dist/web/hooks/useCopyToClipboard.d.ts.map +1 -0
- package/dist/web/hooks/useCopyToClipboard.js +20 -0
- package/dist/web/hooks/useCopyToClipboard.js.map +1 -0
- package/dist/web/hooks/usePaymentCallbacks.d.ts +15 -0
- package/dist/web/hooks/usePaymentCallbacks.d.ts.map +1 -0
- package/dist/web/hooks/usePaymentCallbacks.js +27 -0
- package/dist/web/hooks/usePaymentCallbacks.js.map +1 -0
- package/dist/web/hooks/useSessionNav.d.ts +28 -0
- package/dist/web/hooks/useSessionNav.d.ts.map +1 -0
- package/dist/web/hooks/useSessionNav.js +422 -0
- package/dist/web/hooks/useSessionNav.js.map +1 -0
- package/dist/web/hooks/useSessionPolling.d.ts +10 -0
- package/dist/web/hooks/useSessionPolling.d.ts.map +1 -0
- package/dist/web/hooks/useSessionPolling.js +60 -0
- package/dist/web/hooks/useSessionPolling.js.map +1 -0
- package/dist/web/hooks/useWalletFlow.d.ts +22 -0
- package/dist/web/hooks/useWalletFlow.d.ts.map +1 -0
- package/dist/web/hooks/useWalletFlow.js +350 -0
- package/dist/web/hooks/useWalletFlow.js.map +1 -0
- package/dist/web/hooks/walletProvider.d.ts +34 -0
- package/dist/web/hooks/walletProvider.d.ts.map +1 -0
- package/dist/web/hooks/walletProvider.js +14 -0
- package/dist/web/hooks/walletProvider.js.map +1 -0
- package/dist/web/index.d.ts +33 -0
- package/dist/web/index.d.ts.map +1 -0
- package/dist/web/index.js +30 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/theme.css +183 -0
- package/package.json +64 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { NavNode, SessionWithNav } from "../api/navTree.js";
|
|
2
|
+
import type { WalletPaymentOption } from "../api/walletTypes.js";
|
|
3
|
+
export type { SessionWithNav };
|
|
4
|
+
/**
|
|
5
|
+
* A single entry in the navigation stack. Back = pop.
|
|
6
|
+
* autoNav marks entries pushed by auto-navigation (single-option chains).
|
|
7
|
+
*/
|
|
8
|
+
export type NavEntry = {
|
|
9
|
+
type: "choose-option";
|
|
10
|
+
nodeId: string;
|
|
11
|
+
autoNav: boolean;
|
|
12
|
+
} | {
|
|
13
|
+
type: "deeplink";
|
|
14
|
+
nodeId: string;
|
|
15
|
+
autoNav?: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
type: "select-amount";
|
|
18
|
+
nodeId: string;
|
|
19
|
+
flowType: "deposit" | "tron" | "exchange";
|
|
20
|
+
autoNav?: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
type: "waiting-deposit";
|
|
23
|
+
nodeId: string;
|
|
24
|
+
amountUsd: number;
|
|
25
|
+
autoNav?: boolean;
|
|
26
|
+
} | {
|
|
27
|
+
type: "waiting-tron";
|
|
28
|
+
nodeId: string;
|
|
29
|
+
amountUsd: number;
|
|
30
|
+
address?: string;
|
|
31
|
+
expiresAt?: number;
|
|
32
|
+
error?: string;
|
|
33
|
+
autoNav?: boolean;
|
|
34
|
+
} | {
|
|
35
|
+
type: "exchange-page";
|
|
36
|
+
nodeId: string;
|
|
37
|
+
amountUsd: number;
|
|
38
|
+
exchangeUrl?: string;
|
|
39
|
+
waitingMessage?: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
autoNav?: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
type: "wallet-connect";
|
|
44
|
+
nodeId: string;
|
|
45
|
+
autoNav?: boolean;
|
|
46
|
+
} | {
|
|
47
|
+
type: "wallet-select-token";
|
|
48
|
+
nodeId: string;
|
|
49
|
+
autoNav?: boolean;
|
|
50
|
+
} | {
|
|
51
|
+
type: "wallet-select-amount";
|
|
52
|
+
nodeId: string;
|
|
53
|
+
token: WalletPaymentOption;
|
|
54
|
+
autoNav?: boolean;
|
|
55
|
+
} | {
|
|
56
|
+
type: "wallet-sending";
|
|
57
|
+
nodeId: string;
|
|
58
|
+
token: WalletPaymentOption;
|
|
59
|
+
amountUsd: number;
|
|
60
|
+
txHash?: string;
|
|
61
|
+
error?: string;
|
|
62
|
+
autoNav?: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type DaimoModalEventHandlers = {
|
|
65
|
+
onPaymentStarted?: () => void;
|
|
66
|
+
onPaymentCompleted?: () => void;
|
|
67
|
+
onOpen?: () => void;
|
|
68
|
+
onClose?: () => void;
|
|
69
|
+
};
|
|
70
|
+
/** Helper to find a node by ID in the nav tree */
|
|
71
|
+
export declare function findNode(nodeId: string, nodes: NavNode[]): NavNode | null;
|
|
72
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/web/hooks/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GACvD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACD;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAClE;IACE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,mBAAmB,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEN,MAAM,MAAM,uBAAuB,GAAG;IACpC,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,kDAAkD;AAClD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,GAAG,IAAI,CAQzE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Helper to find a node by ID in the nav tree */
|
|
2
|
+
export function findNode(nodeId, nodes) {
|
|
3
|
+
for (const node of nodes) {
|
|
4
|
+
if (node.id === nodeId)
|
|
5
|
+
return node;
|
|
6
|
+
if (node.type !== "ChooseOption")
|
|
7
|
+
continue;
|
|
8
|
+
const found = findNode(nodeId, node.options);
|
|
9
|
+
if (found)
|
|
10
|
+
return found;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/hooks/types.ts"],"names":[],"mappings":"AAmEA,kDAAkD;AAClD,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,KAAgB;IACvD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,EAAE,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QACpC,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc;YAAE,SAAS;QAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCopyToClipboard.d.ts","sourceRoot":"","sources":["../../../src/web/hooks/useCopyToClipboard.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,wBAAgB,kBAAkB,CAAC,OAAO,SAAO;iBAKhC,MAAM;;EActB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
|
+
/** Web-only clipboard hook with visual feedback. */
|
|
3
|
+
export function useCopyToClipboard(resetMs = 2000) {
|
|
4
|
+
const [copied, setCopied] = useState(false);
|
|
5
|
+
const timerRef = useRef(null);
|
|
6
|
+
const copy = useCallback(async (text) => {
|
|
7
|
+
try {
|
|
8
|
+
await navigator.clipboard.writeText(text);
|
|
9
|
+
setCopied(true);
|
|
10
|
+
if (timerRef.current)
|
|
11
|
+
clearTimeout(timerRef.current);
|
|
12
|
+
timerRef.current = setTimeout(() => setCopied(false), resetMs);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
console.error("failed to copy to clipboard");
|
|
16
|
+
}
|
|
17
|
+
}, [resetMs]);
|
|
18
|
+
return { copy, copied };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=useCopyToClipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCopyToClipboard.js","sourceRoot":"","sources":["../../../src/web/hooks/useCopyToClipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtD,oDAAoD;AACpD,MAAM,UAAU,kBAAkB,CAAC,OAAO,GAAG,IAAI;IAC/C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAuC,IAAI,CAAC,CAAC;IAEpE,MAAM,IAAI,GAAG,WAAW,CACtB,KAAK,EAAE,IAAY,EAAE,EAAE;QACrB,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC1C,SAAS,CAAC,IAAI,CAAC,CAAC;YAChB,IAAI,QAAQ,CAAC,OAAO;gBAAE,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACrD,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;QACjE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SessionWithNav } from "../api/navTree.js";
|
|
2
|
+
type PaymentCallbacks = {
|
|
3
|
+
onOpen?: () => void;
|
|
4
|
+
onPaymentStarted?: () => void;
|
|
5
|
+
onPaymentCompleted?: () => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Manages payment lifecycle callbacks:
|
|
9
|
+
* - onOpen: when modal opens
|
|
10
|
+
* - onPaymentStarted: when first fulfillment is detected
|
|
11
|
+
* - onPaymentCompleted: when session completes
|
|
12
|
+
*/
|
|
13
|
+
export declare function usePaymentCallbacks(session: SessionWithNav, isOpen: boolean, callbacks: PaymentCallbacks): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=usePaymentCallbacks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePaymentCallbacks.d.ts","sourceRoot":"","sources":["../../../src/web/hooks/usePaymentCallbacks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,KAAK,gBAAgB,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,gBAAgB,QAmB5B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Manages payment lifecycle callbacks:
|
|
4
|
+
* - onOpen: when modal opens
|
|
5
|
+
* - onPaymentStarted: when first fulfillment is detected
|
|
6
|
+
* - onPaymentCompleted: when session completes
|
|
7
|
+
*/
|
|
8
|
+
export function usePaymentCallbacks(session, isOpen, callbacks) {
|
|
9
|
+
const isStarted = session.status === "processing" ||
|
|
10
|
+
session.status === "succeeded" ||
|
|
11
|
+
session.status === "bounced";
|
|
12
|
+
const isCompleted = session.status === "succeeded";
|
|
13
|
+
const { onOpen, onPaymentStarted, onPaymentCompleted } = callbacks;
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (isOpen)
|
|
16
|
+
onOpen?.();
|
|
17
|
+
}, [session.sessionId, isOpen, onOpen]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (isStarted)
|
|
20
|
+
onPaymentStarted?.();
|
|
21
|
+
}, [session.sessionId, isStarted, onPaymentStarted]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (isCompleted)
|
|
24
|
+
onPaymentCompleted?.();
|
|
25
|
+
}, [session.sessionId, isCompleted, onPaymentCompleted]);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=usePaymentCallbacks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePaymentCallbacks.js","sourceRoot":"","sources":["../../../src/web/hooks/usePaymentCallbacks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUlC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAuB,EACvB,MAAe,EACf,SAA2B;IAE3B,MAAM,SAAS,GACb,OAAO,CAAC,MAAM,KAAK,YAAY;QAC/B,OAAO,CAAC,MAAM,KAAK,WAAW;QAC9B,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC;IAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC;IAEnD,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAC;IAEnE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,MAAM;YAAE,MAAM,EAAE,EAAE,CAAC;IACzB,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACxC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS;YAAE,gBAAgB,EAAE,EAAE,CAAC;IACtC,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACrD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,WAAW;YAAE,kBAAkB,EAAE,EAAE,CAAC;IAC1C,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SessionWithNav } from "../api/navTree.js";
|
|
2
|
+
import type { WalletPaymentOption } from "../api/walletTypes.js";
|
|
3
|
+
import { type NavNodeType } from "./navEvent.js";
|
|
4
|
+
import { type NavEntry } from "./types.js";
|
|
5
|
+
type NodeContext = {
|
|
6
|
+
nodeId: string | null;
|
|
7
|
+
nodeType: NavNodeType | null;
|
|
8
|
+
};
|
|
9
|
+
type SessionNavResult = {
|
|
10
|
+
stack: NavEntry[];
|
|
11
|
+
topEntry: NavEntry | null;
|
|
12
|
+
getNodeCtx: () => NodeContext;
|
|
13
|
+
canGoBack: boolean;
|
|
14
|
+
handleNavigate: (nodeId: string, options?: {
|
|
15
|
+
autoNav?: boolean;
|
|
16
|
+
}) => void;
|
|
17
|
+
handleBack: () => void;
|
|
18
|
+
handleAmountContinue: (amountUsd: number) => void;
|
|
19
|
+
handleRetry: () => void;
|
|
20
|
+
handleRefresh: () => Promise<void>;
|
|
21
|
+
handleWalletConnected: () => void;
|
|
22
|
+
handleWalletSelectToken: (token: WalletPaymentOption) => void;
|
|
23
|
+
handleWalletSending: (token: WalletPaymentOption, amountUsd: number) => void;
|
|
24
|
+
handleWalletTxResult: (txHash?: string, error?: string) => void;
|
|
25
|
+
};
|
|
26
|
+
export declare function useSessionNav(session: SessionWithNav, setSession: React.Dispatch<React.SetStateAction<SessionWithNav>>, platform?: "ios" | "android" | "other"): SessionNavResult;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=useSessionNav.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionNav.d.ts","sourceRoot":"","sources":["../../../src/web/hooks/useSessionNav.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAKjE,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAErD,KAAK,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3E,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,WAAW,CAAC;IAC9B,SAAS,EAAE,OAAO,CAAC;IAEnB,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1E,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,oBAAoB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,uBAAuB,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC9D,mBAAmB,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7E,oBAAoB,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACjE,CAAC;AAEF,wBAAgB,aAAa,CAC3B,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,EAChE,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,OAAO,GACrC,gBAAgB,CAmelB"}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { useDaimoClient } from "./DaimoClientContext.js";
|
|
3
|
+
import { t } from "./locale.js";
|
|
4
|
+
import { createNavLogger } from "./navEvent.js";
|
|
5
|
+
import { findNode } from "./types.js";
|
|
6
|
+
export function useSessionNav(session, setSession, platform) {
|
|
7
|
+
const client = useDaimoClient();
|
|
8
|
+
const logNavEvent = createNavLogger(client);
|
|
9
|
+
const [stack, setStack] = useState([]);
|
|
10
|
+
const topEntry = stack.length > 0 ? stack[stack.length - 1] : null;
|
|
11
|
+
const getNodeCtx = useCallback(() => {
|
|
12
|
+
const nodeId = topEntry?.nodeId ?? session.navTree[0]?.id ?? null;
|
|
13
|
+
const nodeType = nodeId
|
|
14
|
+
? (findNode(nodeId, session.navTree)?.type ?? null)
|
|
15
|
+
: null;
|
|
16
|
+
return { nodeId, nodeType };
|
|
17
|
+
}, [topEntry, session.navTree]);
|
|
18
|
+
const canGoBack = stack.length > 0 && stack.some((e) => !e.autoNav);
|
|
19
|
+
// ─── Async fetchers ─────────────────────────────────────────────────────
|
|
20
|
+
const fetchTronAddress = useCallback(async (nodeId, amountUsd) => {
|
|
21
|
+
try {
|
|
22
|
+
const result = await client.sessions.paymentMethods.create(session.sessionId, {
|
|
23
|
+
clientSecret: session.clientSecret,
|
|
24
|
+
paymentMethod: { type: "tron", amountUsd },
|
|
25
|
+
});
|
|
26
|
+
if (!result.tron) {
|
|
27
|
+
throw new Error("tron address not returned");
|
|
28
|
+
}
|
|
29
|
+
logNavEvent(session.sessionId, session.clientSecret, {
|
|
30
|
+
nodeId,
|
|
31
|
+
nodeType: "TronDeposit",
|
|
32
|
+
action: "flow_tron_address",
|
|
33
|
+
success: true,
|
|
34
|
+
address: result.tron.receiverAddress,
|
|
35
|
+
});
|
|
36
|
+
setStack((prev) => {
|
|
37
|
+
const top = prev[prev.length - 1];
|
|
38
|
+
if (top?.type !== "waiting-tron" || top.nodeId !== nodeId)
|
|
39
|
+
return prev;
|
|
40
|
+
return [
|
|
41
|
+
...prev.slice(0, -1),
|
|
42
|
+
{
|
|
43
|
+
...top,
|
|
44
|
+
address: result.tron.receiverAddress,
|
|
45
|
+
expiresAt: result.tron.expiresAt,
|
|
46
|
+
error: undefined,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error("failed to create tron address:", error);
|
|
53
|
+
const errorMsg = error instanceof Error ? error.message : t.tronUnavailable;
|
|
54
|
+
logNavEvent(session.sessionId, session.clientSecret, {
|
|
55
|
+
nodeId,
|
|
56
|
+
nodeType: "TronDeposit",
|
|
57
|
+
action: "flow_tron_address",
|
|
58
|
+
success: false,
|
|
59
|
+
error: errorMsg,
|
|
60
|
+
});
|
|
61
|
+
setStack((prev) => {
|
|
62
|
+
const top = prev[prev.length - 1];
|
|
63
|
+
if (top?.type !== "waiting-tron" || top.nodeId !== nodeId)
|
|
64
|
+
return prev;
|
|
65
|
+
return [...prev.slice(0, -1), { ...top, error: errorMsg }];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}, [session.sessionId, session.clientSecret, client]);
|
|
69
|
+
const fetchExchangeUrl = useCallback(async (nodeId, exchangeId, amountUsd) => {
|
|
70
|
+
try {
|
|
71
|
+
const result = await client.sessions.paymentMethods.create(session.sessionId, {
|
|
72
|
+
clientSecret: session.clientSecret,
|
|
73
|
+
paymentMethod: {
|
|
74
|
+
type: "exchange",
|
|
75
|
+
exchangeId: exchangeId,
|
|
76
|
+
amountUsd,
|
|
77
|
+
platform,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
if (!result.exchange)
|
|
81
|
+
return;
|
|
82
|
+
logNavEvent(session.sessionId, session.clientSecret, {
|
|
83
|
+
nodeId,
|
|
84
|
+
nodeType: "Exchange",
|
|
85
|
+
action: "flow_exchange_url",
|
|
86
|
+
exchangeId,
|
|
87
|
+
success: true,
|
|
88
|
+
url: result.exchange.url,
|
|
89
|
+
});
|
|
90
|
+
setStack((prev) => {
|
|
91
|
+
const top = prev[prev.length - 1];
|
|
92
|
+
if (top?.type !== "exchange-page" || top.nodeId !== nodeId)
|
|
93
|
+
return prev;
|
|
94
|
+
return [
|
|
95
|
+
...prev.slice(0, -1),
|
|
96
|
+
{
|
|
97
|
+
...top,
|
|
98
|
+
exchangeUrl: result.exchange.url,
|
|
99
|
+
waitingMessage: result.exchange.waitingMessage,
|
|
100
|
+
error: undefined,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error("failed to get exchange url:", error);
|
|
107
|
+
const errorMsg = error instanceof Error ? error.message : "failed to get exchange url";
|
|
108
|
+
logNavEvent(session.sessionId, session.clientSecret, {
|
|
109
|
+
nodeId,
|
|
110
|
+
nodeType: "Exchange",
|
|
111
|
+
action: "flow_exchange_url",
|
|
112
|
+
exchangeId,
|
|
113
|
+
success: false,
|
|
114
|
+
error: errorMsg,
|
|
115
|
+
});
|
|
116
|
+
setStack((prev) => {
|
|
117
|
+
const top = prev[prev.length - 1];
|
|
118
|
+
if (top?.type !== "exchange-page" || top.nodeId !== nodeId)
|
|
119
|
+
return prev;
|
|
120
|
+
return [...prev.slice(0, -1), { ...top, error: errorMsg }];
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}, [session.sessionId, session.clientSecret, platform, client]);
|
|
124
|
+
// ─── Navigation handlers ────────────────────────────────────────────────
|
|
125
|
+
const handleNavigate = useCallback((nodeId, options) => {
|
|
126
|
+
const nodeCtx = getNodeCtx();
|
|
127
|
+
const targetNode = findNode(nodeId, session.navTree);
|
|
128
|
+
if (!targetNode)
|
|
129
|
+
return;
|
|
130
|
+
const autoNav = options?.autoNav ?? false;
|
|
131
|
+
if (targetNode.type === "Deeplink" && targetNode.url) {
|
|
132
|
+
logNavEvent(session.sessionId, session.clientSecret, {
|
|
133
|
+
...nodeCtx,
|
|
134
|
+
action: "nav_deeplink",
|
|
135
|
+
url: targetNode.url,
|
|
136
|
+
});
|
|
137
|
+
window.open(targetNode.url, "_blank");
|
|
138
|
+
}
|
|
139
|
+
logNavEvent(session.sessionId, session.clientSecret, {
|
|
140
|
+
...nodeCtx,
|
|
141
|
+
action: "nav_select",
|
|
142
|
+
targetNodeId: nodeId,
|
|
143
|
+
targetNodeType: targetNode.type,
|
|
144
|
+
});
|
|
145
|
+
if (targetNode.type === "ChooseOption") {
|
|
146
|
+
setStack((prev) => [
|
|
147
|
+
...prev,
|
|
148
|
+
{ type: "choose-option", nodeId, autoNav },
|
|
149
|
+
]);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (targetNode.type === "Deeplink") {
|
|
153
|
+
setStack((prev) => [...prev, { type: "deeplink", nodeId, autoNav }]);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (targetNode.type === "ConnectedWallet") {
|
|
157
|
+
setStack((prev) => [
|
|
158
|
+
...prev,
|
|
159
|
+
{ type: "wallet-connect", nodeId, autoNav },
|
|
160
|
+
]);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const { amountUnits, tokenSymbol } = session.destination;
|
|
164
|
+
if (amountUnits) {
|
|
165
|
+
console.assert(tokenSymbol.includes("USD"), `expected USD destination, got ${tokenSymbol}`);
|
|
166
|
+
}
|
|
167
|
+
const requiredUsd = amountUnits ? parseFloat(amountUnits) : 0;
|
|
168
|
+
if (targetNode.type === "DepositAddress") {
|
|
169
|
+
if (requiredUsd > 0) {
|
|
170
|
+
setStack((prev) => [
|
|
171
|
+
...prev,
|
|
172
|
+
{
|
|
173
|
+
type: "waiting-deposit",
|
|
174
|
+
nodeId,
|
|
175
|
+
amountUsd: requiredUsd,
|
|
176
|
+
autoNav,
|
|
177
|
+
},
|
|
178
|
+
]);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
setStack((prev) => [
|
|
182
|
+
...prev,
|
|
183
|
+
{ type: "select-amount", nodeId, flowType: "deposit", autoNav },
|
|
184
|
+
]);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (targetNode.type === "TronDeposit") {
|
|
188
|
+
if (requiredUsd > 0) {
|
|
189
|
+
setStack((prev) => [
|
|
190
|
+
...prev,
|
|
191
|
+
{
|
|
192
|
+
type: "waiting-tron",
|
|
193
|
+
nodeId,
|
|
194
|
+
amountUsd: requiredUsd,
|
|
195
|
+
autoNav,
|
|
196
|
+
},
|
|
197
|
+
]);
|
|
198
|
+
fetchTronAddress(nodeId, requiredUsd);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
setStack((prev) => [
|
|
202
|
+
...prev,
|
|
203
|
+
{ type: "select-amount", nodeId, flowType: "tron", autoNav },
|
|
204
|
+
]);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (targetNode.type === "Exchange") {
|
|
208
|
+
if (requiredUsd > 0) {
|
|
209
|
+
setStack((prev) => [
|
|
210
|
+
...prev,
|
|
211
|
+
{ type: "exchange-page", nodeId, amountUsd: requiredUsd, autoNav },
|
|
212
|
+
]);
|
|
213
|
+
fetchExchangeUrl(nodeId, targetNode.exchangeId, requiredUsd);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
setStack((prev) => [
|
|
217
|
+
...prev,
|
|
218
|
+
{ type: "select-amount", nodeId, flowType: "exchange", autoNav },
|
|
219
|
+
]);
|
|
220
|
+
}
|
|
221
|
+
}, [
|
|
222
|
+
session.navTree,
|
|
223
|
+
session.sessionId,
|
|
224
|
+
session.destination,
|
|
225
|
+
getNodeCtx,
|
|
226
|
+
fetchTronAddress,
|
|
227
|
+
fetchExchangeUrl,
|
|
228
|
+
]);
|
|
229
|
+
const handleBack = useCallback(() => {
|
|
230
|
+
logNavEvent(session.sessionId, session.clientSecret, { ...getNodeCtx(), action: "nav_back" });
|
|
231
|
+
setStack((prev) => {
|
|
232
|
+
if (prev.length === 0)
|
|
233
|
+
return prev;
|
|
234
|
+
const next = prev.slice(0, -1);
|
|
235
|
+
while (next.length > 0) {
|
|
236
|
+
const top = next[next.length - 1];
|
|
237
|
+
if (!top.autoNav)
|
|
238
|
+
break;
|
|
239
|
+
if (top.type === "select-amount")
|
|
240
|
+
break;
|
|
241
|
+
if (top.type === "choose-option") {
|
|
242
|
+
const node = findNode(top.nodeId, session.navTree);
|
|
243
|
+
if (node != null && node.options.length > 1)
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
next.pop();
|
|
247
|
+
}
|
|
248
|
+
return next;
|
|
249
|
+
});
|
|
250
|
+
}, [session.sessionId, session.navTree, getNodeCtx]);
|
|
251
|
+
// ─── Flow handlers ──────────────────────────────────────────────────────
|
|
252
|
+
const handleAmountContinue = useCallback((amountUsd) => {
|
|
253
|
+
if (!topEntry || topEntry.type !== "select-amount")
|
|
254
|
+
return;
|
|
255
|
+
const { nodeId, flowType } = topEntry;
|
|
256
|
+
logNavEvent(session.sessionId, session.clientSecret, {
|
|
257
|
+
nodeId,
|
|
258
|
+
nodeType: flowType === "deposit"
|
|
259
|
+
? "DepositAddress"
|
|
260
|
+
: flowType === "tron"
|
|
261
|
+
? "TronDeposit"
|
|
262
|
+
: "Exchange",
|
|
263
|
+
action: "flow_amount_continue",
|
|
264
|
+
amountUsd,
|
|
265
|
+
});
|
|
266
|
+
if (flowType === "deposit") {
|
|
267
|
+
setStack((prev) => [
|
|
268
|
+
...prev,
|
|
269
|
+
{ type: "waiting-deposit", nodeId, amountUsd },
|
|
270
|
+
]);
|
|
271
|
+
}
|
|
272
|
+
else if (flowType === "tron") {
|
|
273
|
+
setStack((prev) => [
|
|
274
|
+
...prev,
|
|
275
|
+
{ type: "waiting-tron", nodeId, amountUsd },
|
|
276
|
+
]);
|
|
277
|
+
fetchTronAddress(nodeId, amountUsd);
|
|
278
|
+
}
|
|
279
|
+
else if (flowType === "exchange") {
|
|
280
|
+
const node = findNode(nodeId, session.navTree);
|
|
281
|
+
setStack((prev) => [
|
|
282
|
+
...prev,
|
|
283
|
+
{ type: "exchange-page", nodeId, amountUsd },
|
|
284
|
+
]);
|
|
285
|
+
if (node)
|
|
286
|
+
fetchExchangeUrl(nodeId, node.exchangeId, amountUsd);
|
|
287
|
+
}
|
|
288
|
+
}, [
|
|
289
|
+
topEntry,
|
|
290
|
+
session.sessionId,
|
|
291
|
+
session.navTree,
|
|
292
|
+
fetchTronAddress,
|
|
293
|
+
fetchExchangeUrl,
|
|
294
|
+
]);
|
|
295
|
+
const handleRetry = useCallback(() => {
|
|
296
|
+
if (!topEntry)
|
|
297
|
+
return;
|
|
298
|
+
if (topEntry.type === "waiting-tron") {
|
|
299
|
+
setStack((prev) => {
|
|
300
|
+
const top = prev[prev.length - 1];
|
|
301
|
+
if (top?.type !== "waiting-tron")
|
|
302
|
+
return prev;
|
|
303
|
+
return [
|
|
304
|
+
...prev.slice(0, -1),
|
|
305
|
+
{
|
|
306
|
+
...top,
|
|
307
|
+
address: undefined,
|
|
308
|
+
expiresAt: undefined,
|
|
309
|
+
error: undefined,
|
|
310
|
+
},
|
|
311
|
+
];
|
|
312
|
+
});
|
|
313
|
+
fetchTronAddress(topEntry.nodeId, topEntry.amountUsd);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (topEntry.type === "exchange-page") {
|
|
317
|
+
const node = findNode(topEntry.nodeId, session.navTree);
|
|
318
|
+
if (!node)
|
|
319
|
+
return;
|
|
320
|
+
setStack((prev) => {
|
|
321
|
+
const top = prev[prev.length - 1];
|
|
322
|
+
if (top?.type !== "exchange-page")
|
|
323
|
+
return prev;
|
|
324
|
+
return [
|
|
325
|
+
...prev.slice(0, -1),
|
|
326
|
+
{ ...top, exchangeUrl: undefined, error: undefined },
|
|
327
|
+
];
|
|
328
|
+
});
|
|
329
|
+
fetchExchangeUrl(topEntry.nodeId, node.exchangeId, topEntry.amountUsd);
|
|
330
|
+
}
|
|
331
|
+
}, [topEntry, session.navTree, fetchTronAddress, fetchExchangeUrl]);
|
|
332
|
+
const handleRefresh = useCallback(async () => {
|
|
333
|
+
logNavEvent(session.sessionId, session.clientSecret, { ...getNodeCtx(), action: "flow_refresh" });
|
|
334
|
+
try {
|
|
335
|
+
const { session: newSession } = await client.internal.sessions.recreate(session.sessionId, session.clientSecret);
|
|
336
|
+
setStack([]);
|
|
337
|
+
setSession(newSession);
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
console.error("failed to recreate session:", error);
|
|
341
|
+
}
|
|
342
|
+
}, [session.sessionId, session.clientSecret, getNodeCtx, setSession, client]);
|
|
343
|
+
// ─── Wallet flow handlers ───────────────────────────────────────────────
|
|
344
|
+
const handleWalletConnected = useCallback(() => {
|
|
345
|
+
if (topEntry?.type !== "wallet-connect")
|
|
346
|
+
return;
|
|
347
|
+
setStack((prev) => [
|
|
348
|
+
...prev,
|
|
349
|
+
{ type: "wallet-select-token", nodeId: topEntry.nodeId },
|
|
350
|
+
]);
|
|
351
|
+
}, [topEntry]);
|
|
352
|
+
const handleWalletSelectToken = useCallback((token) => {
|
|
353
|
+
if (topEntry?.type !== "wallet-select-token")
|
|
354
|
+
return;
|
|
355
|
+
const { amountUnits } = session.destination;
|
|
356
|
+
const requiredUsd = amountUnits ? parseFloat(amountUnits) : 0;
|
|
357
|
+
if (requiredUsd > 0) {
|
|
358
|
+
setStack((prev) => [
|
|
359
|
+
...prev,
|
|
360
|
+
{
|
|
361
|
+
type: "wallet-sending",
|
|
362
|
+
nodeId: topEntry.nodeId,
|
|
363
|
+
token,
|
|
364
|
+
amountUsd: requiredUsd,
|
|
365
|
+
},
|
|
366
|
+
]);
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
setStack((prev) => [
|
|
370
|
+
...prev,
|
|
371
|
+
{ type: "wallet-select-amount", nodeId: topEntry.nodeId, token },
|
|
372
|
+
]);
|
|
373
|
+
}
|
|
374
|
+
}, [topEntry, session.destination]);
|
|
375
|
+
const handleWalletSending = useCallback((token, amountUsd) => {
|
|
376
|
+
if (topEntry?.type !== "wallet-select-amount" &&
|
|
377
|
+
topEntry?.type !== "wallet-select-token")
|
|
378
|
+
return;
|
|
379
|
+
setStack((prev) => [
|
|
380
|
+
...prev,
|
|
381
|
+
{ type: "wallet-sending", nodeId: topEntry.nodeId, token, amountUsd },
|
|
382
|
+
]);
|
|
383
|
+
}, [topEntry]);
|
|
384
|
+
const handleWalletTxResult = useCallback((txHash, error) => {
|
|
385
|
+
setStack((prev) => {
|
|
386
|
+
const top = prev[prev.length - 1];
|
|
387
|
+
if (top?.type !== "wallet-sending")
|
|
388
|
+
return prev;
|
|
389
|
+
return [...prev.slice(0, -1), { ...top, txHash, error }];
|
|
390
|
+
});
|
|
391
|
+
}, []);
|
|
392
|
+
return useMemo(() => ({
|
|
393
|
+
stack,
|
|
394
|
+
topEntry,
|
|
395
|
+
getNodeCtx,
|
|
396
|
+
canGoBack,
|
|
397
|
+
handleNavigate,
|
|
398
|
+
handleBack,
|
|
399
|
+
handleAmountContinue,
|
|
400
|
+
handleRetry,
|
|
401
|
+
handleRefresh,
|
|
402
|
+
handleWalletConnected,
|
|
403
|
+
handleWalletSelectToken,
|
|
404
|
+
handleWalletSending,
|
|
405
|
+
handleWalletTxResult,
|
|
406
|
+
}), [
|
|
407
|
+
stack,
|
|
408
|
+
topEntry,
|
|
409
|
+
getNodeCtx,
|
|
410
|
+
canGoBack,
|
|
411
|
+
handleNavigate,
|
|
412
|
+
handleBack,
|
|
413
|
+
handleAmountContinue,
|
|
414
|
+
handleRetry,
|
|
415
|
+
handleRefresh,
|
|
416
|
+
handleWalletConnected,
|
|
417
|
+
handleWalletSelectToken,
|
|
418
|
+
handleWalletSending,
|
|
419
|
+
handleWalletTxResult,
|
|
420
|
+
]);
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=useSessionNav.js.map
|