@spicenet-io/spiceflow-ui 1.8.2 → 1.8.4
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/hooks/index.d.ts +2 -0
- package/dist/hooks/useSpiceAssets/index.d.ts +27 -0
- package/dist/index.cjs.js +164 -27
- package/dist/index.js +164 -27
- package/dist/utils/relayer/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -13,3 +13,5 @@ export type { UseWalletReturn, WalletState, WalletActions } from "./useWallet";
|
|
|
13
13
|
export { useEmbeddedWalletAddress } from "./useEmbeddedWalletAddress";
|
|
14
14
|
export { useSpiceBalance } from "./useSpiceBalance";
|
|
15
15
|
export type { UseSpiceBalanceConfig, UseSpiceBalanceReturn, SpiceBalanceApiResponse, } from "./useSpiceBalance";
|
|
16
|
+
export { useSpiceAssets } from "./useSpiceAssets";
|
|
17
|
+
export type { UseSpiceAssetsConfig, UseSpiceAssetsReturn, } from "./useSpiceAssets";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
2
|
+
import { Asset } from "../../types/assets";
|
|
3
|
+
export interface SpiceBalanceApiResponse {
|
|
4
|
+
success: boolean;
|
|
5
|
+
data?: {
|
|
6
|
+
tokens: {
|
|
7
|
+
[chainId: string]: {
|
|
8
|
+
[tokenAddress: string]: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface UseSpiceAssetsConfig {
|
|
14
|
+
address?: Address | string;
|
|
15
|
+
supportedChains?: number[];
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
refetchInterval?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface UseSpiceAssetsReturn {
|
|
20
|
+
assets: Asset[];
|
|
21
|
+
loading: boolean;
|
|
22
|
+
error: string | null;
|
|
23
|
+
hasBalance: boolean;
|
|
24
|
+
refetch: () => Promise<void>;
|
|
25
|
+
getAssetsByChain: (chainId: number) => Asset[];
|
|
26
|
+
}
|
|
27
|
+
export declare const useSpiceAssets: ({ address, supportedChains, enabled, refetchInterval, }: UseSpiceAssetsConfig) => UseSpiceAssetsReturn;
|
package/dist/index.cjs.js
CHANGED
|
@@ -51,6 +51,12 @@ const CHAIN_CONFIGS = {
|
|
|
51
51
|
symbol: "USDC",
|
|
52
52
|
decimals: 6
|
|
53
53
|
},
|
|
54
|
+
{
|
|
55
|
+
address: "0x76f983E0F5a4B72C4bac99Fc9399845a58078787",
|
|
56
|
+
name: "Mock Tether USD",
|
|
57
|
+
symbol: "USDT",
|
|
58
|
+
decimals: 6
|
|
59
|
+
},
|
|
54
60
|
{
|
|
55
61
|
address: "0x4Fc381B6CC6Df8cF1c1bD46D184475bE5b7A3c62",
|
|
56
62
|
name: "Mock Wrapped BTC",
|
|
@@ -3074,6 +3080,7 @@ class RelayerService {
|
|
|
3074
3080
|
}
|
|
3075
3081
|
}
|
|
3076
3082
|
async submitSpiceDeposit(request) {
|
|
3083
|
+
const depositType = request.isDeposit ? "deposit" : "withdrawal";
|
|
3077
3084
|
try {
|
|
3078
3085
|
const response = await fetch(`${this.baseUrl}/spicedeposit`, {
|
|
3079
3086
|
method: "POST",
|
|
@@ -3084,13 +3091,16 @@ class RelayerService {
|
|
|
3084
3091
|
});
|
|
3085
3092
|
const data = await response.json();
|
|
3086
3093
|
if (!response.ok || !data.success) {
|
|
3087
|
-
console.error(
|
|
3094
|
+
console.error(
|
|
3095
|
+
`Failed to submit ${depositType} request to API:`,
|
|
3096
|
+
data.error?.message
|
|
3097
|
+
);
|
|
3088
3098
|
return { success: false, error: data.error };
|
|
3089
3099
|
}
|
|
3090
|
-
console.log(
|
|
3100
|
+
console.log(`${depositType} request successfully submitted to API`);
|
|
3091
3101
|
return data;
|
|
3092
3102
|
} catch (error) {
|
|
3093
|
-
console.error(
|
|
3103
|
+
console.error(`Error submitting ${depositType} request to API:`, error);
|
|
3094
3104
|
return {
|
|
3095
3105
|
success: false,
|
|
3096
3106
|
error: {
|
|
@@ -3952,6 +3962,133 @@ const SwapWidget = ({
|
|
|
3952
3962
|
] });
|
|
3953
3963
|
};
|
|
3954
3964
|
|
|
3965
|
+
const useSpiceAssets = ({
|
|
3966
|
+
address,
|
|
3967
|
+
supportedChains,
|
|
3968
|
+
enabled = true,
|
|
3969
|
+
refetchInterval
|
|
3970
|
+
}) => {
|
|
3971
|
+
const [assets, setAssets] = React.useState([]);
|
|
3972
|
+
const [loading, setLoading] = React.useState(false);
|
|
3973
|
+
const [error, setError] = React.useState(null);
|
|
3974
|
+
const [hasBalance, setHasBalance] = React.useState(false);
|
|
3975
|
+
const fetchAssets = React.useCallback(async () => {
|
|
3976
|
+
if (!address || !enabled) {
|
|
3977
|
+
setAssets([]);
|
|
3978
|
+
setHasBalance(false);
|
|
3979
|
+
return;
|
|
3980
|
+
}
|
|
3981
|
+
setLoading(true);
|
|
3982
|
+
setError(null);
|
|
3983
|
+
try {
|
|
3984
|
+
const response = await fetch(
|
|
3985
|
+
`${RELAYER_API_URL}/spicedeposit/${address}`
|
|
3986
|
+
);
|
|
3987
|
+
if (!response.ok) {
|
|
3988
|
+
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
3989
|
+
}
|
|
3990
|
+
const result = await response.json();
|
|
3991
|
+
if (result.success && result.data?.tokens) {
|
|
3992
|
+
const tokens = result.data.tokens;
|
|
3993
|
+
const parsedAssets = [];
|
|
3994
|
+
Object.keys(tokens).forEach((chainIdStr) => {
|
|
3995
|
+
const chainId = parseInt(chainIdStr);
|
|
3996
|
+
if (supportedChains && !supportedChains.includes(chainId)) {
|
|
3997
|
+
return;
|
|
3998
|
+
}
|
|
3999
|
+
const chainTokens = tokens[chainIdStr];
|
|
4000
|
+
const chainConfig = getChainConfig(chainId);
|
|
4001
|
+
if (chainTokens && typeof chainTokens === "object") {
|
|
4002
|
+
Object.keys(chainTokens).forEach((tokenAddress) => {
|
|
4003
|
+
const rawBalanceStr = chainTokens[tokenAddress];
|
|
4004
|
+
const rawBalance = BigInt(rawBalanceStr || "0");
|
|
4005
|
+
if (rawBalance > BigInt(0)) {
|
|
4006
|
+
const isNative = tokenAddress.toLowerCase() === "0x0" || tokenAddress.toLowerCase() === "0x0000000000000000000000000000000000000000" || tokenAddress.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
4007
|
+
let decimals = 18;
|
|
4008
|
+
let symbol = "TOKEN";
|
|
4009
|
+
let name = tokenAddress.slice(0, 6) + "..." + tokenAddress.slice(-4);
|
|
4010
|
+
let logoURI;
|
|
4011
|
+
if (isNative) {
|
|
4012
|
+
decimals = chainConfig?.nativeCurrency?.decimals || 18;
|
|
4013
|
+
symbol = chainConfig?.nativeCurrency?.symbol || "ETH";
|
|
4014
|
+
name = chainConfig?.nativeCurrency?.name || "Native Token";
|
|
4015
|
+
} else {
|
|
4016
|
+
const tokenConfig = chainConfig?.supportedTokens?.find(
|
|
4017
|
+
(t) => t.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
4018
|
+
);
|
|
4019
|
+
if (tokenConfig) {
|
|
4020
|
+
decimals = tokenConfig.decimals;
|
|
4021
|
+
symbol = tokenConfig.symbol;
|
|
4022
|
+
name = tokenConfig.name;
|
|
4023
|
+
logoURI = tokenConfig.logoURI;
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
const balanceFormatted = parseFloat(
|
|
4027
|
+
(Number(rawBalance) / Math.pow(10, decimals)).toFixed(6)
|
|
4028
|
+
);
|
|
4029
|
+
if (balanceFormatted > 0) {
|
|
4030
|
+
parsedAssets.push({
|
|
4031
|
+
address: isNative ? "0x0000000000000000000000000000000000000000" : tokenAddress,
|
|
4032
|
+
symbol,
|
|
4033
|
+
name,
|
|
4034
|
+
decimals,
|
|
4035
|
+
chainId,
|
|
4036
|
+
balance: rawBalance,
|
|
4037
|
+
balanceFormatted,
|
|
4038
|
+
balanceUsd: 0,
|
|
4039
|
+
// API doesn't provide USD value
|
|
4040
|
+
isNative,
|
|
4041
|
+
logoURI
|
|
4042
|
+
});
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
4045
|
+
});
|
|
4046
|
+
}
|
|
4047
|
+
});
|
|
4048
|
+
setAssets(parsedAssets);
|
|
4049
|
+
setHasBalance(parsedAssets.length > 0);
|
|
4050
|
+
} else {
|
|
4051
|
+
setAssets([]);
|
|
4052
|
+
setHasBalance(false);
|
|
4053
|
+
}
|
|
4054
|
+
} catch (err) {
|
|
4055
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch balance";
|
|
4056
|
+
setError(errorMessage);
|
|
4057
|
+
console.error("Error fetching Spice assets:", err);
|
|
4058
|
+
setAssets([]);
|
|
4059
|
+
setHasBalance(false);
|
|
4060
|
+
} finally {
|
|
4061
|
+
setLoading(false);
|
|
4062
|
+
}
|
|
4063
|
+
}, [address, enabled, supportedChains]);
|
|
4064
|
+
React.useEffect(() => {
|
|
4065
|
+
if (enabled && address) {
|
|
4066
|
+
fetchAssets();
|
|
4067
|
+
}
|
|
4068
|
+
}, [address, enabled, fetchAssets]);
|
|
4069
|
+
React.useEffect(() => {
|
|
4070
|
+
if (!enabled || !address || !refetchInterval) return;
|
|
4071
|
+
const interval = setInterval(() => {
|
|
4072
|
+
fetchAssets();
|
|
4073
|
+
}, refetchInterval);
|
|
4074
|
+
return () => clearInterval(interval);
|
|
4075
|
+
}, [address, enabled, refetchInterval, fetchAssets]);
|
|
4076
|
+
const getAssetsByChain = React.useCallback(
|
|
4077
|
+
(chainId) => {
|
|
4078
|
+
return assets.filter((asset) => asset.chainId === chainId);
|
|
4079
|
+
},
|
|
4080
|
+
[assets]
|
|
4081
|
+
);
|
|
4082
|
+
return {
|
|
4083
|
+
assets,
|
|
4084
|
+
loading,
|
|
4085
|
+
error,
|
|
4086
|
+
hasBalance,
|
|
4087
|
+
refetch: fetchAssets,
|
|
4088
|
+
getAssetsByChain
|
|
4089
|
+
};
|
|
4090
|
+
};
|
|
4091
|
+
|
|
3955
4092
|
const DepositWidget = ({
|
|
3956
4093
|
depositBatches,
|
|
3957
4094
|
tokenAddress,
|
|
@@ -3991,14 +4128,15 @@ const DepositWidget = ({
|
|
|
3991
4128
|
const [selectedDepositAsset, setSelectedDepositAsset] = React.useState(null);
|
|
3992
4129
|
const [isPending, startTransition] = React.useTransition();
|
|
3993
4130
|
const {
|
|
3994
|
-
assets,
|
|
3995
|
-
loading:
|
|
3996
|
-
error:
|
|
3997
|
-
|
|
3998
|
-
} =
|
|
4131
|
+
assets: spiceAssets,
|
|
4132
|
+
loading: loadingSpiceAssets,
|
|
4133
|
+
error: spiceAssetsError,
|
|
4134
|
+
refetch: refreshSpiceAssets
|
|
4135
|
+
} = useSpiceAssets({
|
|
3999
4136
|
address,
|
|
4000
4137
|
supportedChains,
|
|
4001
|
-
|
|
4138
|
+
enabled: isConnected,
|
|
4139
|
+
refetchInterval: 3e4
|
|
4002
4140
|
});
|
|
4003
4141
|
const [isExecuting, setIsExecuting] = React.useState(false);
|
|
4004
4142
|
const [error, setError] = React.useState(null);
|
|
@@ -4162,7 +4300,7 @@ const DepositWidget = ({
|
|
|
4162
4300
|
const initialSteps = createInitialSteps(allChainBatches, getChainName);
|
|
4163
4301
|
startStatusPolling(result.intentId, initialSteps);
|
|
4164
4302
|
onDepositSuccess?.(result.intentId);
|
|
4165
|
-
|
|
4303
|
+
refreshSpiceAssets();
|
|
4166
4304
|
}
|
|
4167
4305
|
} catch (error2) {
|
|
4168
4306
|
const errorMessage = error2 instanceof Error ? error2.message : "Deposit failed";
|
|
@@ -4172,23 +4310,18 @@ const DepositWidget = ({
|
|
|
4172
4310
|
setIsExecuting(false);
|
|
4173
4311
|
}
|
|
4174
4312
|
};
|
|
4175
|
-
const
|
|
4176
|
-
const allAssets = supportedChains.flatMap(
|
|
4177
|
-
(chainId) => getAllAssetsForChain(chainId, assets)
|
|
4178
|
-
);
|
|
4179
|
-
console.log("allAssets", allAssets);
|
|
4180
|
-
console.log("supportedTokens", supportedTokens);
|
|
4313
|
+
const spiceDepositAssets = React.useMemo(() => {
|
|
4181
4314
|
if (supportedTokens && supportedTokens.length > 0) {
|
|
4182
|
-
return
|
|
4315
|
+
return spiceAssets.filter(
|
|
4183
4316
|
(asset) => supportedTokens.some(
|
|
4184
4317
|
(symbol) => symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
4185
4318
|
)
|
|
4186
4319
|
);
|
|
4187
4320
|
}
|
|
4188
|
-
return
|
|
4189
|
-
}, [
|
|
4321
|
+
return spiceAssets;
|
|
4322
|
+
}, [spiceAssets, supportedTokens]);
|
|
4190
4323
|
const canDeposit = selectedDepositAsset && selectedDepositAsset.amount && parseFloat(selectedDepositAsset.amount) > 0 && parseFloat(selectedDepositAsset.amount) <= selectedDepositAsset.asset.balanceFormatted && isConnected && !isExecuting && depositBatches.length > 0;
|
|
4191
|
-
const displayError =
|
|
4324
|
+
const displayError = spiceAssetsError || error;
|
|
4192
4325
|
const containerStyles = {
|
|
4193
4326
|
backgroundColor: styles?.container?.backgroundColor || styles?.primaryBackground || theme.colors.background,
|
|
4194
4327
|
border: `1px solid ${styles?.container?.borderColor || theme.colors.border}`,
|
|
@@ -4215,7 +4348,7 @@ const DepositWidget = ({
|
|
|
4215
4348
|
onNewTx: () => {
|
|
4216
4349
|
clearStatus();
|
|
4217
4350
|
setSelectedDepositAsset(null);
|
|
4218
|
-
|
|
4351
|
+
refreshSpiceAssets();
|
|
4219
4352
|
},
|
|
4220
4353
|
explorerUrlBuilder: (chainId, txHash) => getExplorerUrl(chainId, txHash),
|
|
4221
4354
|
theme
|
|
@@ -4344,11 +4477,11 @@ const DepositWidget = ({
|
|
|
4344
4477
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: theme.spacing.sm }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4345
4478
|
AssetSelector,
|
|
4346
4479
|
{
|
|
4347
|
-
assets:
|
|
4480
|
+
assets: spiceDepositAssets,
|
|
4348
4481
|
selectedAsset: selectedDepositAsset || void 0,
|
|
4349
4482
|
onAssetSelect: handleDepositAssetSelect,
|
|
4350
4483
|
onAmountChange: handleDepositAmountChange,
|
|
4351
|
-
loading:
|
|
4484
|
+
loading: loadingSpiceAssets,
|
|
4352
4485
|
label: "Deposit",
|
|
4353
4486
|
showBalance: true,
|
|
4354
4487
|
showMaxButton: true,
|
|
@@ -7643,7 +7776,8 @@ const DepositModal = React.memo(
|
|
|
7643
7776
|
tokenAddress,
|
|
7644
7777
|
chainId,
|
|
7645
7778
|
amount: amount.toString(),
|
|
7646
|
-
user: address
|
|
7779
|
+
user: address,
|
|
7780
|
+
isDeposit: true
|
|
7647
7781
|
});
|
|
7648
7782
|
await relayerService.submitSpiceDeposit({
|
|
7649
7783
|
txHash: transferToEmbeddedTx,
|
|
@@ -7651,7 +7785,8 @@ const DepositModal = React.memo(
|
|
|
7651
7785
|
tokenAddress,
|
|
7652
7786
|
chainId,
|
|
7653
7787
|
amount: amount.toString(),
|
|
7654
|
-
user: address
|
|
7788
|
+
user: address,
|
|
7789
|
+
isDeposit: true
|
|
7655
7790
|
});
|
|
7656
7791
|
console.log(
|
|
7657
7792
|
`Successfully submitted deposit for txHash: ${transferToEmbeddedTx}`
|
|
@@ -9253,7 +9388,8 @@ const WithdrawModal = React.memo(
|
|
|
9253
9388
|
sender: externalWalletAddress,
|
|
9254
9389
|
tokenAddress: apiTokenAddress,
|
|
9255
9390
|
chainId: destinationChainId,
|
|
9256
|
-
amount: amount2.toString()
|
|
9391
|
+
amount: amount2.toString(),
|
|
9392
|
+
isDeposit: false
|
|
9257
9393
|
});
|
|
9258
9394
|
const depositResult = await relayerService.submitSpiceDeposit({
|
|
9259
9395
|
user: externalWalletAddress,
|
|
@@ -9261,7 +9397,8 @@ const WithdrawModal = React.memo(
|
|
|
9261
9397
|
sender: externalWalletAddress,
|
|
9262
9398
|
tokenAddress: apiTokenAddress,
|
|
9263
9399
|
chainId: destinationChainId,
|
|
9264
|
-
amount: amount2.toString()
|
|
9400
|
+
amount: amount2.toString(),
|
|
9401
|
+
isDeposit: false
|
|
9265
9402
|
});
|
|
9266
9403
|
if (!depositResult.success) {
|
|
9267
9404
|
console.error(
|
package/dist/index.js
CHANGED
|
@@ -49,6 +49,12 @@ const CHAIN_CONFIGS = {
|
|
|
49
49
|
symbol: "USDC",
|
|
50
50
|
decimals: 6
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
address: "0x76f983E0F5a4B72C4bac99Fc9399845a58078787",
|
|
54
|
+
name: "Mock Tether USD",
|
|
55
|
+
symbol: "USDT",
|
|
56
|
+
decimals: 6
|
|
57
|
+
},
|
|
52
58
|
{
|
|
53
59
|
address: "0x4Fc381B6CC6Df8cF1c1bD46D184475bE5b7A3c62",
|
|
54
60
|
name: "Mock Wrapped BTC",
|
|
@@ -3072,6 +3078,7 @@ class RelayerService {
|
|
|
3072
3078
|
}
|
|
3073
3079
|
}
|
|
3074
3080
|
async submitSpiceDeposit(request) {
|
|
3081
|
+
const depositType = request.isDeposit ? "deposit" : "withdrawal";
|
|
3075
3082
|
try {
|
|
3076
3083
|
const response = await fetch(`${this.baseUrl}/spicedeposit`, {
|
|
3077
3084
|
method: "POST",
|
|
@@ -3082,13 +3089,16 @@ class RelayerService {
|
|
|
3082
3089
|
});
|
|
3083
3090
|
const data = await response.json();
|
|
3084
3091
|
if (!response.ok || !data.success) {
|
|
3085
|
-
console.error(
|
|
3092
|
+
console.error(
|
|
3093
|
+
`Failed to submit ${depositType} request to API:`,
|
|
3094
|
+
data.error?.message
|
|
3095
|
+
);
|
|
3086
3096
|
return { success: false, error: data.error };
|
|
3087
3097
|
}
|
|
3088
|
-
console.log(
|
|
3098
|
+
console.log(`${depositType} request successfully submitted to API`);
|
|
3089
3099
|
return data;
|
|
3090
3100
|
} catch (error) {
|
|
3091
|
-
console.error(
|
|
3101
|
+
console.error(`Error submitting ${depositType} request to API:`, error);
|
|
3092
3102
|
return {
|
|
3093
3103
|
success: false,
|
|
3094
3104
|
error: {
|
|
@@ -3950,6 +3960,133 @@ const SwapWidget = ({
|
|
|
3950
3960
|
] });
|
|
3951
3961
|
};
|
|
3952
3962
|
|
|
3963
|
+
const useSpiceAssets = ({
|
|
3964
|
+
address,
|
|
3965
|
+
supportedChains,
|
|
3966
|
+
enabled = true,
|
|
3967
|
+
refetchInterval
|
|
3968
|
+
}) => {
|
|
3969
|
+
const [assets, setAssets] = useState([]);
|
|
3970
|
+
const [loading, setLoading] = useState(false);
|
|
3971
|
+
const [error, setError] = useState(null);
|
|
3972
|
+
const [hasBalance, setHasBalance] = useState(false);
|
|
3973
|
+
const fetchAssets = useCallback(async () => {
|
|
3974
|
+
if (!address || !enabled) {
|
|
3975
|
+
setAssets([]);
|
|
3976
|
+
setHasBalance(false);
|
|
3977
|
+
return;
|
|
3978
|
+
}
|
|
3979
|
+
setLoading(true);
|
|
3980
|
+
setError(null);
|
|
3981
|
+
try {
|
|
3982
|
+
const response = await fetch(
|
|
3983
|
+
`${RELAYER_API_URL}/spicedeposit/${address}`
|
|
3984
|
+
);
|
|
3985
|
+
if (!response.ok) {
|
|
3986
|
+
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
3987
|
+
}
|
|
3988
|
+
const result = await response.json();
|
|
3989
|
+
if (result.success && result.data?.tokens) {
|
|
3990
|
+
const tokens = result.data.tokens;
|
|
3991
|
+
const parsedAssets = [];
|
|
3992
|
+
Object.keys(tokens).forEach((chainIdStr) => {
|
|
3993
|
+
const chainId = parseInt(chainIdStr);
|
|
3994
|
+
if (supportedChains && !supportedChains.includes(chainId)) {
|
|
3995
|
+
return;
|
|
3996
|
+
}
|
|
3997
|
+
const chainTokens = tokens[chainIdStr];
|
|
3998
|
+
const chainConfig = getChainConfig(chainId);
|
|
3999
|
+
if (chainTokens && typeof chainTokens === "object") {
|
|
4000
|
+
Object.keys(chainTokens).forEach((tokenAddress) => {
|
|
4001
|
+
const rawBalanceStr = chainTokens[tokenAddress];
|
|
4002
|
+
const rawBalance = BigInt(rawBalanceStr || "0");
|
|
4003
|
+
if (rawBalance > BigInt(0)) {
|
|
4004
|
+
const isNative = tokenAddress.toLowerCase() === "0x0" || tokenAddress.toLowerCase() === "0x0000000000000000000000000000000000000000" || tokenAddress.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
4005
|
+
let decimals = 18;
|
|
4006
|
+
let symbol = "TOKEN";
|
|
4007
|
+
let name = tokenAddress.slice(0, 6) + "..." + tokenAddress.slice(-4);
|
|
4008
|
+
let logoURI;
|
|
4009
|
+
if (isNative) {
|
|
4010
|
+
decimals = chainConfig?.nativeCurrency?.decimals || 18;
|
|
4011
|
+
symbol = chainConfig?.nativeCurrency?.symbol || "ETH";
|
|
4012
|
+
name = chainConfig?.nativeCurrency?.name || "Native Token";
|
|
4013
|
+
} else {
|
|
4014
|
+
const tokenConfig = chainConfig?.supportedTokens?.find(
|
|
4015
|
+
(t) => t.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
4016
|
+
);
|
|
4017
|
+
if (tokenConfig) {
|
|
4018
|
+
decimals = tokenConfig.decimals;
|
|
4019
|
+
symbol = tokenConfig.symbol;
|
|
4020
|
+
name = tokenConfig.name;
|
|
4021
|
+
logoURI = tokenConfig.logoURI;
|
|
4022
|
+
}
|
|
4023
|
+
}
|
|
4024
|
+
const balanceFormatted = parseFloat(
|
|
4025
|
+
(Number(rawBalance) / Math.pow(10, decimals)).toFixed(6)
|
|
4026
|
+
);
|
|
4027
|
+
if (balanceFormatted > 0) {
|
|
4028
|
+
parsedAssets.push({
|
|
4029
|
+
address: isNative ? "0x0000000000000000000000000000000000000000" : tokenAddress,
|
|
4030
|
+
symbol,
|
|
4031
|
+
name,
|
|
4032
|
+
decimals,
|
|
4033
|
+
chainId,
|
|
4034
|
+
balance: rawBalance,
|
|
4035
|
+
balanceFormatted,
|
|
4036
|
+
balanceUsd: 0,
|
|
4037
|
+
// API doesn't provide USD value
|
|
4038
|
+
isNative,
|
|
4039
|
+
logoURI
|
|
4040
|
+
});
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
});
|
|
4044
|
+
}
|
|
4045
|
+
});
|
|
4046
|
+
setAssets(parsedAssets);
|
|
4047
|
+
setHasBalance(parsedAssets.length > 0);
|
|
4048
|
+
} else {
|
|
4049
|
+
setAssets([]);
|
|
4050
|
+
setHasBalance(false);
|
|
4051
|
+
}
|
|
4052
|
+
} catch (err) {
|
|
4053
|
+
const errorMessage = err instanceof Error ? err.message : "Failed to fetch balance";
|
|
4054
|
+
setError(errorMessage);
|
|
4055
|
+
console.error("Error fetching Spice assets:", err);
|
|
4056
|
+
setAssets([]);
|
|
4057
|
+
setHasBalance(false);
|
|
4058
|
+
} finally {
|
|
4059
|
+
setLoading(false);
|
|
4060
|
+
}
|
|
4061
|
+
}, [address, enabled, supportedChains]);
|
|
4062
|
+
useEffect(() => {
|
|
4063
|
+
if (enabled && address) {
|
|
4064
|
+
fetchAssets();
|
|
4065
|
+
}
|
|
4066
|
+
}, [address, enabled, fetchAssets]);
|
|
4067
|
+
useEffect(() => {
|
|
4068
|
+
if (!enabled || !address || !refetchInterval) return;
|
|
4069
|
+
const interval = setInterval(() => {
|
|
4070
|
+
fetchAssets();
|
|
4071
|
+
}, refetchInterval);
|
|
4072
|
+
return () => clearInterval(interval);
|
|
4073
|
+
}, [address, enabled, refetchInterval, fetchAssets]);
|
|
4074
|
+
const getAssetsByChain = useCallback(
|
|
4075
|
+
(chainId) => {
|
|
4076
|
+
return assets.filter((asset) => asset.chainId === chainId);
|
|
4077
|
+
},
|
|
4078
|
+
[assets]
|
|
4079
|
+
);
|
|
4080
|
+
return {
|
|
4081
|
+
assets,
|
|
4082
|
+
loading,
|
|
4083
|
+
error,
|
|
4084
|
+
hasBalance,
|
|
4085
|
+
refetch: fetchAssets,
|
|
4086
|
+
getAssetsByChain
|
|
4087
|
+
};
|
|
4088
|
+
};
|
|
4089
|
+
|
|
3953
4090
|
const DepositWidget = ({
|
|
3954
4091
|
depositBatches,
|
|
3955
4092
|
tokenAddress,
|
|
@@ -3989,14 +4126,15 @@ const DepositWidget = ({
|
|
|
3989
4126
|
const [selectedDepositAsset, setSelectedDepositAsset] = useState(null);
|
|
3990
4127
|
const [isPending, startTransition] = useTransition();
|
|
3991
4128
|
const {
|
|
3992
|
-
assets,
|
|
3993
|
-
loading:
|
|
3994
|
-
error:
|
|
3995
|
-
|
|
3996
|
-
} =
|
|
4129
|
+
assets: spiceAssets,
|
|
4130
|
+
loading: loadingSpiceAssets,
|
|
4131
|
+
error: spiceAssetsError,
|
|
4132
|
+
refetch: refreshSpiceAssets
|
|
4133
|
+
} = useSpiceAssets({
|
|
3997
4134
|
address,
|
|
3998
4135
|
supportedChains,
|
|
3999
|
-
|
|
4136
|
+
enabled: isConnected,
|
|
4137
|
+
refetchInterval: 3e4
|
|
4000
4138
|
});
|
|
4001
4139
|
const [isExecuting, setIsExecuting] = useState(false);
|
|
4002
4140
|
const [error, setError] = useState(null);
|
|
@@ -4160,7 +4298,7 @@ const DepositWidget = ({
|
|
|
4160
4298
|
const initialSteps = createInitialSteps(allChainBatches, getChainName);
|
|
4161
4299
|
startStatusPolling(result.intentId, initialSteps);
|
|
4162
4300
|
onDepositSuccess?.(result.intentId);
|
|
4163
|
-
|
|
4301
|
+
refreshSpiceAssets();
|
|
4164
4302
|
}
|
|
4165
4303
|
} catch (error2) {
|
|
4166
4304
|
const errorMessage = error2 instanceof Error ? error2.message : "Deposit failed";
|
|
@@ -4170,23 +4308,18 @@ const DepositWidget = ({
|
|
|
4170
4308
|
setIsExecuting(false);
|
|
4171
4309
|
}
|
|
4172
4310
|
};
|
|
4173
|
-
const
|
|
4174
|
-
const allAssets = supportedChains.flatMap(
|
|
4175
|
-
(chainId) => getAllAssetsForChain(chainId, assets)
|
|
4176
|
-
);
|
|
4177
|
-
console.log("allAssets", allAssets);
|
|
4178
|
-
console.log("supportedTokens", supportedTokens);
|
|
4311
|
+
const spiceDepositAssets = useMemo(() => {
|
|
4179
4312
|
if (supportedTokens && supportedTokens.length > 0) {
|
|
4180
|
-
return
|
|
4313
|
+
return spiceAssets.filter(
|
|
4181
4314
|
(asset) => supportedTokens.some(
|
|
4182
4315
|
(symbol) => symbol.toLowerCase() === asset.symbol.toLowerCase()
|
|
4183
4316
|
)
|
|
4184
4317
|
);
|
|
4185
4318
|
}
|
|
4186
|
-
return
|
|
4187
|
-
}, [
|
|
4319
|
+
return spiceAssets;
|
|
4320
|
+
}, [spiceAssets, supportedTokens]);
|
|
4188
4321
|
const canDeposit = selectedDepositAsset && selectedDepositAsset.amount && parseFloat(selectedDepositAsset.amount) > 0 && parseFloat(selectedDepositAsset.amount) <= selectedDepositAsset.asset.balanceFormatted && isConnected && !isExecuting && depositBatches.length > 0;
|
|
4189
|
-
const displayError =
|
|
4322
|
+
const displayError = spiceAssetsError || error;
|
|
4190
4323
|
const containerStyles = {
|
|
4191
4324
|
backgroundColor: styles?.container?.backgroundColor || styles?.primaryBackground || theme.colors.background,
|
|
4192
4325
|
border: `1px solid ${styles?.container?.borderColor || theme.colors.border}`,
|
|
@@ -4213,7 +4346,7 @@ const DepositWidget = ({
|
|
|
4213
4346
|
onNewTx: () => {
|
|
4214
4347
|
clearStatus();
|
|
4215
4348
|
setSelectedDepositAsset(null);
|
|
4216
|
-
|
|
4349
|
+
refreshSpiceAssets();
|
|
4217
4350
|
},
|
|
4218
4351
|
explorerUrlBuilder: (chainId, txHash) => getExplorerUrl(chainId, txHash),
|
|
4219
4352
|
theme
|
|
@@ -4342,11 +4475,11 @@ const DepositWidget = ({
|
|
|
4342
4475
|
/* @__PURE__ */ jsx("div", { style: { marginBottom: theme.spacing.sm }, children: /* @__PURE__ */ jsx(
|
|
4343
4476
|
AssetSelector,
|
|
4344
4477
|
{
|
|
4345
|
-
assets:
|
|
4478
|
+
assets: spiceDepositAssets,
|
|
4346
4479
|
selectedAsset: selectedDepositAsset || void 0,
|
|
4347
4480
|
onAssetSelect: handleDepositAssetSelect,
|
|
4348
4481
|
onAmountChange: handleDepositAmountChange,
|
|
4349
|
-
loading:
|
|
4482
|
+
loading: loadingSpiceAssets,
|
|
4350
4483
|
label: "Deposit",
|
|
4351
4484
|
showBalance: true,
|
|
4352
4485
|
showMaxButton: true,
|
|
@@ -7641,7 +7774,8 @@ const DepositModal = React.memo(
|
|
|
7641
7774
|
tokenAddress,
|
|
7642
7775
|
chainId,
|
|
7643
7776
|
amount: amount.toString(),
|
|
7644
|
-
user: address
|
|
7777
|
+
user: address,
|
|
7778
|
+
isDeposit: true
|
|
7645
7779
|
});
|
|
7646
7780
|
await relayerService.submitSpiceDeposit({
|
|
7647
7781
|
txHash: transferToEmbeddedTx,
|
|
@@ -7649,7 +7783,8 @@ const DepositModal = React.memo(
|
|
|
7649
7783
|
tokenAddress,
|
|
7650
7784
|
chainId,
|
|
7651
7785
|
amount: amount.toString(),
|
|
7652
|
-
user: address
|
|
7786
|
+
user: address,
|
|
7787
|
+
isDeposit: true
|
|
7653
7788
|
});
|
|
7654
7789
|
console.log(
|
|
7655
7790
|
`Successfully submitted deposit for txHash: ${transferToEmbeddedTx}`
|
|
@@ -9251,7 +9386,8 @@ const WithdrawModal = React.memo(
|
|
|
9251
9386
|
sender: externalWalletAddress,
|
|
9252
9387
|
tokenAddress: apiTokenAddress,
|
|
9253
9388
|
chainId: destinationChainId,
|
|
9254
|
-
amount: amount2.toString()
|
|
9389
|
+
amount: amount2.toString(),
|
|
9390
|
+
isDeposit: false
|
|
9255
9391
|
});
|
|
9256
9392
|
const depositResult = await relayerService.submitSpiceDeposit({
|
|
9257
9393
|
user: externalWalletAddress,
|
|
@@ -9259,7 +9395,8 @@ const WithdrawModal = React.memo(
|
|
|
9259
9395
|
sender: externalWalletAddress,
|
|
9260
9396
|
tokenAddress: apiTokenAddress,
|
|
9261
9397
|
chainId: destinationChainId,
|
|
9262
|
-
amount: amount2.toString()
|
|
9398
|
+
amount: amount2.toString(),
|
|
9399
|
+
isDeposit: false
|
|
9263
9400
|
});
|
|
9264
9401
|
if (!depositResult.success) {
|
|
9265
9402
|
console.error(
|