@rozoai/intent-pay 0.0.29-beta.2 → 0.0.29-beta.3
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/package.json.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { base, polygon, baseUSDC, polygonUSDC, bsc, bscUSDT } from '@rozoai/intent-common';
|
|
2
|
-
import { useState, useMemo, useEffect } from 'react';
|
|
2
|
+
import { useState, useRef, useMemo, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Wallet payment options. User picks one.
|
|
@@ -21,6 +21,8 @@ import { useState, useMemo, useEffect } from 'react';
|
|
|
21
21
|
function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, preferredChains, preferredTokens, evmChains, isDepositFlow, payParams, log, }) {
|
|
22
22
|
const [options, setOptions] = useState(null);
|
|
23
23
|
const [isLoading, setIsLoading] = useState(false);
|
|
24
|
+
const requestIdRef = useRef(0);
|
|
25
|
+
const abortControllerRef = useRef(null);
|
|
24
26
|
// Create stable array dependencies that only change when content actually changes
|
|
25
27
|
const stablePreferredChains = useMemo(() => {
|
|
26
28
|
if (!preferredChains || preferredChains.length === 0)
|
|
@@ -48,6 +50,15 @@ function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, pref
|
|
|
48
50
|
const refreshWalletPaymentOptions = async () => {
|
|
49
51
|
if (address == null || usdRequired == null || destChainId == null)
|
|
50
52
|
return;
|
|
53
|
+
// Cancel any in-flight requests
|
|
54
|
+
if (abortControllerRef.current) {
|
|
55
|
+
abortControllerRef.current.abort();
|
|
56
|
+
}
|
|
57
|
+
// Create new abort controller for this request
|
|
58
|
+
const abortController = new AbortController();
|
|
59
|
+
abortControllerRef.current = abortController;
|
|
60
|
+
// Increment request ID
|
|
61
|
+
const currentRequestId = ++requestIdRef.current;
|
|
51
62
|
setOptions(null);
|
|
52
63
|
setIsLoading(true);
|
|
53
64
|
try {
|
|
@@ -68,40 +79,54 @@ function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, pref
|
|
|
68
79
|
queryParams.evmChains = stableEvmChains;
|
|
69
80
|
}
|
|
70
81
|
const newOptions = await trpc.getWalletPaymentOptions.query(queryParams);
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
// Only update state if this is still the latest request
|
|
83
|
+
if (currentRequestId === requestIdRef.current &&
|
|
84
|
+
!abortController.signal.aborted) {
|
|
85
|
+
// SUPPORTED CHAINS: Only these chains are currently active in wallet payment options
|
|
86
|
+
// To add more chains, add them to both arrays below and ensure they're defined in pay-common
|
|
87
|
+
const supportedChains = [base, polygon];
|
|
88
|
+
// SUPPORTED TOKENS: Only these specific tokens are currently active
|
|
89
|
+
// Each token corresponds to its respective chain above
|
|
90
|
+
const supportedTokens = [baseUSDC.token, polygonUSDC.token];
|
|
91
|
+
// Show BSC USDT for MugglePay apps or when BSC is preferred
|
|
92
|
+
const showBSCUSDT = payParams?.appId?.includes("MP") ||
|
|
93
|
+
stablePreferredChains?.includes(bsc.chainId) ||
|
|
94
|
+
stableEvmChains?.includes(bsc.chainId);
|
|
95
|
+
if (showBSCUSDT) {
|
|
96
|
+
supportedChains.push(bsc);
|
|
97
|
+
supportedTokens.push(bscUSDT.token);
|
|
98
|
+
}
|
|
99
|
+
// Filter out chains/tokens we don't support yet in wallet payment options
|
|
100
|
+
// API may return more options, but we only show these filtered ones to users
|
|
101
|
+
const isSupported = (o) => supportedChains.some((c) => c.chainId === o.balance.token.chainId &&
|
|
102
|
+
supportedTokens.includes(o.balance.token.token));
|
|
103
|
+
const filteredOptions = newOptions.filter(isSupported);
|
|
104
|
+
if (filteredOptions.length < newOptions.length) {
|
|
105
|
+
log(`[WALLET]: skipping ${newOptions.length - filteredOptions.length} unsupported-chain balances on ${address}`);
|
|
106
|
+
}
|
|
107
|
+
setOptions(filteredOptions);
|
|
92
108
|
}
|
|
93
|
-
setOptions(filteredOptions);
|
|
94
109
|
}
|
|
95
110
|
catch (error) {
|
|
96
111
|
console.error(error);
|
|
97
112
|
}
|
|
98
113
|
finally {
|
|
99
|
-
|
|
114
|
+
// Only update loading state if this is still the latest request
|
|
115
|
+
if (currentRequestId === requestIdRef.current &&
|
|
116
|
+
!abortController.signal.aborted) {
|
|
117
|
+
setIsLoading(false);
|
|
118
|
+
}
|
|
100
119
|
}
|
|
101
120
|
};
|
|
102
121
|
if (address != null && usdRequired != null && destChainId != null) {
|
|
103
122
|
refreshWalletPaymentOptions();
|
|
104
123
|
}
|
|
124
|
+
// Cleanup function to abort requests on unmount
|
|
125
|
+
return () => {
|
|
126
|
+
if (abortControllerRef.current) {
|
|
127
|
+
abortControllerRef.current.abort();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
105
130
|
}, [
|
|
106
131
|
address,
|
|
107
132
|
usdRequired,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWalletPaymentOptions.js","sources":["../../../src/hooks/useWalletPaymentOptions.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAaA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,uBAAuB,CAAC,EACtC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,WAAW,EACX,eAAe,EACf,eAAe,EACf,SAAS,EACT,aAAa,EACb,SAAS,EACT,GAAG,GAYJ,EAAA;IACC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAA+B,IAAI,CAAC,CAAC;IAC3E,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;;
|
|
1
|
+
{"version":3,"file":"useWalletPa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