@0xsquid/react-hooks 8.11.1-beta-danal.2 → 8.11.1-beta-danal.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/dist/core/constants.d.ts +1 -0
- package/dist/core/types/danal.d.ts +18 -0
- package/dist/core/types/index.d.ts +2 -1
- package/dist/core/types/tokens.d.ts +1 -8
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/tokens/useBalance.d.ts +1 -0
- package/dist/hooks/tokens/useNativeBalance.d.ts +1 -0
- package/dist/{index-ByakOYXP.js → index-DUJ-UlLM.js} +123 -9
- package/dist/index-DUJ-UlLM.js.map +1 -0
- package/dist/{index-nTqoaD0B.js → index-DrkMKLtr.js} +125 -8
- package/dist/index-DrkMKLtr.js.map +1 -0
- package/dist/{index.es-DtFDz6qc.js → index.es-C7zrx1ig.js} +2 -2
- package/dist/{index.es-DtFDz6qc.js.map → index.es-C7zrx1ig.js.map} +1 -1
- package/dist/{index.es--AR2n7a0.js → index.es-CDalyOHR.js} +2 -2
- package/dist/{index.es--AR2n7a0.js.map → index.es-CDalyOHR.js.map} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/{secretService-29Ak2qp5.js → secretService-CFS8rXMv.js} +2 -2
- package/dist/{secretService-29Ak2qp5.js.map → secretService-CFS8rXMv.js.map} +1 -1
- package/dist/{secretService-cgr3P1zw.js → secretService-YF4EFa4h.js} +2 -2
- package/dist/{secretService-cgr3P1zw.js.map → secretService-YF4EFa4h.js.map} +1 -1
- package/dist/server.esm.js.map +1 -1
- package/dist/server.js.map +1 -1
- package/dist/services/external/danalApiClient.d.ts +8 -0
- package/dist/services/external/index.d.ts +1 -0
- package/dist/services/external/rpcService.d.ts +2 -0
- package/dist/services/internal/danalService.d.ts +2 -0
- package/dist/services/internal/searchService.d.ts +1 -2
- package/dist/{stellarService.client-B__dTUBZ.js → stellarService.client-LAWbES06.js} +2 -2
- package/dist/{stellarService.client-B__dTUBZ.js.map → stellarService.client-LAWbES06.js.map} +1 -1
- package/dist/{stellarService.client-D-zkMI5s.js → stellarService.client-uTJfWhDa.js} +2 -2
- package/dist/{stellarService.client-D-zkMI5s.js.map → stellarService.client-uTJfWhDa.js.map} +1 -1
- package/dist/tests/danalBalances.test.d.ts +1 -0
- package/package.json +2 -2
- package/dist/index-ByakOYXP.js.map +0 -1
- package/dist/index-nTqoaD0B.js.map +0 -1
|
@@ -110,6 +110,7 @@ const internalSquidApiBaseUrl = "https://app.squidrouter.com/api";
|
|
|
110
110
|
const XAMAN_API_URL = `${internalSquidApiBaseUrl}/xaman/`;
|
|
111
111
|
const TOKEN_PRICE_API_URL = `${internalSquidApiBaseUrl}/coingecko`;
|
|
112
112
|
const CANTON_AMULET_REGISTRY_URL = `${internalSquidApiBaseUrl}/canton/scan-proxy`;
|
|
113
|
+
const DANAL_TESTNET_API_URL = "https://testnet.squid-api.payprotocol.io";
|
|
113
114
|
const DEFAULT_ROUTE_REFETCH_INTERVAL = 30_000;
|
|
114
115
|
const SOLANA_RPC_URL = "https://meredith-ute2ko-fast-mainnet.helius-rpc.com";
|
|
115
116
|
const INTEGRATOR_ID = "squid-widget-playground-local-cd33cba6-7e12-4fcc-8d5d-35e286f655ea";
|
|
@@ -21132,6 +21133,11 @@ function groupCantonHoldingBalances(acsResponse) {
|
|
|
21132
21133
|
return Object.fromEntries(Object.entries(totals).map(([key, total]) => [key, total.toString(10)]));
|
|
21133
21134
|
}
|
|
21134
21135
|
|
|
21136
|
+
function isDanalTestnetToken(token) {
|
|
21137
|
+
return (token?.type === squidTypes.ChainType.DANAL &&
|
|
21138
|
+
token.chainId === CHAIN_IDS.DANAL_TESTNET &&
|
|
21139
|
+
token.address.toLowerCase() === nativeDanalTokenAddress);
|
|
21140
|
+
}
|
|
21135
21141
|
// Matches the backend validation: "PCI" + 50 uppercase-hex chars, case-sensitive.
|
|
21136
21142
|
const DANAL_ADDRESS_REGEX = /^PCI[0-9A-F]{50}$/;
|
|
21137
21143
|
function isDanalAddressValid(address) {
|
|
@@ -22592,6 +22598,44 @@ function mergeWallets({ multiChainWallets, singleChainWallets, }) {
|
|
|
22592
22598
|
return unifiedWallets;
|
|
22593
22599
|
}
|
|
22594
22600
|
|
|
22601
|
+
const isBalanceAmount = (value) => typeof value === "string" && /^\d+$/.test(value);
|
|
22602
|
+
class DanalApiClient {
|
|
22603
|
+
apiUrl;
|
|
22604
|
+
constructor(apiUrl = DANAL_TESTNET_API_URL) {
|
|
22605
|
+
this.apiUrl = apiUrl;
|
|
22606
|
+
}
|
|
22607
|
+
async getBalance(address) {
|
|
22608
|
+
const data = await this.fetch("balance", address);
|
|
22609
|
+
if (data?.address !== address ||
|
|
22610
|
+
data.token !== "PCI" ||
|
|
22611
|
+
!isBalanceAmount(data.balance)) {
|
|
22612
|
+
throw new Error("Invalid Danal balance response");
|
|
22613
|
+
}
|
|
22614
|
+
return data;
|
|
22615
|
+
}
|
|
22616
|
+
async getAccountInfo(address) {
|
|
22617
|
+
const data = await this.fetch("account", address);
|
|
22618
|
+
if (data?.["@account"] !== address ||
|
|
22619
|
+
data.token !== "PCI" ||
|
|
22620
|
+
data.balance?.["@balance"] !== address ||
|
|
22621
|
+
!isBalanceAmount(data.balance.amount)) {
|
|
22622
|
+
throw new Error("Invalid Danal account response");
|
|
22623
|
+
}
|
|
22624
|
+
return data;
|
|
22625
|
+
}
|
|
22626
|
+
async fetch(resource, address) {
|
|
22627
|
+
if (!isDanalAddressValid(address)) {
|
|
22628
|
+
throw new Error("Invalid Danal address");
|
|
22629
|
+
}
|
|
22630
|
+
const url = `${this.apiUrl.replace(/\/$/, "")}/${resource}/${address}`;
|
|
22631
|
+
const response = await fetch(url);
|
|
22632
|
+
if (!response.ok) {
|
|
22633
|
+
throw new Error(`Danal API error: ${response.status}`);
|
|
22634
|
+
}
|
|
22635
|
+
return response.json();
|
|
22636
|
+
}
|
|
22637
|
+
}
|
|
22638
|
+
|
|
22595
22639
|
const provider = new ethers.CloudflareProvider();
|
|
22596
22640
|
const API_BASE_URL = `${internalSquidApiBaseUrl}/ens`;
|
|
22597
22641
|
const getAvatarFromEns = async (ensName) => {
|
|
@@ -23735,7 +23779,7 @@ const filterViewableTokens = (tokens, config, direction) => {
|
|
|
23735
23779
|
};
|
|
23736
23780
|
const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
|
|
23737
23781
|
const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
|
|
23738
|
-
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-
|
|
23782
|
+
const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-CFS8rXMv.js'); });
|
|
23739
23783
|
return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
|
|
23740
23784
|
};
|
|
23741
23785
|
function getTokenAssetsKey(token) {
|
|
@@ -27495,7 +27539,7 @@ function useStellarWallets() {
|
|
|
27495
27539
|
try {
|
|
27496
27540
|
const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
|
|
27497
27541
|
const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module.mjs');
|
|
27498
|
-
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-
|
|
27542
|
+
const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-uTJfWhDa.js'); });
|
|
27499
27543
|
const modules = [...initializeAllModules(), new LedgerModule()];
|
|
27500
27544
|
const promises = modules.map(async (module) => {
|
|
27501
27545
|
const isAvailable = await module.isAvailable();
|
|
@@ -30112,6 +30156,24 @@ const getAllSuiTokensBalance = async (userAddress, suiTokens, suiChains) => {
|
|
|
30112
30156
|
const allResults = await Promise.all(suiChains.map(getBalancesForChain));
|
|
30113
30157
|
return allResults.flat();
|
|
30114
30158
|
};
|
|
30159
|
+
const getDanalTokenBalance = async (userAddress, token) => {
|
|
30160
|
+
if (!isDanalTestnetToken(token))
|
|
30161
|
+
return BigInt(0);
|
|
30162
|
+
const { balance } = await new DanalApiClient().getBalance(userAddress);
|
|
30163
|
+
return BigInt(balance);
|
|
30164
|
+
};
|
|
30165
|
+
const getAllDanalTokensBalance = async (userAddress, tokens) => {
|
|
30166
|
+
const nativeToken = tokens.find(isDanalTestnetToken);
|
|
30167
|
+
const balance = nativeToken
|
|
30168
|
+
? await getDanalTokenBalance(userAddress, nativeToken)
|
|
30169
|
+
: BigInt(0);
|
|
30170
|
+
return tokens.map((token) => ({
|
|
30171
|
+
...token,
|
|
30172
|
+
balance: isDanalTestnetToken(token)
|
|
30173
|
+
? formatBNToReadable(balance, token.decimals)
|
|
30174
|
+
: "0",
|
|
30175
|
+
}));
|
|
30176
|
+
};
|
|
30115
30177
|
const getXrplTokenBalance = async (userAddress, token, chain) => {
|
|
30116
30178
|
const xrplClient = await getClient(chain);
|
|
30117
30179
|
const balance = await xrplClient.getBalance(userAddress, token.address);
|
|
@@ -30391,6 +30453,25 @@ const useStellarBalance = ({ userAddress, chain, enabled, token, refreshInterval
|
|
|
30391
30453
|
});
|
|
30392
30454
|
return { balance, isLoading };
|
|
30393
30455
|
};
|
|
30456
|
+
const useDanalBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS$1, }) => {
|
|
30457
|
+
const { data: balance = "0", isInitialLoading } = reactQuery.useQuery({
|
|
30458
|
+
queryKey: keys().balance(chain?.chainId, token?.address, userAddress),
|
|
30459
|
+
queryFn: async () => {
|
|
30460
|
+
if (!userAddress || !token)
|
|
30461
|
+
return "0";
|
|
30462
|
+
const balanceBn = await getDanalTokenBalance(userAddress, token);
|
|
30463
|
+
return formatBNToReadable(balanceBn, token.decimals);
|
|
30464
|
+
},
|
|
30465
|
+
enabled: enabled &&
|
|
30466
|
+
chain?.chainType === squidTypes.ChainType.DANAL &&
|
|
30467
|
+
chain.chainId === token?.chainId &&
|
|
30468
|
+
isDanalTestnetToken(token) &&
|
|
30469
|
+
isDanalAddressValid(userAddress),
|
|
30470
|
+
refetchInterval: refreshIntervalMs,
|
|
30471
|
+
retry: 2,
|
|
30472
|
+
});
|
|
30473
|
+
return { balance, isLoading: isInitialLoading };
|
|
30474
|
+
};
|
|
30394
30475
|
const useCantonBalance = ({ chain, token, userAddress, enabled = true, refreshIntervalMs = DEFAULT_REFRESH_INTERVAL_MS$1, }) => {
|
|
30395
30476
|
const cantonConnector = useWalletStore((store) => store.connectedWalletsByChainType[squidTypes.ChainType.CANTON]?.wallet?.connector);
|
|
30396
30477
|
const { data: balance = "0", isLoading } = reactQuery.useQuery({
|
|
@@ -30635,6 +30716,23 @@ const useCantonNativeBalance = ({ address, chain, }) => {
|
|
|
30635
30716
|
}, [nativeToken?.decimals, rawBalance]);
|
|
30636
30717
|
return { balance, isLoading };
|
|
30637
30718
|
};
|
|
30719
|
+
const useDanalNativeBalance = ({ address, chain, }) => {
|
|
30720
|
+
const { nativeToken } = useNativeTokenForChain(chain);
|
|
30721
|
+
const { balance: rawBalance, isLoading } = useDanalBalance({
|
|
30722
|
+
chain,
|
|
30723
|
+
token: nativeToken,
|
|
30724
|
+
userAddress: address,
|
|
30725
|
+
});
|
|
30726
|
+
const balance = React.useMemo(() => {
|
|
30727
|
+
if (nativeToken?.decimals != null) {
|
|
30728
|
+
return {
|
|
30729
|
+
decimals: nativeToken.decimals,
|
|
30730
|
+
value: parseToBigInt(rawBalance, nativeToken.decimals),
|
|
30731
|
+
};
|
|
30732
|
+
}
|
|
30733
|
+
}, [nativeToken?.decimals, rawBalance]);
|
|
30734
|
+
return { balance, isLoading };
|
|
30735
|
+
};
|
|
30638
30736
|
const useNativeBalance = (chain) => {
|
|
30639
30737
|
const { connectedAddresses } = useWallet();
|
|
30640
30738
|
const { data: cosmosAddressForChain } = useCosmosForChain(chain);
|
|
@@ -30669,6 +30767,10 @@ const useNativeBalance = (chain) => {
|
|
|
30669
30767
|
address: connectedAddresses[squidTypes.ChainType.CANTON],
|
|
30670
30768
|
chain,
|
|
30671
30769
|
});
|
|
30770
|
+
const { balance: nativeDanalBalance, isLoading: isDanalLoading } = useDanalNativeBalance({
|
|
30771
|
+
address: connectedAddresses[squidTypes.ChainType.DANAL],
|
|
30772
|
+
chain,
|
|
30773
|
+
});
|
|
30672
30774
|
const { nativeBalance, nativeBalanceFormatted } = React.useMemo(() => {
|
|
30673
30775
|
let balance;
|
|
30674
30776
|
switch (chain?.chainType) {
|
|
@@ -30697,7 +30799,7 @@ const useNativeBalance = (chain) => {
|
|
|
30697
30799
|
balance = nativeCantonBalance;
|
|
30698
30800
|
break;
|
|
30699
30801
|
case squidTypes.ChainType.DANAL:
|
|
30700
|
-
balance =
|
|
30802
|
+
balance = nativeDanalBalance;
|
|
30701
30803
|
break;
|
|
30702
30804
|
}
|
|
30703
30805
|
const balanceFormatted = !!balance
|
|
@@ -30717,6 +30819,7 @@ const useNativeBalance = (chain) => {
|
|
|
30717
30819
|
nativeXrplBalance,
|
|
30718
30820
|
nativeStellarBalance,
|
|
30719
30821
|
nativeCantonBalance,
|
|
30822
|
+
nativeDanalBalance,
|
|
30720
30823
|
]);
|
|
30721
30824
|
const isLoading = React.useMemo(() => {
|
|
30722
30825
|
if (!chain?.chainType)
|
|
@@ -30739,7 +30842,7 @@ const useNativeBalance = (chain) => {
|
|
|
30739
30842
|
case squidTypes.ChainType.CANTON:
|
|
30740
30843
|
return isCantonLoading;
|
|
30741
30844
|
case squidTypes.ChainType.DANAL:
|
|
30742
|
-
return
|
|
30845
|
+
return isDanalLoading;
|
|
30743
30846
|
}
|
|
30744
30847
|
}, [
|
|
30745
30848
|
chain?.chainType,
|
|
@@ -30751,6 +30854,7 @@ const useNativeBalance = (chain) => {
|
|
|
30751
30854
|
isXrpLoading,
|
|
30752
30855
|
isStellarLoading,
|
|
30753
30856
|
isCantonLoading,
|
|
30857
|
+
isDanalLoading,
|
|
30754
30858
|
]);
|
|
30755
30859
|
return { nativeBalance, nativeBalanceFormatted, isLoading };
|
|
30756
30860
|
};
|
|
@@ -30965,7 +31069,7 @@ function hederaWalletConnect(parameters) {
|
|
|
30965
31069
|
const optionalChains = config.chains.map((x) => x.id);
|
|
30966
31070
|
if (!optionalChains.length)
|
|
30967
31071
|
return;
|
|
30968
|
-
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-
|
|
31072
|
+
const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-C7zrx1ig.js'); });
|
|
30969
31073
|
const rawProvider = await EthereumProvider.init({
|
|
30970
31074
|
...restParameters,
|
|
30971
31075
|
disableProviderPing: true,
|
|
@@ -31838,7 +31942,7 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
31838
31942
|
case squidTypes.ChainType.CANTON:
|
|
31839
31943
|
return cantonTokens.length > 0;
|
|
31840
31944
|
case squidTypes.ChainType.DANAL:
|
|
31841
|
-
return danalTokens.length > 0;
|
|
31945
|
+
return danalTokens.length > 0 && isDanalAddressValid(address);
|
|
31842
31946
|
}
|
|
31843
31947
|
}, [
|
|
31844
31948
|
chainType,
|
|
@@ -31901,6 +32005,9 @@ const useAllTokensWithBalanceForChainType = ({ chainType, address, direction, qu
|
|
|
31901
32005
|
})
|
|
31902
32006
|
: placeholderData.tokens;
|
|
31903
32007
|
break;
|
|
32008
|
+
case squidTypes.ChainType.DANAL:
|
|
32009
|
+
fetchedTokens = await getAllDanalTokensBalance(address, danalTokens);
|
|
32010
|
+
break;
|
|
31904
32011
|
default:
|
|
31905
32012
|
fetchedTokens = placeholderData.tokens;
|
|
31906
32013
|
break;
|
|
@@ -32091,6 +32198,12 @@ const useMultiChainBalance = ({ chain, token, userAddress, enabled = true, }) =>
|
|
|
32091
32198
|
userAddress,
|
|
32092
32199
|
enabled: chain?.chainType === squidTypes.ChainType.CANTON && enabled,
|
|
32093
32200
|
});
|
|
32201
|
+
const { balance: danalBalance } = useDanalBalance({
|
|
32202
|
+
chain,
|
|
32203
|
+
token,
|
|
32204
|
+
userAddress,
|
|
32205
|
+
enabled: chain?.chainType === squidTypes.ChainType.DANAL && enabled,
|
|
32206
|
+
});
|
|
32094
32207
|
const balance = React.useMemo(() => {
|
|
32095
32208
|
if (!chain?.chainType)
|
|
32096
32209
|
return "0";
|
|
@@ -32112,7 +32225,7 @@ const useMultiChainBalance = ({ chain, token, userAddress, enabled = true, }) =>
|
|
|
32112
32225
|
case squidTypes.ChainType.CANTON:
|
|
32113
32226
|
return cantonBalance;
|
|
32114
32227
|
case squidTypes.ChainType.DANAL:
|
|
32115
|
-
return
|
|
32228
|
+
return danalBalance;
|
|
32116
32229
|
}
|
|
32117
32230
|
}, [
|
|
32118
32231
|
chain?.chainType,
|
|
@@ -32124,6 +32237,7 @@ const useMultiChainBalance = ({ chain, token, userAddress, enabled = true, }) =>
|
|
|
32124
32237
|
xrplBalance,
|
|
32125
32238
|
stellarBalance,
|
|
32126
32239
|
cantonBalance,
|
|
32240
|
+
danalBalance,
|
|
32127
32241
|
]);
|
|
32128
32242
|
return { balance };
|
|
32129
32243
|
};
|
|
@@ -38972,6 +39086,7 @@ exports.CHAIN_IDS = CHAIN_IDS;
|
|
|
38972
39086
|
exports.CosmosProvider = CosmosProvider;
|
|
38973
39087
|
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
38974
39088
|
exports.DEFAULT_ROUTE_REFETCH_INTERVAL = DEFAULT_ROUTE_REFETCH_INTERVAL;
|
|
39089
|
+
exports.DanalApiClient = DanalApiClient;
|
|
38975
39090
|
exports.EnsService = EnsService;
|
|
38976
39091
|
exports.EvmNetworkNotSupportedErrorCode = EvmNetworkNotSupportedErrorCode;
|
|
38977
39092
|
exports.FINAL_TRANSACTION_STATUSES = FINAL_TRANSACTION_STATUSES;
|
|
@@ -39089,6 +39204,7 @@ exports.isCoralBridgeAction = isCoralBridgeAction;
|
|
|
39089
39204
|
exports.isCosmosAddressValid = isCosmosAddressValid;
|
|
39090
39205
|
exports.isDanalAddressValid = isDanalAddressValid;
|
|
39091
39206
|
exports.isDanalDepositRoute = isDanalDepositRoute;
|
|
39207
|
+
exports.isDanalTestnetToken = isDanalTestnetToken;
|
|
39092
39208
|
exports.isDanalTxHashValid = isDanalTxHashValid;
|
|
39093
39209
|
exports.isDepositAddressDirectTransferRoute = isDepositAddressDirectTransferRoute;
|
|
39094
39210
|
exports.isEmptyObject = isEmptyObject;
|
|
@@ -39171,6 +39287,7 @@ exports.useCosmosForChain = useCosmosForChain;
|
|
|
39171
39287
|
exports.useCosmosNativeBalance = useCosmosNativeBalance;
|
|
39172
39288
|
exports.useCountryDetails = useCountryDetails;
|
|
39173
39289
|
exports.useCurrencyDetails = useCurrencyDetails;
|
|
39290
|
+
exports.useDanalBalance = useDanalBalance;
|
|
39174
39291
|
exports.useDebouncedValue = useDebouncedValue;
|
|
39175
39292
|
exports.useDepositAddress = useDepositAddress;
|
|
39176
39293
|
exports.useDepositTransactionStatus = useDepositTransactionStatus;
|
|
@@ -39240,4 +39357,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
|
|
|
39240
39357
|
exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
|
|
39241
39358
|
exports.walletIconBaseUrl = walletIconBaseUrl;
|
|
39242
39359
|
exports.walletSupportsChainType = walletSupportsChainType;
|
|
39243
|
-
//# sourceMappingURL=index-
|
|
39360
|
+
//# sourceMappingURL=index-DrkMKLtr.js.map
|