@spicenet-io/spiceflow-ui 1.8.3 → 1.8.5
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.
|
@@ -3,11 +3,11 @@ import { Asset } from "../../types/assets";
|
|
|
3
3
|
export interface SpiceBalanceApiResponse {
|
|
4
4
|
success: boolean;
|
|
5
5
|
data?: {
|
|
6
|
-
tokens: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
6
|
+
tokens: Array<{
|
|
7
|
+
chainId: number;
|
|
8
|
+
tokenAddress: string;
|
|
9
|
+
amount: string;
|
|
10
|
+
}>;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export interface UseSpiceAssetsConfig {
|
|
@@ -3,11 +3,11 @@ import { BalanceData } from "../../types/balance";
|
|
|
3
3
|
export interface SpiceBalanceApiResponse {
|
|
4
4
|
success: boolean;
|
|
5
5
|
data?: {
|
|
6
|
-
tokens: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
6
|
+
tokens: Array<{
|
|
7
|
+
chainId: number;
|
|
8
|
+
tokenAddress: string;
|
|
9
|
+
amount: string;
|
|
10
|
+
}>;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export interface UseSpiceBalanceConfig {
|
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",
|
|
@@ -3982,61 +3988,55 @@ const useSpiceAssets = ({
|
|
|
3982
3988
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
3983
3989
|
}
|
|
3984
3990
|
const result = await response.json();
|
|
3985
|
-
if (result.success && result.data?.tokens) {
|
|
3986
|
-
const tokens = result.data.tokens;
|
|
3991
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
3987
3992
|
const parsedAssets = [];
|
|
3988
|
-
|
|
3989
|
-
const chainId =
|
|
3993
|
+
result.data.tokens.forEach((token) => {
|
|
3994
|
+
const chainId = token.chainId;
|
|
3995
|
+
const tokenAddress = token.tokenAddress;
|
|
3996
|
+
const rawBalanceStr = token.amount;
|
|
3990
3997
|
if (supportedChains && !supportedChains.includes(chainId)) {
|
|
3991
3998
|
return;
|
|
3992
3999
|
}
|
|
3993
|
-
const
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
decimals = tokenConfig.decimals;
|
|
4015
|
-
symbol = tokenConfig.symbol;
|
|
4016
|
-
name = tokenConfig.name;
|
|
4017
|
-
logoURI = tokenConfig.logoURI;
|
|
4018
|
-
}
|
|
4019
|
-
}
|
|
4020
|
-
const balanceFormatted = parseFloat(
|
|
4021
|
-
(Number(rawBalance) / Math.pow(10, decimals)).toFixed(6)
|
|
4022
|
-
);
|
|
4023
|
-
if (balanceFormatted > 0) {
|
|
4024
|
-
parsedAssets.push({
|
|
4025
|
-
address: isNative ? "0x0000000000000000000000000000000000000000" : tokenAddress,
|
|
4026
|
-
symbol,
|
|
4027
|
-
name,
|
|
4028
|
-
decimals,
|
|
4029
|
-
chainId,
|
|
4030
|
-
balance: rawBalance,
|
|
4031
|
-
balanceFormatted,
|
|
4032
|
-
balanceUsd: 0,
|
|
4033
|
-
// API doesn't provide USD value
|
|
4034
|
-
isNative,
|
|
4035
|
-
logoURI
|
|
4036
|
-
});
|
|
4037
|
-
}
|
|
4000
|
+
const rawBalance = BigInt(rawBalanceStr || "0");
|
|
4001
|
+
if (rawBalance > BigInt(0)) {
|
|
4002
|
+
const chainConfig = getChainConfig(chainId);
|
|
4003
|
+
const isNative = tokenAddress.toLowerCase() === "0x0" || tokenAddress.toLowerCase() === "0x0000000000000000000000000000000000000000" || tokenAddress.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
4004
|
+
let decimals = 18;
|
|
4005
|
+
let symbol = "TOKEN";
|
|
4006
|
+
let name = tokenAddress.slice(0, 6) + "..." + tokenAddress.slice(-4);
|
|
4007
|
+
let logoURI;
|
|
4008
|
+
if (isNative) {
|
|
4009
|
+
decimals = chainConfig?.nativeCurrency?.decimals || 18;
|
|
4010
|
+
symbol = chainConfig?.nativeCurrency?.symbol || "ETH";
|
|
4011
|
+
name = chainConfig?.nativeCurrency?.name || "Native Token";
|
|
4012
|
+
} else {
|
|
4013
|
+
const tokenConfig = chainConfig?.supportedTokens?.find(
|
|
4014
|
+
(t) => t.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
4015
|
+
);
|
|
4016
|
+
if (tokenConfig) {
|
|
4017
|
+
decimals = tokenConfig.decimals;
|
|
4018
|
+
symbol = tokenConfig.symbol;
|
|
4019
|
+
name = tokenConfig.name;
|
|
4020
|
+
logoURI = tokenConfig.logoURI;
|
|
4038
4021
|
}
|
|
4039
|
-
}
|
|
4022
|
+
}
|
|
4023
|
+
const balanceFormatted = parseFloat(
|
|
4024
|
+
(Number(rawBalance) / Math.pow(10, decimals)).toFixed(6)
|
|
4025
|
+
);
|
|
4026
|
+
if (balanceFormatted > 0) {
|
|
4027
|
+
parsedAssets.push({
|
|
4028
|
+
address: isNative ? "0x0000000000000000000000000000000000000000" : tokenAddress,
|
|
4029
|
+
symbol,
|
|
4030
|
+
name,
|
|
4031
|
+
decimals,
|
|
4032
|
+
chainId,
|
|
4033
|
+
balance: rawBalance,
|
|
4034
|
+
balanceFormatted,
|
|
4035
|
+
balanceUsd: 0,
|
|
4036
|
+
isNative,
|
|
4037
|
+
logoURI
|
|
4038
|
+
});
|
|
4039
|
+
}
|
|
4040
4040
|
}
|
|
4041
4041
|
});
|
|
4042
4042
|
setAssets(parsedAssets);
|
|
@@ -9043,51 +9043,45 @@ const useSpiceBalance = ({
|
|
|
9043
9043
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
9044
9044
|
}
|
|
9045
9045
|
const result = await response.json();
|
|
9046
|
-
if (result.success && result.data && result.data.tokens) {
|
|
9047
|
-
const tokens = result.data.tokens;
|
|
9046
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
9048
9047
|
const freeCollateralItems = [];
|
|
9049
9048
|
let totalBalance = 0;
|
|
9050
|
-
|
|
9051
|
-
const chainId =
|
|
9052
|
-
const
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
decimals = tokenConfig.decimals;
|
|
9073
|
-
tokenSymbol = tokenConfig.symbol;
|
|
9074
|
-
tokenName = tokenConfig.name;
|
|
9075
|
-
}
|
|
9076
|
-
}
|
|
9077
|
-
const balance = rawBalance / Math.pow(10, decimals);
|
|
9078
|
-
if (balance > 0) {
|
|
9079
|
-
freeCollateralItems.push({
|
|
9080
|
-
id: `${tokenSymbol.toLowerCase()}-${chainId}`,
|
|
9081
|
-
name: tokenSymbol,
|
|
9082
|
-
balance,
|
|
9083
|
-
subtitle: tokenName,
|
|
9084
|
-
iconColor: "#2775CA",
|
|
9085
|
-
networks: [chainId]
|
|
9086
|
-
});
|
|
9087
|
-
totalBalance += balance;
|
|
9088
|
-
}
|
|
9049
|
+
result.data.tokens.forEach((token) => {
|
|
9050
|
+
const chainId = token.chainId;
|
|
9051
|
+
const tokenAddress = token.tokenAddress;
|
|
9052
|
+
const rawBalance = parseFloat(token.amount || "0");
|
|
9053
|
+
if (rawBalance > 0) {
|
|
9054
|
+
const chainConfig = getChainConfig(chainId);
|
|
9055
|
+
const isNative = tokenAddress.toLowerCase() === "0x0" || tokenAddress.toLowerCase() === "0x0000000000000000000000000000000000000000" || tokenAddress.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
9056
|
+
let decimals = 18;
|
|
9057
|
+
let tokenSymbol = "TOKEN";
|
|
9058
|
+
let tokenName = tokenAddress.slice(0, 6) + "..." + tokenAddress.slice(-4);
|
|
9059
|
+
if (isNative) {
|
|
9060
|
+
decimals = chainConfig?.nativeCurrency?.decimals || 18;
|
|
9061
|
+
tokenSymbol = chainConfig?.nativeCurrency?.symbol || "ETH";
|
|
9062
|
+
tokenName = chainConfig?.nativeCurrency?.name || "Native Token";
|
|
9063
|
+
} else {
|
|
9064
|
+
const tokenConfig = chainConfig?.supportedTokens?.find(
|
|
9065
|
+
(t) => t.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
9066
|
+
);
|
|
9067
|
+
if (tokenConfig) {
|
|
9068
|
+
decimals = tokenConfig.decimals;
|
|
9069
|
+
tokenSymbol = tokenConfig.symbol;
|
|
9070
|
+
tokenName = tokenConfig.name;
|
|
9089
9071
|
}
|
|
9090
|
-
}
|
|
9072
|
+
}
|
|
9073
|
+
const balance = rawBalance / Math.pow(10, decimals);
|
|
9074
|
+
if (balance > 0) {
|
|
9075
|
+
freeCollateralItems.push({
|
|
9076
|
+
id: `${tokenSymbol.toLowerCase()}-${chainId}`,
|
|
9077
|
+
name: tokenSymbol,
|
|
9078
|
+
balance,
|
|
9079
|
+
subtitle: tokenName,
|
|
9080
|
+
iconColor: "#2775CA",
|
|
9081
|
+
networks: [chainId]
|
|
9082
|
+
});
|
|
9083
|
+
totalBalance += balance;
|
|
9084
|
+
}
|
|
9091
9085
|
}
|
|
9092
9086
|
});
|
|
9093
9087
|
if (totalBalance > 0 && freeCollateralItems.length > 0) {
|
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",
|
|
@@ -3980,61 +3986,55 @@ const useSpiceAssets = ({
|
|
|
3980
3986
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
3981
3987
|
}
|
|
3982
3988
|
const result = await response.json();
|
|
3983
|
-
if (result.success && result.data?.tokens) {
|
|
3984
|
-
const tokens = result.data.tokens;
|
|
3989
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
3985
3990
|
const parsedAssets = [];
|
|
3986
|
-
|
|
3987
|
-
const chainId =
|
|
3991
|
+
result.data.tokens.forEach((token) => {
|
|
3992
|
+
const chainId = token.chainId;
|
|
3993
|
+
const tokenAddress = token.tokenAddress;
|
|
3994
|
+
const rawBalanceStr = token.amount;
|
|
3988
3995
|
if (supportedChains && !supportedChains.includes(chainId)) {
|
|
3989
3996
|
return;
|
|
3990
3997
|
}
|
|
3991
|
-
const
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
decimals = tokenConfig.decimals;
|
|
4013
|
-
symbol = tokenConfig.symbol;
|
|
4014
|
-
name = tokenConfig.name;
|
|
4015
|
-
logoURI = tokenConfig.logoURI;
|
|
4016
|
-
}
|
|
4017
|
-
}
|
|
4018
|
-
const balanceFormatted = parseFloat(
|
|
4019
|
-
(Number(rawBalance) / Math.pow(10, decimals)).toFixed(6)
|
|
4020
|
-
);
|
|
4021
|
-
if (balanceFormatted > 0) {
|
|
4022
|
-
parsedAssets.push({
|
|
4023
|
-
address: isNative ? "0x0000000000000000000000000000000000000000" : tokenAddress,
|
|
4024
|
-
symbol,
|
|
4025
|
-
name,
|
|
4026
|
-
decimals,
|
|
4027
|
-
chainId,
|
|
4028
|
-
balance: rawBalance,
|
|
4029
|
-
balanceFormatted,
|
|
4030
|
-
balanceUsd: 0,
|
|
4031
|
-
// API doesn't provide USD value
|
|
4032
|
-
isNative,
|
|
4033
|
-
logoURI
|
|
4034
|
-
});
|
|
4035
|
-
}
|
|
3998
|
+
const rawBalance = BigInt(rawBalanceStr || "0");
|
|
3999
|
+
if (rawBalance > BigInt(0)) {
|
|
4000
|
+
const chainConfig = getChainConfig(chainId);
|
|
4001
|
+
const isNative = tokenAddress.toLowerCase() === "0x0" || tokenAddress.toLowerCase() === "0x0000000000000000000000000000000000000000" || tokenAddress.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
4002
|
+
let decimals = 18;
|
|
4003
|
+
let symbol = "TOKEN";
|
|
4004
|
+
let name = tokenAddress.slice(0, 6) + "..." + tokenAddress.slice(-4);
|
|
4005
|
+
let logoURI;
|
|
4006
|
+
if (isNative) {
|
|
4007
|
+
decimals = chainConfig?.nativeCurrency?.decimals || 18;
|
|
4008
|
+
symbol = chainConfig?.nativeCurrency?.symbol || "ETH";
|
|
4009
|
+
name = chainConfig?.nativeCurrency?.name || "Native Token";
|
|
4010
|
+
} else {
|
|
4011
|
+
const tokenConfig = chainConfig?.supportedTokens?.find(
|
|
4012
|
+
(t) => t.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
4013
|
+
);
|
|
4014
|
+
if (tokenConfig) {
|
|
4015
|
+
decimals = tokenConfig.decimals;
|
|
4016
|
+
symbol = tokenConfig.symbol;
|
|
4017
|
+
name = tokenConfig.name;
|
|
4018
|
+
logoURI = tokenConfig.logoURI;
|
|
4036
4019
|
}
|
|
4037
|
-
}
|
|
4020
|
+
}
|
|
4021
|
+
const balanceFormatted = parseFloat(
|
|
4022
|
+
(Number(rawBalance) / Math.pow(10, decimals)).toFixed(6)
|
|
4023
|
+
);
|
|
4024
|
+
if (balanceFormatted > 0) {
|
|
4025
|
+
parsedAssets.push({
|
|
4026
|
+
address: isNative ? "0x0000000000000000000000000000000000000000" : tokenAddress,
|
|
4027
|
+
symbol,
|
|
4028
|
+
name,
|
|
4029
|
+
decimals,
|
|
4030
|
+
chainId,
|
|
4031
|
+
balance: rawBalance,
|
|
4032
|
+
balanceFormatted,
|
|
4033
|
+
balanceUsd: 0,
|
|
4034
|
+
isNative,
|
|
4035
|
+
logoURI
|
|
4036
|
+
});
|
|
4037
|
+
}
|
|
4038
4038
|
}
|
|
4039
4039
|
});
|
|
4040
4040
|
setAssets(parsedAssets);
|
|
@@ -9041,51 +9041,45 @@ const useSpiceBalance = ({
|
|
|
9041
9041
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
9042
9042
|
}
|
|
9043
9043
|
const result = await response.json();
|
|
9044
|
-
if (result.success && result.data && result.data.tokens) {
|
|
9045
|
-
const tokens = result.data.tokens;
|
|
9044
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
9046
9045
|
const freeCollateralItems = [];
|
|
9047
9046
|
let totalBalance = 0;
|
|
9048
|
-
|
|
9049
|
-
const chainId =
|
|
9050
|
-
const
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
decimals = tokenConfig.decimals;
|
|
9071
|
-
tokenSymbol = tokenConfig.symbol;
|
|
9072
|
-
tokenName = tokenConfig.name;
|
|
9073
|
-
}
|
|
9074
|
-
}
|
|
9075
|
-
const balance = rawBalance / Math.pow(10, decimals);
|
|
9076
|
-
if (balance > 0) {
|
|
9077
|
-
freeCollateralItems.push({
|
|
9078
|
-
id: `${tokenSymbol.toLowerCase()}-${chainId}`,
|
|
9079
|
-
name: tokenSymbol,
|
|
9080
|
-
balance,
|
|
9081
|
-
subtitle: tokenName,
|
|
9082
|
-
iconColor: "#2775CA",
|
|
9083
|
-
networks: [chainId]
|
|
9084
|
-
});
|
|
9085
|
-
totalBalance += balance;
|
|
9086
|
-
}
|
|
9047
|
+
result.data.tokens.forEach((token) => {
|
|
9048
|
+
const chainId = token.chainId;
|
|
9049
|
+
const tokenAddress = token.tokenAddress;
|
|
9050
|
+
const rawBalance = parseFloat(token.amount || "0");
|
|
9051
|
+
if (rawBalance > 0) {
|
|
9052
|
+
const chainConfig = getChainConfig(chainId);
|
|
9053
|
+
const isNative = tokenAddress.toLowerCase() === "0x0" || tokenAddress.toLowerCase() === "0x0000000000000000000000000000000000000000" || tokenAddress.toLowerCase() === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
9054
|
+
let decimals = 18;
|
|
9055
|
+
let tokenSymbol = "TOKEN";
|
|
9056
|
+
let tokenName = tokenAddress.slice(0, 6) + "..." + tokenAddress.slice(-4);
|
|
9057
|
+
if (isNative) {
|
|
9058
|
+
decimals = chainConfig?.nativeCurrency?.decimals || 18;
|
|
9059
|
+
tokenSymbol = chainConfig?.nativeCurrency?.symbol || "ETH";
|
|
9060
|
+
tokenName = chainConfig?.nativeCurrency?.name || "Native Token";
|
|
9061
|
+
} else {
|
|
9062
|
+
const tokenConfig = chainConfig?.supportedTokens?.find(
|
|
9063
|
+
(t) => t.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
9064
|
+
);
|
|
9065
|
+
if (tokenConfig) {
|
|
9066
|
+
decimals = tokenConfig.decimals;
|
|
9067
|
+
tokenSymbol = tokenConfig.symbol;
|
|
9068
|
+
tokenName = tokenConfig.name;
|
|
9087
9069
|
}
|
|
9088
|
-
}
|
|
9070
|
+
}
|
|
9071
|
+
const balance = rawBalance / Math.pow(10, decimals);
|
|
9072
|
+
if (balance > 0) {
|
|
9073
|
+
freeCollateralItems.push({
|
|
9074
|
+
id: `${tokenSymbol.toLowerCase()}-${chainId}`,
|
|
9075
|
+
name: tokenSymbol,
|
|
9076
|
+
balance,
|
|
9077
|
+
subtitle: tokenName,
|
|
9078
|
+
iconColor: "#2775CA",
|
|
9079
|
+
networks: [chainId]
|
|
9080
|
+
});
|
|
9081
|
+
totalBalance += balance;
|
|
9082
|
+
}
|
|
9089
9083
|
}
|
|
9090
9084
|
});
|
|
9091
9085
|
if (totalBalance > 0 && freeCollateralItems.length > 0) {
|