@spicenet-io/spiceflow-ui 1.8.4 → 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
|
@@ -3988,61 +3988,55 @@ const useSpiceAssets = ({
|
|
|
3988
3988
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
3989
3989
|
}
|
|
3990
3990
|
const result = await response.json();
|
|
3991
|
-
if (result.success && result.data?.tokens) {
|
|
3992
|
-
const tokens = result.data.tokens;
|
|
3991
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
3993
3992
|
const parsedAssets = [];
|
|
3994
|
-
|
|
3995
|
-
const chainId =
|
|
3993
|
+
result.data.tokens.forEach((token) => {
|
|
3994
|
+
const chainId = token.chainId;
|
|
3995
|
+
const tokenAddress = token.tokenAddress;
|
|
3996
|
+
const rawBalanceStr = token.amount;
|
|
3996
3997
|
if (supportedChains && !supportedChains.includes(chainId)) {
|
|
3997
3998
|
return;
|
|
3998
3999
|
}
|
|
3999
|
-
const
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
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
|
-
}
|
|
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;
|
|
4044
4021
|
}
|
|
4045
|
-
}
|
|
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
|
+
}
|
|
4046
4040
|
}
|
|
4047
4041
|
});
|
|
4048
4042
|
setAssets(parsedAssets);
|
|
@@ -9049,51 +9043,45 @@ const useSpiceBalance = ({
|
|
|
9049
9043
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
9050
9044
|
}
|
|
9051
9045
|
const result = await response.json();
|
|
9052
|
-
if (result.success && result.data && result.data.tokens) {
|
|
9053
|
-
const tokens = result.data.tokens;
|
|
9046
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
9054
9047
|
const freeCollateralItems = [];
|
|
9055
9048
|
let totalBalance = 0;
|
|
9056
|
-
|
|
9057
|
-
const chainId =
|
|
9058
|
-
const
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
decimals = tokenConfig.decimals;
|
|
9079
|
-
tokenSymbol = tokenConfig.symbol;
|
|
9080
|
-
tokenName = tokenConfig.name;
|
|
9081
|
-
}
|
|
9082
|
-
}
|
|
9083
|
-
const balance = rawBalance / Math.pow(10, decimals);
|
|
9084
|
-
if (balance > 0) {
|
|
9085
|
-
freeCollateralItems.push({
|
|
9086
|
-
id: `${tokenSymbol.toLowerCase()}-${chainId}`,
|
|
9087
|
-
name: tokenSymbol,
|
|
9088
|
-
balance,
|
|
9089
|
-
subtitle: tokenName,
|
|
9090
|
-
iconColor: "#2775CA",
|
|
9091
|
-
networks: [chainId]
|
|
9092
|
-
});
|
|
9093
|
-
totalBalance += balance;
|
|
9094
|
-
}
|
|
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;
|
|
9095
9071
|
}
|
|
9096
|
-
}
|
|
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
|
+
}
|
|
9097
9085
|
}
|
|
9098
9086
|
});
|
|
9099
9087
|
if (totalBalance > 0 && freeCollateralItems.length > 0) {
|
package/dist/index.js
CHANGED
|
@@ -3986,61 +3986,55 @@ const useSpiceAssets = ({
|
|
|
3986
3986
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
3987
3987
|
}
|
|
3988
3988
|
const result = await response.json();
|
|
3989
|
-
if (result.success && result.data?.tokens) {
|
|
3990
|
-
const tokens = result.data.tokens;
|
|
3989
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
3991
3990
|
const parsedAssets = [];
|
|
3992
|
-
|
|
3993
|
-
const chainId =
|
|
3991
|
+
result.data.tokens.forEach((token) => {
|
|
3992
|
+
const chainId = token.chainId;
|
|
3993
|
+
const tokenAddress = token.tokenAddress;
|
|
3994
|
+
const rawBalanceStr = token.amount;
|
|
3994
3995
|
if (supportedChains && !supportedChains.includes(chainId)) {
|
|
3995
3996
|
return;
|
|
3996
3997
|
}
|
|
3997
|
-
const
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
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
|
-
}
|
|
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;
|
|
4042
4019
|
}
|
|
4043
|
-
}
|
|
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
|
+
}
|
|
4044
4038
|
}
|
|
4045
4039
|
});
|
|
4046
4040
|
setAssets(parsedAssets);
|
|
@@ -9047,51 +9041,45 @@ const useSpiceBalance = ({
|
|
|
9047
9041
|
throw new Error(`Failed to fetch balance: ${response.status}`);
|
|
9048
9042
|
}
|
|
9049
9043
|
const result = await response.json();
|
|
9050
|
-
if (result.success && result.data && result.data.tokens) {
|
|
9051
|
-
const tokens = result.data.tokens;
|
|
9044
|
+
if (result.success && result.data?.tokens && Array.isArray(result.data.tokens)) {
|
|
9052
9045
|
const freeCollateralItems = [];
|
|
9053
9046
|
let totalBalance = 0;
|
|
9054
|
-
|
|
9055
|
-
const chainId =
|
|
9056
|
-
const
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9076
|
-
decimals = tokenConfig.decimals;
|
|
9077
|
-
tokenSymbol = tokenConfig.symbol;
|
|
9078
|
-
tokenName = tokenConfig.name;
|
|
9079
|
-
}
|
|
9080
|
-
}
|
|
9081
|
-
const balance = rawBalance / Math.pow(10, decimals);
|
|
9082
|
-
if (balance > 0) {
|
|
9083
|
-
freeCollateralItems.push({
|
|
9084
|
-
id: `${tokenSymbol.toLowerCase()}-${chainId}`,
|
|
9085
|
-
name: tokenSymbol,
|
|
9086
|
-
balance,
|
|
9087
|
-
subtitle: tokenName,
|
|
9088
|
-
iconColor: "#2775CA",
|
|
9089
|
-
networks: [chainId]
|
|
9090
|
-
});
|
|
9091
|
-
totalBalance += balance;
|
|
9092
|
-
}
|
|
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;
|
|
9093
9069
|
}
|
|
9094
|
-
}
|
|
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
|
+
}
|
|
9095
9083
|
}
|
|
9096
9084
|
});
|
|
9097
9085
|
if (totalBalance > 0 && freeCollateralItems.length > 0) {
|