@silentswap/react 0.0.79 → 0.0.80
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/contexts/OrdersContext.d.ts +5 -0
- package/dist/contexts/OrdersContext.js +52 -0
- package/dist/contexts/orderTrackingConnection.d.ts +19 -0
- package/dist/contexts/orderTrackingConnection.js +327 -0
- package/dist/contexts/orderTrackingTypes.d.ts +149 -0
- package/dist/contexts/orderTrackingTypes.js +151 -0
- package/dist/hooks/silent/useBridgeExecution.d.ts +1 -1
- package/dist/hooks/silent/useBridgeExecution.js +47 -41
- package/dist/hooks/silent/useOrderTracking.d.ts +7 -148
- package/dist/hooks/silent/useOrderTracking.js +37 -622
- package/dist/hooks/silent/useSilentQuote.js +5 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types and helpers for order tracking (WebSocket + context).
|
|
3
|
+
* Used by orderTrackingConnection.ts and useOrderTracking.ts.
|
|
4
|
+
*/
|
|
5
|
+
export var OutputStage;
|
|
6
|
+
(function (OutputStage) {
|
|
7
|
+
OutputStage["NONE"] = "NONE";
|
|
8
|
+
OutputStage["INIT"] = "INIT";
|
|
9
|
+
OutputStage["FUNDED"] = "FUNDED";
|
|
10
|
+
OutputStage["REDEEMED"] = "REDEEMED";
|
|
11
|
+
OutputStage["IBC_SENT"] = "IBC_SENT";
|
|
12
|
+
OutputStage["IBC_RCVD"] = "IBC_RCVD";
|
|
13
|
+
OutputStage["BRIDGE_SENT"] = "BRIDGE_SENT";
|
|
14
|
+
OutputStage["BRIDGE_CFRM"] = "BRIDGE_CFRM";
|
|
15
|
+
OutputStage["BRIDGE_RCVD"] = "BRIDGE_RCVD";
|
|
16
|
+
OutputStage["SWAP_USDC_GAS"] = "SWAP_USDC_GAS";
|
|
17
|
+
OutputStage["SWAP_USDC_TRG"] = "SWAP_USDC_TRG";
|
|
18
|
+
OutputStage["LTRL_TRG_SENT"] = "LTRL_TRG_SENT";
|
|
19
|
+
OutputStage["LTRL_TRG_RCVD"] = "LTRL_TRG_RCVD";
|
|
20
|
+
OutputStage["SWAP_TRG_DST"] = "SWAP_TRG_DST";
|
|
21
|
+
OutputStage["XFER_TRG_DST"] = "XFER_TRG_DST";
|
|
22
|
+
OutputStage["REFUND_NATIVE"] = "REFUND_NATIVE";
|
|
23
|
+
OutputStage["FINALIZED"] = "FINALIZED";
|
|
24
|
+
})(OutputStage || (OutputStage = {}));
|
|
25
|
+
export const DEFAULT_ORDER_TRACKING_STATE = {
|
|
26
|
+
isConnected: false,
|
|
27
|
+
isLoading: false,
|
|
28
|
+
error: null,
|
|
29
|
+
orderStatus: null,
|
|
30
|
+
deposit: null,
|
|
31
|
+
outputs: [],
|
|
32
|
+
progresses: [undefined],
|
|
33
|
+
statusTexts: ['Connecting'],
|
|
34
|
+
completedTimestamp: null,
|
|
35
|
+
isComplete: false,
|
|
36
|
+
};
|
|
37
|
+
export function getStatusTextFromStage(stage) {
|
|
38
|
+
switch (stage) {
|
|
39
|
+
case OutputStage.NONE:
|
|
40
|
+
return 'Uncertain state';
|
|
41
|
+
case OutputStage.INIT:
|
|
42
|
+
return 'Verifying deposit';
|
|
43
|
+
case OutputStage.FUNDED:
|
|
44
|
+
return 'Initializing';
|
|
45
|
+
case OutputStage.REDEEMED:
|
|
46
|
+
return 'Anonymizing';
|
|
47
|
+
case OutputStage.IBC_SENT:
|
|
48
|
+
return 'Moving';
|
|
49
|
+
case OutputStage.IBC_RCVD:
|
|
50
|
+
return 'Staging';
|
|
51
|
+
case OutputStage.BRIDGE_SENT:
|
|
52
|
+
case OutputStage.BRIDGE_CFRM:
|
|
53
|
+
case OutputStage.BRIDGE_RCVD:
|
|
54
|
+
return 'Bridging';
|
|
55
|
+
case OutputStage.SWAP_USDC_GAS:
|
|
56
|
+
return 'Fueling';
|
|
57
|
+
case OutputStage.SWAP_USDC_TRG:
|
|
58
|
+
return 'Swapping';
|
|
59
|
+
case OutputStage.LTRL_TRG_SENT:
|
|
60
|
+
case OutputStage.LTRL_TRG_RCVD:
|
|
61
|
+
case OutputStage.SWAP_TRG_DST:
|
|
62
|
+
return 'Finalizing';
|
|
63
|
+
case OutputStage.XFER_TRG_DST:
|
|
64
|
+
case OutputStage.REFUND_NATIVE:
|
|
65
|
+
case OutputStage.FINALIZED:
|
|
66
|
+
return 'Completed';
|
|
67
|
+
default:
|
|
68
|
+
return 'Processing';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function getProgressFromStage(stage) {
|
|
72
|
+
switch (stage) {
|
|
73
|
+
case OutputStage.NONE:
|
|
74
|
+
case OutputStage.INIT:
|
|
75
|
+
return 0;
|
|
76
|
+
case OutputStage.FUNDED:
|
|
77
|
+
return 0.1;
|
|
78
|
+
case OutputStage.REDEEMED:
|
|
79
|
+
return 0.15;
|
|
80
|
+
case OutputStage.IBC_SENT:
|
|
81
|
+
return 0.25;
|
|
82
|
+
case OutputStage.IBC_RCVD:
|
|
83
|
+
return 0.35;
|
|
84
|
+
case OutputStage.BRIDGE_SENT:
|
|
85
|
+
return 0.5;
|
|
86
|
+
case OutputStage.BRIDGE_CFRM:
|
|
87
|
+
return 0.6;
|
|
88
|
+
case OutputStage.BRIDGE_RCVD:
|
|
89
|
+
return 0.7;
|
|
90
|
+
case OutputStage.SWAP_USDC_GAS:
|
|
91
|
+
return 0.8;
|
|
92
|
+
case OutputStage.SWAP_USDC_TRG:
|
|
93
|
+
return 0.9;
|
|
94
|
+
case OutputStage.LTRL_TRG_SENT:
|
|
95
|
+
case OutputStage.LTRL_TRG_RCVD:
|
|
96
|
+
case OutputStage.SWAP_TRG_DST:
|
|
97
|
+
return 0.95;
|
|
98
|
+
case OutputStage.XFER_TRG_DST:
|
|
99
|
+
case OutputStage.REFUND_NATIVE:
|
|
100
|
+
case OutputStage.FINALIZED:
|
|
101
|
+
return 1;
|
|
102
|
+
default:
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function getOrderTrackingCacheKey(orderId, auth) {
|
|
107
|
+
return `${orderId}|${auth}`;
|
|
108
|
+
}
|
|
109
|
+
export function hasFinalizedOutput(status) {
|
|
110
|
+
return status.outputs?.some((o) => o.stage === OutputStage.FINALIZED) ?? false;
|
|
111
|
+
}
|
|
112
|
+
const STATUS_UPDATE_TYPES = ['deposit', 'stage', 'transaction', 'error'];
|
|
113
|
+
export function isFullOrderStatus(result) {
|
|
114
|
+
if (typeof result !== 'object' || result === null)
|
|
115
|
+
return false;
|
|
116
|
+
const r = result;
|
|
117
|
+
const hasOutputs = Array.isArray(r.outputs) && r.outputs.length > 0;
|
|
118
|
+
const hasType = typeof r.type === 'string' && STATUS_UPDATE_TYPES.includes(r.type);
|
|
119
|
+
return hasOutputs && !hasType;
|
|
120
|
+
}
|
|
121
|
+
export function buildOrderTrackingWsUrl(client) {
|
|
122
|
+
let wsUrl;
|
|
123
|
+
if (typeof window !== 'undefined' && window.__WEBSOCKET_URL__) {
|
|
124
|
+
wsUrl = window.__WEBSOCKET_URL__;
|
|
125
|
+
}
|
|
126
|
+
else if (client) {
|
|
127
|
+
const baseUrl = client.baseUrl;
|
|
128
|
+
try {
|
|
129
|
+
const url = new URL(baseUrl);
|
|
130
|
+
wsUrl = `${url.protocol === 'https:' ? 'wss:' : 'ws:'}//${url.host}/websocket`;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
wsUrl = baseUrl.replace(/^https?:\/\//, 'wss://').replace(/^http:\/\//, 'ws://') + '/websocket';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (typeof window !== 'undefined') {
|
|
137
|
+
wsUrl = `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.host}/websocket`;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
wsUrl = 'ws://localhost/websocket';
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const url = new URL(wsUrl);
|
|
144
|
+
const protocol = url.protocol === 'https:' || url.protocol === 'wss:' ? 'wss:' : 'ws:';
|
|
145
|
+
wsUrl = `${protocol}//${url.host}/websocket`;
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
wsUrl = wsUrl.split('?')[0].split('#')[0].replace(/\/+$/, '') + '/websocket';
|
|
149
|
+
}
|
|
150
|
+
return wsUrl;
|
|
151
|
+
}
|
|
@@ -39,5 +39,5 @@ export interface BridgeExecutionResult {
|
|
|
39
39
|
export declare function useBridgeExecution(walletClient: WalletClient | undefined, connector: Connector | undefined, solanaConnector: SolanaWalletConnector | undefined, solanaConnection: SolanaConnection | undefined, solanaRpcUrl: string | undefined, setCurrentStep: (step: string) => void, depositorAddress: Hex, onStatus?: (status: string) => void, bitcoinConnector?: BitcoinWalletConnector, bitcoinConnection?: BitcoinConnection): {
|
|
40
40
|
executeSolanaBridge: (sourceAsset: string, sourceAmount: string, usdcAmount: string | undefined, solanaSenderAddress: string, evmSignerAddress: `0x${string}`, depositParams?: DepositParams<`${bigint}`>) => Promise<BridgeExecutionResult>;
|
|
41
41
|
executeBitcoinBridge: (sourceAsset: string, sourceAmount: string, usdcAmount: string | undefined, bitcoinSenderAddress: string, evmSignerAddress: `0x${string}`, depositParams?: DepositParams<`${bigint}`>) => Promise<BridgeExecutionResult>;
|
|
42
|
-
executeEvmBridge: (sourceChainId: number, sourceTokenAddress: string, sourceAmount: string, usdcAmount: string | undefined, depositParams: DepositParams<`${bigint}`>, evmSignerAddress: `0x${string}`, evmSenderAddress?: `0x${string}`, provider?: "relay" | "debridge") => Promise<BridgeExecutionResult>;
|
|
42
|
+
executeEvmBridge: (sourceChainId: number, sourceTokenAddress: string, sourceAmount: string, usdcAmount: string | undefined, depositParams: DepositParams<`${bigint}`>, evmSignerAddress: `0x${string}`, evmSenderAddress?: `0x${string}`, provider?: "relay" | "debridge", allowanceTarget?: string) => Promise<BridgeExecutionResult>;
|
|
43
43
|
};
|
|
@@ -582,7 +582,7 @@ export function useBridgeExecution(walletClient, connector, solanaConnector, sol
|
|
|
582
582
|
*/
|
|
583
583
|
const executeEvmBridge = useCallback(async (sourceChainId, sourceTokenAddress, sourceAmount, usdcAmount, depositParams, evmSignerAddress, // EVM signer address (must match quote request signer, used for deposit calldata)
|
|
584
584
|
evmSenderAddress, // Optional EVM sender address (used for bridge quotes, matches Svelte's s0x_sender)
|
|
585
|
-
provider) => {
|
|
585
|
+
provider, allowanceTarget) => {
|
|
586
586
|
try {
|
|
587
587
|
if (!walletClient || !connector) {
|
|
588
588
|
throw new Error('Wallet client and connector required for EVM bridge execution');
|
|
@@ -658,7 +658,7 @@ export function useBridgeExecution(walletClient, connector, solanaConnector, sol
|
|
|
658
658
|
// DeBridge will provide its own allowanceTarget from the response if needed.
|
|
659
659
|
try {
|
|
660
660
|
return await executeDebridgeBridge(sourceChainId, sourceTokenAddress, isSourceNative, bridgeUsdcAmount, depositCalldata, evmSignerAddress, // Use EVM signer address for deposit calldata
|
|
661
|
-
'', //
|
|
661
|
+
allowanceTarget ?? '', // From solve phase; create-tx with enableEstimate:false is used for approval when needed
|
|
662
662
|
depositorAddress, // Pass environment-based depositor address
|
|
663
663
|
walletClient, connector, setCurrentStep, onStatus);
|
|
664
664
|
}
|
|
@@ -835,56 +835,63 @@ walletClient, connector, setCurrentStep, onStatus) {
|
|
|
835
835
|
// For deBridge, we need to use the wallet account address, not the extracted sender address
|
|
836
836
|
// This ensures the transaction can be properly executed by the connected wallet
|
|
837
837
|
const evmUserForBridge = getWalletAccountAddress(walletClient);
|
|
838
|
+
// Match Svelte Form.svelte / silentswap.ts: do NOT send enableEstimate so the API returns the tx
|
|
839
|
+
// (with allowanceTarget/allowanceValue). Approve if needed and retry, then send. Same as Svelte.
|
|
840
|
+
const debridgeParams = {
|
|
841
|
+
account: evmUserForBridge,
|
|
842
|
+
srcChainId: sourceChainId,
|
|
843
|
+
dstChainId: NI_CHAIN_ID_AVALANCHE,
|
|
844
|
+
srcChainTokenIn: isSourceNative ? S0X_ADDR_EVM_ZERO : sourceTokenAddress,
|
|
845
|
+
dstChainTokenOut: S0X_ADDR_USDC_AVALANCHE,
|
|
846
|
+
srcChainTokenInAmount: 'auto',
|
|
847
|
+
dstChainTokenOutAmount: `${BigInt(bridgeUsdcAmount)}`,
|
|
848
|
+
dstChainTokenOutRecipient: depositorAddress,
|
|
849
|
+
prependOperatingExpenses: true,
|
|
850
|
+
srcChainOrderAuthorityAddress: evmUserForBridge,
|
|
851
|
+
srcChainRefundAddress: evmUserForBridge,
|
|
852
|
+
dstChainOrderAuthorityAddress: evmUserForBridge,
|
|
853
|
+
dlnHook: JSON.stringify({
|
|
854
|
+
type: 'evm_transaction_call',
|
|
855
|
+
data: {
|
|
856
|
+
to: depositorAddress,
|
|
857
|
+
calldata: depositCalldata,
|
|
858
|
+
gas: 500_000,
|
|
859
|
+
},
|
|
860
|
+
}),
|
|
861
|
+
// omit enableEstimate so API returns tx with allowanceTarget (matches Svelte debridge_order call)
|
|
862
|
+
};
|
|
838
863
|
while (retryCount < maxRetries) {
|
|
839
|
-
debridgeQuote = await fetchDebridgeOrder(
|
|
840
|
-
account: evmUserForBridge, // Use wallet account address (must match transaction sender)
|
|
841
|
-
srcChainId: sourceChainId,
|
|
842
|
-
dstChainId: NI_CHAIN_ID_AVALANCHE,
|
|
843
|
-
srcChainTokenIn: isSourceNative ? S0X_ADDR_EVM_ZERO : sourceTokenAddress,
|
|
844
|
-
dstChainTokenOut: S0X_ADDR_USDC_AVALANCHE,
|
|
845
|
-
srcChainTokenInAmount: 'auto',
|
|
846
|
-
dstChainTokenOutAmount: `${BigInt(bridgeUsdcAmount)}`,
|
|
847
|
-
dstChainTokenOutRecipient: depositorAddress,
|
|
848
|
-
prependOperatingExpenses: true,
|
|
849
|
-
enableEstimate: true,
|
|
850
|
-
srcChainOrderAuthorityAddress: evmUserForBridge, // Use wallet account address (must match transaction sender)
|
|
851
|
-
srcChainRefundAddress: evmUserForBridge, // Use wallet account address (must match transaction sender)
|
|
852
|
-
dstChainOrderAuthorityAddress: evmUserForBridge, // Use wallet account address (must match transaction sender)
|
|
853
|
-
dlnHook: JSON.stringify({
|
|
854
|
-
type: 'evm_transaction_call',
|
|
855
|
-
data: {
|
|
856
|
-
to: depositorAddress,
|
|
857
|
-
calldata: depositCalldata,
|
|
858
|
-
gas: 500_000,
|
|
859
|
-
},
|
|
860
|
-
}),
|
|
861
|
-
});
|
|
864
|
+
debridgeQuote = await fetchDebridgeOrder(debridgeParams);
|
|
862
865
|
debridgeTx = debridgeQuote.tx;
|
|
863
866
|
debridgeResponse = debridgeQuote;
|
|
864
|
-
//
|
|
865
|
-
|
|
867
|
+
// If approval needed, approve and retry (matches Svelte: "if(g_debridge.tx.allowanceTarget) { await approve_spender(...); continue; }")
|
|
868
|
+
// Prefer API response; use allowanceTarget param (from solve phase) as fallback when API omits it
|
|
869
|
+
const targetAllowance = debridgeTx?.allowanceTarget || allowanceTarget;
|
|
866
870
|
if (targetAllowance && !isSourceNative) {
|
|
867
|
-
const allowanceValue = debridgeTx
|
|
868
|
-
if (!allowanceValue) {
|
|
871
|
+
const allowanceValue = debridgeTx?.allowanceValue;
|
|
872
|
+
if (debridgeTx?.allowanceTarget && !allowanceValue) {
|
|
869
873
|
throw new Error('DeBridge response missing allowance value');
|
|
870
874
|
}
|
|
871
875
|
setCurrentStep('Approving token spending');
|
|
872
876
|
onStatus?.('Approving token spending');
|
|
873
|
-
// Switch to source chain for approval
|
|
874
877
|
const { publicClient } = await ensureChainAndCreateClient(sourceChainId, walletClient, connector);
|
|
878
|
+
// Match Svelte: allowance(owner, spender) where owner is the wallet that sends approve (s0x_sender)
|
|
875
879
|
const currentAllowance = (await publicClient.readContract({
|
|
876
880
|
address: sourceTokenAddress,
|
|
877
881
|
abi: erc20Abi,
|
|
878
882
|
functionName: 'allowance',
|
|
879
|
-
args: [
|
|
883
|
+
args: [evmUserForBridge, targetAllowance],
|
|
880
884
|
}));
|
|
881
|
-
//
|
|
882
|
-
|
|
885
|
+
// Need approval: when API gave a value, use it; otherwise (fallback from param) approve if allowance is zero
|
|
886
|
+
const needsApproval = allowanceValue
|
|
887
|
+
? currentAllowance < BigInt(allowanceValue)
|
|
888
|
+
: currentAllowance === 0n;
|
|
889
|
+
if (needsApproval) {
|
|
883
890
|
const hash = await walletClient.writeContract({
|
|
884
891
|
address: sourceTokenAddress,
|
|
885
892
|
abi: erc20Abi,
|
|
886
893
|
functionName: 'approve',
|
|
887
|
-
args: [targetAllowance,
|
|
894
|
+
args: [targetAllowance, XG_UINT256_MAX],
|
|
888
895
|
account: walletClient.account,
|
|
889
896
|
chain: null,
|
|
890
897
|
});
|
|
@@ -893,9 +900,8 @@ walletClient, connector, setCurrentStep, onStatus) {
|
|
|
893
900
|
retryCount++;
|
|
894
901
|
continue;
|
|
895
902
|
}
|
|
896
|
-
// Check price impact
|
|
903
|
+
// Check price impact (matches Svelte)
|
|
897
904
|
const impactPercent = (100 * (debridgeQuote.usdPriceImpact ?? 0)) / (debridgeQuote.estimation.srcChainTokenIn.approximateUsdValue || 1);
|
|
898
|
-
// TODO: check negative impact
|
|
899
905
|
if (impactPercent > X_MAX_IMPACT_PERCENT) {
|
|
900
906
|
throw new Error(`Price impact across bridge too high: ${impactPercent.toFixed(2)}%`);
|
|
901
907
|
}
|
|
@@ -904,11 +910,11 @@ walletClient, connector, setCurrentStep, onStatus) {
|
|
|
904
910
|
if (!debridgeQuote) {
|
|
905
911
|
throw new Error('Failed to get deBridge quote after approvals');
|
|
906
912
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
setCurrentStep('
|
|
910
|
-
onStatus?.('
|
|
911
|
-
// Send deBridge transaction
|
|
913
|
+
// Match Svelte: "Requesting deposit..." then ensure_chain + send (no separate "Switching"/"Sending" steps;
|
|
914
|
+
// sendTransactionAndWait does the chain switch and sets its own steps)
|
|
915
|
+
setCurrentStep('Requesting deposit...');
|
|
916
|
+
onStatus?.('Requesting deposit...');
|
|
917
|
+
// Send deBridge transaction (sendTransactionAndWait switches to sourceChainId and sends)
|
|
912
918
|
console.log('Sending deBridge transaction:', {
|
|
913
919
|
to: debridgeQuote.tx.to,
|
|
914
920
|
value: debridgeQuote.tx.value,
|
|
@@ -1,136 +1,11 @@
|
|
|
1
|
-
import type { SilentSwapClient } from '@silentswap/sdk';
|
|
2
|
-
/**
|
|
3
|
-
* Output stage enum matching Svelte's OutputStage (string values)
|
|
4
|
-
*/
|
|
5
|
-
export declare enum OutputStage {
|
|
6
|
-
NONE = "NONE",
|
|
7
|
-
INIT = "INIT",
|
|
8
|
-
FUNDED = "FUNDED",
|
|
9
|
-
REDEEMED = "REDEEMED",
|
|
10
|
-
IBC_SENT = "IBC_SENT",
|
|
11
|
-
IBC_RCVD = "IBC_RCVD",
|
|
12
|
-
BRIDGE_SENT = "BRIDGE_SENT",
|
|
13
|
-
BRIDGE_CFRM = "BRIDGE_CFRM",
|
|
14
|
-
BRIDGE_RCVD = "BRIDGE_RCVD",
|
|
15
|
-
SWAP_USDC_GAS = "SWAP_USDC_GAS",
|
|
16
|
-
SWAP_USDC_TRG = "SWAP_USDC_TRG",
|
|
17
|
-
LTRL_TRG_SENT = "LTRL_TRG_SENT",
|
|
18
|
-
LTRL_TRG_RCVD = "LTRL_TRG_RCVD",
|
|
19
|
-
SWAP_TRG_DST = "SWAP_TRG_DST",
|
|
20
|
-
XFER_TRG_DST = "XFER_TRG_DST",
|
|
21
|
-
REFUND_NATIVE = "REFUND_NATIVE",
|
|
22
|
-
FINALIZED = "FINALIZED"
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Deposit information
|
|
26
|
-
*/
|
|
27
|
-
export type OrderDeposit = {
|
|
28
|
-
amount: string;
|
|
29
|
-
timestamp: number;
|
|
30
|
-
duration: number;
|
|
31
|
-
orderId?: string;
|
|
32
|
-
tx?: string;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Output status information
|
|
36
|
-
*/
|
|
37
|
-
export type OutputStatus = {
|
|
38
|
-
index: number;
|
|
39
|
-
stage: OutputStage;
|
|
40
|
-
timestamp: number;
|
|
41
|
-
recipient?: string;
|
|
42
|
-
asset?: {
|
|
43
|
-
caip19: string;
|
|
44
|
-
amount: string;
|
|
45
|
-
decimals: number;
|
|
46
|
-
priceUsd?: number;
|
|
47
|
-
};
|
|
48
|
-
txs?: OrderTransactions;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Order transactions
|
|
52
|
-
*/
|
|
53
|
-
export type OrderTransactions = {
|
|
54
|
-
RECEIPT?: {
|
|
55
|
-
chain: string;
|
|
56
|
-
txId: string;
|
|
57
|
-
};
|
|
58
|
-
REFUND?: {
|
|
59
|
-
chain: string;
|
|
60
|
-
txId: string;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
1
|
/**
|
|
64
|
-
* Order tracking
|
|
65
|
-
|
|
66
|
-
export type OrderStatus = {
|
|
67
|
-
priority?: string;
|
|
68
|
-
signer: string;
|
|
69
|
-
deposit?: OrderDeposit;
|
|
70
|
-
outputs: Array<{
|
|
71
|
-
stage: OutputStage;
|
|
72
|
-
timestamp: number;
|
|
73
|
-
asset: string;
|
|
74
|
-
value: string;
|
|
75
|
-
recipient: string;
|
|
76
|
-
txs?: OrderTransactions;
|
|
77
|
-
output?: {
|
|
78
|
-
caip19: string;
|
|
79
|
-
amount: string;
|
|
80
|
-
decimals: number;
|
|
81
|
-
priceUsd?: number;
|
|
82
|
-
};
|
|
83
|
-
}>;
|
|
84
|
-
metadata?: {
|
|
85
|
-
sourceAsset?: {
|
|
86
|
-
caip19: string;
|
|
87
|
-
amount: string;
|
|
88
|
-
};
|
|
89
|
-
sourceSender?: {
|
|
90
|
-
contactId: string;
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Status update types (matches Svelte's StatusUpdate)
|
|
96
|
-
*/
|
|
97
|
-
export type StatusUpdate = {
|
|
98
|
-
type: 'deposit';
|
|
99
|
-
data: OrderDeposit;
|
|
100
|
-
} | {
|
|
101
|
-
type: 'stage';
|
|
102
|
-
data: {
|
|
103
|
-
orderId: string;
|
|
104
|
-
index: number;
|
|
105
|
-
stage: OutputStage;
|
|
106
|
-
timestamp: number;
|
|
107
|
-
asset?: {
|
|
108
|
-
caip19: string;
|
|
109
|
-
amount: string;
|
|
110
|
-
decimals: number;
|
|
111
|
-
priceUsd?: number;
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
} | {
|
|
115
|
-
type: 'transaction';
|
|
116
|
-
data: {
|
|
117
|
-
orderId: string;
|
|
118
|
-
index: number;
|
|
119
|
-
chain: string;
|
|
120
|
-
txId: string;
|
|
121
|
-
kind: keyof OrderTransactions;
|
|
122
|
-
};
|
|
123
|
-
} | {
|
|
124
|
-
type: 'error';
|
|
125
|
-
data: {
|
|
126
|
-
orderId: string;
|
|
127
|
-
message: string;
|
|
128
|
-
index?: number;
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* JSON-RPC error type
|
|
2
|
+
* Order tracking via WebSocket — state and connections live in OrdersContext.
|
|
3
|
+
* This hook subscribes to tracking for (orderId, auth) and returns the state from context.
|
|
133
4
|
*/
|
|
5
|
+
import type { SilentSwapClient } from '@silentswap/sdk';
|
|
6
|
+
import { type OutputStage, type OrderDeposit, type OutputStatus, type OrderStatus } from '../../contexts/orderTrackingTypes.js';
|
|
7
|
+
export { OutputStage, getStatusTextFromStage, getProgressFromStage, getOrderTrackingCacheKey, } from '../../contexts/orderTrackingTypes.js';
|
|
8
|
+
export type { OrderDeposit, OutputStatus, OrderTransactions, OrderStatus, StatusUpdate, OrderTrackingState, OrderTrackingOptions, } from '../../contexts/orderTrackingTypes.js';
|
|
134
9
|
export type JsonRpcError = {
|
|
135
10
|
code: number;
|
|
136
11
|
message: string;
|
|
@@ -143,7 +18,7 @@ export interface UseOrderTrackingOptions {
|
|
|
143
18
|
onStatusUpdate?: (status: OrderStatus) => void;
|
|
144
19
|
onError?: (error: Error) => void;
|
|
145
20
|
onComplete?: () => void;
|
|
146
|
-
/** Fetch USD price for an asset when priceUsd is missing from WS response
|
|
21
|
+
/** Fetch USD price for an asset when priceUsd is missing from WS response */
|
|
147
22
|
fetchAssetPrice?: (caip19: string) => Promise<number>;
|
|
148
23
|
}
|
|
149
24
|
export interface UseOrderTrackingReturn {
|
|
@@ -162,20 +37,4 @@ export interface UseOrderTrackingReturn {
|
|
|
162
37
|
getStatusText: (stage: OutputStage) => string;
|
|
163
38
|
getProgress: (stage: OutputStage) => number;
|
|
164
39
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Get human-readable status text from output stage
|
|
167
|
-
*/
|
|
168
|
-
export declare function getStatusTextFromStage(stage: OutputStage): string;
|
|
169
|
-
/**
|
|
170
|
-
* Get progress value (0-1) from output stage
|
|
171
|
-
*/
|
|
172
|
-
export declare function getProgressFromStage(stage: OutputStage): number;
|
|
173
|
-
/**
|
|
174
|
-
* React hook for tracking SilentSwap orders via WebSocket
|
|
175
|
-
*
|
|
176
|
-
* Uses a module-level singleton: one WebSocket per order, reused across
|
|
177
|
-
* React lifecycle events (Strict Mode, re-renders, effect re-runs).
|
|
178
|
-
* Reconnection matches Svelte ws_order_subscribe: immediate reconnect,
|
|
179
|
-
* 5s delay if idle >90s, no exponential backoff.
|
|
180
|
-
*/
|
|
181
40
|
export declare function useOrderTracking({ client, orderId: initialOrderId, viewingAuth: initialAuth, onStatusUpdate, onError, onComplete, fetchAssetPrice, }?: UseOrderTrackingOptions): UseOrderTrackingReturn;
|