@mezo-org/passport 0.4.0-dev.9 → 0.5.1-dev.0
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/README.md +18 -22
- package/dist/src/api/auth.d.ts +7 -3
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +3 -1
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +4 -1
- package/dist/src/api/client.d.ts.map +1 -1
- package/dist/src/api/client.js +9 -2
- package/dist/src/api/client.js.map +1 -1
- package/dist/src/api/portal.d.ts +3 -9
- package/dist/src/api/portal.d.ts.map +1 -1
- package/dist/src/api/portal.js +8 -5
- package/dist/src/api/portal.js.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Content.d.ts +4 -5
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +19 -61
- package/dist/src/components/Dropdown/Content.js.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.d.ts +9 -6
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +10 -10
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.d.ts +14 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +42 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +8 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +32 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +4 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +64 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +49 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +35 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
- package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
- package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
- package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +43 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +45 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +4 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +66 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +6 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +88 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
- package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
- package/dist/src/components/Dropdown/SlotNumber.js +67 -0
- package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
- package/dist/src/config.d.ts +19 -5
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +58 -14
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +11 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +12 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +18 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +67 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +9 -8
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +108 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +201 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +22 -1
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +4 -6
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +19 -13
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +20 -1
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
- package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
- package/dist/src/hooks/useRefreshPassport.js +44 -0
- package/dist/src/hooks/useRefreshPassport.js.map +1 -0
- package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useTokensBalances.d.ts +75 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +181 -0
- package/dist/src/hooks/useTokensBalances.js.map +1 -0
- package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
- package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useValidateMezoId.js +24 -0
- package/dist/src/hooks/useValidateMezoId.js.map +1 -0
- package/dist/src/hooks/useWalletAccount.d.ts +2 -1
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
- package/dist/src/hooks/useWalletAccount.js +20 -15
- package/dist/src/hooks/useWalletAccount.js.map +1 -1
- package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.js +63 -0
- package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +13 -0
- package/dist/src/lib/contracts/index.d.ts.map +1 -0
- package/dist/src/lib/contracts/index.js +66 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
- package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
- package/dist/src/lib/contracts/priceOracle.js +52 -0
- package/dist/src/lib/contracts/priceOracle.js.map +1 -0
- package/dist/src/provider.d.ts +7 -1
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +4 -1
- package/dist/src/provider.js.map +1 -1
- package/dist/src/stores/dropdownStore.d.ts +12 -0
- package/dist/src/stores/dropdownStore.d.ts.map +1 -0
- package/dist/src/stores/dropdownStore.js +13 -0
- package/dist/src/stores/dropdownStore.js.map +1 -0
- package/dist/src/utils/address.d.ts +1 -1
- package/dist/src/utils/address.d.ts.map +1 -1
- package/dist/src/utils/address.js +2 -0
- package/dist/src/utils/address.js.map +1 -1
- package/dist/src/utils/address.test.js +8 -5
- package/dist/src/utils/address.test.js.map +1 -1
- package/dist/src/utils/assets.d.ts +145 -0
- package/dist/src/utils/assets.d.ts.map +1 -0
- package/dist/src/utils/assets.js +100 -0
- package/dist/src/utils/assets.js.map +1 -0
- package/dist/src/utils/assets.test.d.ts +2 -0
- package/dist/src/utils/assets.test.d.ts.map +1 -0
- package/dist/src/utils/assets.test.js +46 -0
- package/dist/src/utils/assets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +13 -2
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +22 -8
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +44 -1
- package/dist/src/utils/currency.test.js.map +1 -1
- package/dist/src/utils/mezoId.d.ts +7 -0
- package/dist/src/utils/mezoId.d.ts.map +1 -0
- package/dist/src/utils/mezoId.js +41 -0
- package/dist/src/utils/mezoId.js.map +1 -0
- package/dist/src/utils/number2.d.ts +106 -0
- package/dist/src/utils/number2.d.ts.map +1 -0
- package/dist/src/utils/number2.js +289 -0
- package/dist/src/utils/number2.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +15 -33
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +26 -70
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +46 -42
- package/dist/src/utils/numbers.test.js.map +1 -1
- package/dist/src/utils/siww.d.ts +1 -0
- package/dist/src/utils/siww.d.ts.map +1 -1
- package/dist/src/utils/siww.js +50 -12
- package/dist/src/utils/siww.js.map +1 -1
- package/dist/src/utils/wagmi.d.ts +3 -0
- package/dist/src/utils/wagmi.d.ts.map +1 -0
- package/dist/src/utils/wagmi.js +7 -0
- package/dist/src/utils/wagmi.js.map +1 -0
- package/dist/src/wallet/index.d.ts +1 -1
- package/dist/src/wallet/index.d.ts.map +1 -1
- package/dist/src/wallet/index.js +1 -1
- package/dist/src/wallet/index.js.map +1 -1
- package/package.json +11 -8
- package/src/api/auth.ts +8 -4
- package/src/api/client.ts +11 -2
- package/src/api/portal.ts +11 -14
- package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
- package/src/components/Dropdown/Content.tsx +26 -121
- package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
- package/src/components/Dropdown/Dropdown.tsx +29 -17
- package/src/components/Dropdown/ListingItem.tsx +176 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
- package/src/components/Dropdown/README.md +10 -18
- package/src/components/Dropdown/Receive/Receive.tsx +144 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +75 -0
- package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
- package/src/components/Dropdown/Root/AccountError.tsx +34 -0
- package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
- package/src/components/Dropdown/Root/Root.tsx +77 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
- package/src/components/Dropdown/SlotNumber.tsx +131 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +88 -20
- package/src/constants.ts +12 -4
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useAssetsConversionRates.ts +79 -0
- package/src/hooks/useAuthenticateWithWallet.ts +30 -14
- package/src/hooks/useBorrowData.ts +246 -0
- package/src/hooks/useCreateAccount.ts +29 -2
- package/src/hooks/useGetCurrentAccount.ts +5 -7
- package/src/hooks/useLinkAccount.ts +37 -4
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useSignInWithWallet.ts +2 -2
- package/src/hooks/useSignUpWithWallet.ts +2 -2
- package/src/hooks/useTokensBalances.ts +265 -0
- package/src/hooks/useValidateMezoId.ts +31 -0
- package/src/hooks/useWalletAccount.ts +32 -20
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +12 -1
- package/src/lib/contracts/index.ts +99 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +11 -3
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +10 -6
- package/src/utils/address.ts +5 -3
- package/src/utils/assets.test.ts +57 -0
- package/src/utils/assets.ts +103 -0
- package/src/utils/currency.test.ts +77 -1
- package/src/utils/currency.ts +35 -9
- package/src/utils/mezoId.ts +51 -0
- package/src/utils/number2.ts +419 -0
- package/src/utils/numbers.test.ts +49 -42
- package/src/utils/numbers.ts +33 -95
- package/src/utils/siww.ts +71 -16
- package/src/utils/wagmi.ts +12 -0
- package/src/wallet/index.ts +3 -2
- package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
- package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAddress.js +0 -58
- package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
- package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.js +0 -44
- package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.d.ts +0 -7
- package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.js +0 -18
- package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts +0 -8
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.js +0 -44
- package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
- package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
- package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
- package/dist/src/hooks/useDropdownData.d.ts +0 -44
- package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
- package/dist/src/hooks/useDropdownData.js +0 -73
- package/dist/src/hooks/useDropdownData.js.map +0 -1
- package/dist/src/utils/cryptoAssets.d.ts +0 -28
- package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
- package/dist/src/utils/cryptoAssets.js +0 -73
- package/dist/src/utils/cryptoAssets.js.map +0 -1
- package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
- package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
- package/dist/src/utils/cryptoAssets.test.js +0 -49
- package/dist/src/utils/cryptoAssets.test.js.map +0 -1
- package/src/components/Dropdown/AccountAddress.tsx +0 -111
- package/src/components/Dropdown/AccountAssets.tsx +0 -110
- package/src/components/Dropdown/AccountBalance.tsx +0 -38
- package/src/components/Dropdown/WelcomeBlock.tsx +0 -92
- package/src/hooks/useAssetsUSDConversion.ts +0 -31
- package/src/hooks/useDropdownData.ts +0 -130
- package/src/utils/cryptoAssets.test.ts +0 -59
- package/src/utils/cryptoAssets.ts +0 -93
|
@@ -10,14 +10,12 @@ export function useGetCurrentAccount(queryOptions = {}) {
|
|
|
10
10
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
11
11
|
queryFn: async () => {
|
|
12
12
|
const currentAccount = await authApiClient.getCurrentAccount();
|
|
13
|
+
if (!currentAccount) {
|
|
14
|
+
throw new Error("No current account found");
|
|
15
|
+
}
|
|
13
16
|
const linkedWallets = currentAccount?.linkedAccounts?.filter((account) => account.type === "wallet");
|
|
14
17
|
if (!linkedWallets || linkedWallets.length === 0) {
|
|
15
|
-
|
|
16
|
-
...currentAccount,
|
|
17
|
-
mats: {
|
|
18
|
-
totalMats: 0,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
18
|
+
throw new Error("No linked wallets found for the current account");
|
|
21
19
|
}
|
|
22
20
|
const addresses = linkedWallets.map((account) => account.btcAddress || account.evmAddress);
|
|
23
21
|
const mats = await Promise.all(addresses.map((address) => portalApiClient.getPortalMats(address)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetCurrentAccount.js","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AASzD,MAAM,UAAU,oBAAoB,CAClC,eAGI,EAAE;IAEN,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAA;IAE5C,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;QAClD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,iBAAiB,EAAE,CAAA;YAC9D,MAAM,aAAa,GAAG,cAAc,EAAE,cAAc,EAAE,MAAM,CAC1D,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,CACvC,CAAA;YACD,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjD,
|
|
1
|
+
{"version":3,"file":"useGetCurrentAccount.js","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AASzD,MAAM,UAAU,oBAAoB,CAClC,eAGI,EAAE;IAEN,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAA;IAE5C,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;QAClD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,iBAAiB,EAAE,CAAA;YAC9D,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;YAC7C,CAAC;YAED,MAAM,aAAa,GAAG,cAAc,EAAE,cAAc,EAAE,MAAM,CAC1D,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,CACvC,CAAA;YACD,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;YACpE,CAAC;YAED,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CACjC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,CACtD,CAAA;YACD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAC5B,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CACnE,CAAA;YACD,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAC3B,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,OAAO,GAAG,WAAW,CAAC,SAAS,EACzD,CAAC,CACF,CAAA;YAED,OAAO;gBACL,GAAG,cAAc;gBACjB,IAAI,EAAE;oBACJ,SAAS;iBACV;aACF,CAAA;QACH,CAAC;QACD,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,CAAC;QACR,GAAG,YAAY;KAChB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { MutationOptions, DefaultError } from "@tanstack/react-query";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { LinkAccountResponse, SignatureData } from "../api";
|
|
3
|
+
type LinkAccountMutationFnParameters = ({
|
|
4
|
+
type: "wallet";
|
|
5
|
+
} & SignatureData) | {
|
|
6
|
+
type: "discord";
|
|
7
|
+
};
|
|
8
|
+
export declare function useLinkAccount(mutationOptions?: Omit<MutationOptions<LinkAccountResponse, DefaultError, LinkAccountMutationFnParameters>, "mutationFn" | "mutationKey">): {
|
|
4
9
|
data: undefined;
|
|
5
10
|
variables: undefined;
|
|
6
11
|
error: null;
|
|
@@ -15,11 +20,11 @@ export declare function useLinkAccount(mutationOptions?: Omit<MutationOptions<Li
|
|
|
15
20
|
failureReason: Error | null;
|
|
16
21
|
isPaused: boolean;
|
|
17
22
|
submittedAt: number;
|
|
18
|
-
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error,
|
|
19
|
-
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error,
|
|
23
|
+
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
24
|
+
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
20
25
|
} | {
|
|
21
26
|
data: undefined;
|
|
22
|
-
variables:
|
|
27
|
+
variables: LinkAccountMutationFnParameters;
|
|
23
28
|
error: null;
|
|
24
29
|
isError: false;
|
|
25
30
|
isIdle: false;
|
|
@@ -32,12 +37,12 @@ export declare function useLinkAccount(mutationOptions?: Omit<MutationOptions<Li
|
|
|
32
37
|
failureReason: Error | null;
|
|
33
38
|
isPaused: boolean;
|
|
34
39
|
submittedAt: number;
|
|
35
|
-
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error,
|
|
36
|
-
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error,
|
|
40
|
+
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
41
|
+
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
37
42
|
} | {
|
|
38
43
|
data: undefined;
|
|
39
44
|
error: Error;
|
|
40
|
-
variables:
|
|
45
|
+
variables: LinkAccountMutationFnParameters;
|
|
41
46
|
isError: true;
|
|
42
47
|
isIdle: false;
|
|
43
48
|
isPending: false;
|
|
@@ -49,12 +54,12 @@ export declare function useLinkAccount(mutationOptions?: Omit<MutationOptions<Li
|
|
|
49
54
|
failureReason: Error | null;
|
|
50
55
|
isPaused: boolean;
|
|
51
56
|
submittedAt: number;
|
|
52
|
-
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error,
|
|
53
|
-
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error,
|
|
57
|
+
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
58
|
+
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
54
59
|
} | {
|
|
55
60
|
data: LinkAccountResponse;
|
|
56
61
|
error: null;
|
|
57
|
-
variables:
|
|
62
|
+
variables: LinkAccountMutationFnParameters;
|
|
58
63
|
isError: false;
|
|
59
64
|
isIdle: false;
|
|
60
65
|
isPending: false;
|
|
@@ -66,7 +71,8 @@ export declare function useLinkAccount(mutationOptions?: Omit<MutationOptions<Li
|
|
|
66
71
|
failureReason: Error | null;
|
|
67
72
|
isPaused: boolean;
|
|
68
73
|
submittedAt: number;
|
|
69
|
-
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error,
|
|
70
|
-
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error,
|
|
74
|
+
linkAccount: import("@tanstack/react-query").UseMutateFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
75
|
+
linkAccountAsync: import("@tanstack/react-query").UseMutateAsyncFunction<LinkAccountResponse, Error, LinkAccountMutationFnParameters, unknown>;
|
|
71
76
|
};
|
|
77
|
+
export {};
|
|
72
78
|
//# sourceMappingURL=useLinkAccount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinkAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useLinkAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useLinkAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useLinkAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAKhE,KAAK,+BAA+B,GAChC,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,aAAa,CAAC,GACpC;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAA;AAEvB,wBAAgB,cAAc,CAC5B,eAAe,GAAE,IAAI,CACnB,eAAe,CACb,mBAAmB,EACnB,YAAY,EACZ,+BAA+B,CAChC,EACD,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyCP"}
|
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { useQueryClient, useMutation, } from "@tanstack/react-query";
|
|
2
2
|
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
3
|
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
import useWalletAccount from "./useWalletAccount";
|
|
5
|
+
import { getBitcoinPublicKeyFromConnector } from "../utils/wagmi";
|
|
4
6
|
export function useLinkAccount(mutationOptions = {}) {
|
|
5
7
|
const queryClient = useQueryClient();
|
|
6
8
|
const authApiClient = useAuthApiClient();
|
|
9
|
+
const walletAccount = useWalletAccount();
|
|
7
10
|
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions;
|
|
8
11
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
9
|
-
mutationFn: (
|
|
12
|
+
mutationFn: async (linkAccountMutationFnParameters) => {
|
|
13
|
+
if (linkAccountMutationFnParameters.type === "wallet") {
|
|
14
|
+
if (!walletAccount?.connector) {
|
|
15
|
+
throw new Error("Connector not defined.");
|
|
16
|
+
}
|
|
17
|
+
const bitcoinPublicKey = await getBitcoinPublicKeyFromConnector(walletAccount.connector);
|
|
18
|
+
// Linking bitcoin account
|
|
19
|
+
if (bitcoinPublicKey) {
|
|
20
|
+
return authApiClient.linkAccount({
|
|
21
|
+
...linkAccountMutationFnParameters,
|
|
22
|
+
bitcoinPublicKey,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Linking any other account like wallet evm address account or discord
|
|
27
|
+
return authApiClient.linkAccount(linkAccountMutationFnParameters);
|
|
28
|
+
},
|
|
10
29
|
onSuccess: (data, variables, context) => {
|
|
11
30
|
queryClient.resetQueries({ queryKey: [QUERY_KEYS.ACCOUNT] });
|
|
12
31
|
if (customOnSuccess)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLinkAccount.js","sourceRoot":"","sources":["../../../src/hooks/useLinkAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"useLinkAccount.js","sourceRoot":"","sources":["../../../src/hooks/useLinkAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,gCAAgC,EAAE,MAAM,gBAAgB,CAAA;AAMjE,MAAM,UAAU,cAAc,CAC5B,kBAOI,EAAE;IAEN,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,mBAAmB,EAAE,GAAG,eAAe,CAAA;IAE9E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACnD,UAAU,EAAE,KAAK,EACf,+BAAgE,EAChE,EAAE;YACF,IAAI,+BAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtD,IAAI,CAAC,aAAa,EAAE,SAAS,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;gBAC3C,CAAC;gBAED,MAAM,gBAAgB,GAAG,MAAM,gCAAgC,CAC7D,aAAa,CAAC,SAAS,CACxB,CAAA;gBAED,0BAA0B;gBAC1B,IAAI,gBAAgB,EAAE,CAAC;oBACrB,OAAO,aAAa,CAAC,WAAW,CAAC;wBAC/B,GAAG,+BAA+B;wBAClC,gBAAgB;qBACjB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YAED,uEAAuE;YACvE,OAAO,aAAa,CAAC,WAAW,CAAC,+BAA+B,CAAC,CAAA;QACnE,CAAC;QACD,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;YACtC,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC5D,IAAI,eAAe;gBAAE,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;QACD,GAAG,mBAAmB;KACvB,CAAC,CAAA;IAEF,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to refresh the passport using query invalidation mechanism.
|
|
3
|
+
* By calling the refresh function, the latest data will be refetched as soon as possible.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const { refreshCurrentAccount, refreshUsdConversion } = useRefreshPassport()
|
|
7
|
+
*
|
|
8
|
+
* // Call this function to refresh the current account
|
|
9
|
+
* const handlerefreshCurrentAccount = async () => {
|
|
10
|
+
* await refreshCurrentAccount()
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
export declare function useRefreshPassport(): {
|
|
14
|
+
refreshCurrentAccount: () => Promise<void>;
|
|
15
|
+
refreshUsdConversion: () => Promise<void>;
|
|
16
|
+
refreshBorrowData: () => Promise<void>;
|
|
17
|
+
refreshTokensBalances: () => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=useRefreshPassport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRefreshPassport.d.ts","sourceRoot":"","sources":["../../../src/hooks/useRefreshPassport.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB;;;;;EAoCjC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { useAccount, useBalance } from "wagmi";
|
|
4
|
+
import { QUERY_KEYS } from "./constants";
|
|
5
|
+
import { useInvalidateBorrowData } from "./useBorrowData";
|
|
6
|
+
import { useInvalidateTokensBalances } from "./useTokensBalances";
|
|
7
|
+
/**
|
|
8
|
+
* Hook to refresh the passport using query invalidation mechanism.
|
|
9
|
+
* By calling the refresh function, the latest data will be refetched as soon as possible.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const { refreshCurrentAccount, refreshUsdConversion } = useRefreshPassport()
|
|
13
|
+
*
|
|
14
|
+
* // Call this function to refresh the current account
|
|
15
|
+
* const handlerefreshCurrentAccount = async () => {
|
|
16
|
+
* await refreshCurrentAccount()
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export function useRefreshPassport() {
|
|
20
|
+
const { address } = useAccount();
|
|
21
|
+
const queryClient = useQueryClient();
|
|
22
|
+
const { invalidateBorrowData } = useInvalidateBorrowData();
|
|
23
|
+
const { invalidateTokensBalances } = useInvalidateTokensBalances();
|
|
24
|
+
const { queryKey: nativeTokenQueryKey } = useBalance({ address });
|
|
25
|
+
const refreshCurrentAccount = useCallback(() => queryClient.invalidateQueries({
|
|
26
|
+
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
27
|
+
}), [queryClient]);
|
|
28
|
+
const refreshUsdConversion = useCallback(() => queryClient.invalidateQueries({
|
|
29
|
+
queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
|
|
30
|
+
}), [queryClient]);
|
|
31
|
+
const refreshTokensBalances = useCallback(async () => {
|
|
32
|
+
await queryClient.invalidateQueries({
|
|
33
|
+
queryKey: nativeTokenQueryKey,
|
|
34
|
+
});
|
|
35
|
+
await invalidateTokensBalances();
|
|
36
|
+
}, [queryClient, nativeTokenQueryKey, invalidateTokensBalances]);
|
|
37
|
+
return {
|
|
38
|
+
refreshCurrentAccount,
|
|
39
|
+
refreshUsdConversion,
|
|
40
|
+
refreshBorrowData: invalidateBorrowData,
|
|
41
|
+
refreshTokensBalances,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=useRefreshPassport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRefreshPassport.js","sourceRoot":"","sources":["../../../src/hooks/useRefreshPassport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAEjE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,CAAA;IAChC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,EAAE,oBAAoB,EAAE,GAAG,uBAAuB,EAAE,CAAA;IAC1D,MAAM,EAAE,wBAAwB,EAAE,GAAG,2BAA2B,EAAE,CAAA;IAClE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,GAAG,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IAEjE,MAAM,qBAAqB,GAAG,WAAW,CACvC,GAAG,EAAE,CACH,WAAW,CAAC,iBAAiB,CAAC;QAC5B,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;KACnD,CAAC,EACJ,CAAC,WAAW,CAAC,CACd,CAAA;IAED,MAAM,oBAAoB,GAAG,WAAW,CACtC,GAAG,EAAE,CACH,WAAW,CAAC,iBAAiB,CAAC;QAC5B,QAAQ,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC;KAC7C,CAAC,EACJ,CAAC,WAAW,CAAC,CACd,CAAA;IAED,MAAM,qBAAqB,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACnD,MAAM,WAAW,CAAC,iBAAiB,CAAC;YAClC,QAAQ,EAAE,mBAAmB;SAC9B,CAAC,CAAA;QACF,MAAM,wBAAwB,EAAE,CAAA;IAClC,CAAC,EAAE,CAAC,WAAW,EAAE,mBAAmB,EAAE,wBAAwB,CAAC,CAAC,CAAA;IAEhE,OAAO;QACL,qBAAqB;QACrB,oBAAoB;QACpB,iBAAiB,EAAE,oBAAoB;QACvC,qBAAqB;KACtB,CAAA;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MutationOptions } from "@tanstack/react-query";
|
|
1
|
+
import { DefaultError, MutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import type { Session } from "../api";
|
|
3
|
-
declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Session>, "mutationFn" | "mutationKey">): {
|
|
3
|
+
declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Session, DefaultError, number | void>, "mutationFn" | "mutationKey">): {
|
|
4
4
|
data: undefined;
|
|
5
5
|
variables: undefined;
|
|
6
6
|
error: null;
|
|
@@ -15,11 +15,11 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
15
15
|
failureReason: Error | null;
|
|
16
16
|
isPaused: boolean;
|
|
17
17
|
submittedAt: number;
|
|
18
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
19
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
18
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
19
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
20
20
|
} | {
|
|
21
21
|
data: undefined;
|
|
22
|
-
variables: void;
|
|
22
|
+
variables: number | void | undefined;
|
|
23
23
|
error: null;
|
|
24
24
|
isError: false;
|
|
25
25
|
isIdle: false;
|
|
@@ -32,12 +32,12 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
32
32
|
failureReason: Error | null;
|
|
33
33
|
isPaused: boolean;
|
|
34
34
|
submittedAt: number;
|
|
35
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
36
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
35
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
36
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
37
37
|
} | {
|
|
38
38
|
data: undefined;
|
|
39
39
|
error: Error;
|
|
40
|
-
variables: void;
|
|
40
|
+
variables: number | void | undefined;
|
|
41
41
|
isError: true;
|
|
42
42
|
isIdle: false;
|
|
43
43
|
isPending: false;
|
|
@@ -49,12 +49,12 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
49
49
|
failureReason: Error | null;
|
|
50
50
|
isPaused: boolean;
|
|
51
51
|
submittedAt: number;
|
|
52
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
53
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
52
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
53
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
54
54
|
} | {
|
|
55
55
|
data: Session;
|
|
56
56
|
error: null;
|
|
57
|
-
variables: void;
|
|
57
|
+
variables: number | void | undefined;
|
|
58
58
|
isError: false;
|
|
59
59
|
isIdle: false;
|
|
60
60
|
isPending: false;
|
|
@@ -66,8 +66,8 @@ declare function useSignInWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
66
66
|
failureReason: Error | null;
|
|
67
67
|
isPaused: boolean;
|
|
68
68
|
submittedAt: number;
|
|
69
|
-
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
70
|
-
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
69
|
+
signInWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
70
|
+
signInWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
71
71
|
};
|
|
72
72
|
export { useSignInWithWallet };
|
|
73
73
|
//# sourceMappingURL=useSignInWithWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignInWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignInWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"useSignInWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignInWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,iBAAS,mBAAmB,CAC1B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,EACrD,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUP;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MutationOptions } from "@tanstack/react-query";
|
|
1
|
+
import { DefaultError, MutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import type { Session } from "../api";
|
|
3
|
-
declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Session>, "mutationFn" | "mutationKey">): {
|
|
3
|
+
declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Session, DefaultError, number | void>, "mutationFn" | "mutationKey">): {
|
|
4
4
|
data: undefined;
|
|
5
5
|
variables: undefined;
|
|
6
6
|
error: null;
|
|
@@ -15,11 +15,11 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
15
15
|
failureReason: Error | null;
|
|
16
16
|
isPaused: boolean;
|
|
17
17
|
submittedAt: number;
|
|
18
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
19
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
18
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
19
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
20
20
|
} | {
|
|
21
21
|
data: undefined;
|
|
22
|
-
variables: void;
|
|
22
|
+
variables: number | void | undefined;
|
|
23
23
|
error: null;
|
|
24
24
|
isError: false;
|
|
25
25
|
isIdle: false;
|
|
@@ -32,12 +32,12 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
32
32
|
failureReason: Error | null;
|
|
33
33
|
isPaused: boolean;
|
|
34
34
|
submittedAt: number;
|
|
35
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
36
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
35
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
36
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
37
37
|
} | {
|
|
38
38
|
data: undefined;
|
|
39
39
|
error: Error;
|
|
40
|
-
variables: void;
|
|
40
|
+
variables: number | void | undefined;
|
|
41
41
|
isError: true;
|
|
42
42
|
isIdle: false;
|
|
43
43
|
isPending: false;
|
|
@@ -49,12 +49,12 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
49
49
|
failureReason: Error | null;
|
|
50
50
|
isPaused: boolean;
|
|
51
51
|
submittedAt: number;
|
|
52
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
53
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
52
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
53
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
54
54
|
} | {
|
|
55
55
|
data: Session;
|
|
56
56
|
error: null;
|
|
57
|
-
variables: void;
|
|
57
|
+
variables: number | void | undefined;
|
|
58
58
|
isError: false;
|
|
59
59
|
isIdle: false;
|
|
60
60
|
isPending: false;
|
|
@@ -66,8 +66,8 @@ declare function useSignUpWithWallet(mutationOptions?: Omit<MutationOptions<Sess
|
|
|
66
66
|
failureReason: Error | null;
|
|
67
67
|
isPaused: boolean;
|
|
68
68
|
submittedAt: number;
|
|
69
|
-
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
|
|
70
|
-
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
|
|
69
|
+
signUpWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
|
|
70
|
+
signUpWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
|
|
71
71
|
};
|
|
72
72
|
export { useSignUpWithWallet };
|
|
73
73
|
//# sourceMappingURL=useSignUpWithWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignUpWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignUpWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"useSignUpWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignUpWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,iBAAS,mBAAmB,CAC1B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,EACrD,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUP;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
import { MezoChainToken } from "../lib/contracts";
|
|
3
|
+
export declare const BALANCE_OF_ABI: readonly [{
|
|
4
|
+
readonly inputs: readonly [{
|
|
5
|
+
readonly internalType: "address";
|
|
6
|
+
readonly name: "account";
|
|
7
|
+
readonly type: "address";
|
|
8
|
+
}];
|
|
9
|
+
readonly name: "balanceOf";
|
|
10
|
+
readonly outputs: readonly [{
|
|
11
|
+
readonly internalType: "uint256";
|
|
12
|
+
readonly name: "";
|
|
13
|
+
readonly type: "uint256";
|
|
14
|
+
}];
|
|
15
|
+
readonly stateMutability: "view";
|
|
16
|
+
readonly type: "function";
|
|
17
|
+
}];
|
|
18
|
+
type UseMezoChainTokensBalancesOptions<T extends MezoChainToken[]> = {
|
|
19
|
+
tokens?: T;
|
|
20
|
+
queryOptions?: Omit<UseQueryOptions<Record<T[number], TokenBalance>>, "queryKey" | "queryFn" | "select" | "enabled">;
|
|
21
|
+
};
|
|
22
|
+
export type TokenBalance = {
|
|
23
|
+
decimals: number;
|
|
24
|
+
formatted: string;
|
|
25
|
+
symbol: string;
|
|
26
|
+
value: bigint;
|
|
27
|
+
usd: {
|
|
28
|
+
value: bigint;
|
|
29
|
+
formatted: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Hook to get the balance of a list of tokens for the current account
|
|
34
|
+
* @param options.tokens The list of tokens to get the balance for. It will
|
|
35
|
+
* fallback to all tokens if not provided.
|
|
36
|
+
* @param options.queryOptions The query options to pass to the
|
|
37
|
+
* `useReadContracts`
|
|
38
|
+
* @returns Tanstack's `useQuery` returnings with balance of tokens for the
|
|
39
|
+
* current account in form of typesafe object with token names as keys
|
|
40
|
+
* and balances as values.
|
|
41
|
+
* @example
|
|
42
|
+
* const mezoTokensBalance = useTokensBalances({
|
|
43
|
+
* tokens: ["mT", "mxSolvBTC"],
|
|
44
|
+
* })
|
|
45
|
+
* // Assuming the status is "success"
|
|
46
|
+
* console.log(mezoTokensBalance.data.mT) // Eg. { value: 0n ... }
|
|
47
|
+
* console.log(Object.keys(mezoTokensBalance.data)) // ["mT", "mxSolvBTC"]
|
|
48
|
+
*/
|
|
49
|
+
export declare function useTokensBalances<T extends MezoChainToken[]>(options?: UseMezoChainTokensBalancesOptions<T>): import("@tanstack/react-query").UseQueryResult<Record<"BTC" | T[number], TokenBalance>, Error>;
|
|
50
|
+
/**
|
|
51
|
+
* Hook for invalidating current user's token balances. Can be used to
|
|
52
|
+
* invalidate the balances manually, which forces the data to be re-fetched.
|
|
53
|
+
* @returns Function `invalidateTokenBalances` that invalidates token balances
|
|
54
|
+
* @example
|
|
55
|
+
* const { invalidateTokenBalances } = useInvalidateTokensBalances()
|
|
56
|
+
* (...)
|
|
57
|
+
* await invalidateTokenBalances()
|
|
58
|
+
*/
|
|
59
|
+
export declare function useInvalidateTokensBalances(): {
|
|
60
|
+
invalidateTokensBalances: () => Promise<void>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Hook for resetting current user's token balances. Can be used to reset the
|
|
64
|
+
* balances manually, which forces the data to be re-fetched.
|
|
65
|
+
* @returns Function `resetTokenBalances` that invalidates token balances
|
|
66
|
+
* @example
|
|
67
|
+
* const { resetTokenBalances } = useResetTokensBalances()
|
|
68
|
+
* (...)
|
|
69
|
+
* await resetTokenBalances()
|
|
70
|
+
*/
|
|
71
|
+
export declare function useResetTokensBalances(): {
|
|
72
|
+
resetTokenBalances: () => Promise<void>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=useTokensBalances.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTokensBalances.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTokensBalances.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAEL,cAAc,EAEf,MAAM,kBAAkB,CAAA;AAkBzB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;EAoBH,CAAA;AAgBxB,KAAK,iCAAiC,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI;IACnE,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,YAAY,CAAC,EAAE,IAAI,CACjB,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,EAChD,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAC9C,CAAA;CACF,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAA;QACb,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAAE,EAC1D,OAAO,GAAE,iCAAiC,CAAC,CAAC,CAAM,kGAuHnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B;;EAS1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB;;EASrC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { useConfig } from "wagmi";
|
|
2
|
+
import { formatUnits } from "viem";
|
|
3
|
+
import { useQuery, useQueryClient, } from "@tanstack/react-query";
|
|
4
|
+
import { getBalance, readContracts } from "wagmi/actions";
|
|
5
|
+
import { mainnetTokenContracts, testnetTokenContracts, } from "../lib/contracts";
|
|
6
|
+
import useWalletAccount from "./useWalletAccount";
|
|
7
|
+
import { getAsset, isBitcoinLikeCryptoAsset, isTTokenCryptoAsset, } from "../utils/assets";
|
|
8
|
+
import { convertToUsd } from "../utils/currency";
|
|
9
|
+
import { CHAIN_ID } from "../constants";
|
|
10
|
+
import { useAssetsConversionRates } from "./useAssetsConversionRates";
|
|
11
|
+
import { normalizePrecision } from "../utils/numbers";
|
|
12
|
+
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
13
|
+
// support importing JSON as const yet so types cannot be inferred from the
|
|
14
|
+
// imported contract. As a workaround there is minimal ABI definition that can
|
|
15
|
+
// be asserted types from.
|
|
16
|
+
// Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
|
|
17
|
+
export const BALANCE_OF_ABI = [
|
|
18
|
+
{
|
|
19
|
+
inputs: [
|
|
20
|
+
{
|
|
21
|
+
internalType: "address",
|
|
22
|
+
name: "account",
|
|
23
|
+
type: "address",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
name: "balanceOf",
|
|
27
|
+
outputs: [
|
|
28
|
+
{
|
|
29
|
+
internalType: "uint256",
|
|
30
|
+
name: "",
|
|
31
|
+
type: "uint256",
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
stateMutability: "view",
|
|
35
|
+
type: "function",
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
const BALANCE_TOKENS = [
|
|
39
|
+
"mcbBTC",
|
|
40
|
+
"mDAI",
|
|
41
|
+
"mFBTC",
|
|
42
|
+
"mSolvBTC",
|
|
43
|
+
"mswBTC",
|
|
44
|
+
"mT",
|
|
45
|
+
"mUSDC",
|
|
46
|
+
"mUSDe",
|
|
47
|
+
"mUSDT",
|
|
48
|
+
"mxSolvBTC",
|
|
49
|
+
"MUSD",
|
|
50
|
+
];
|
|
51
|
+
const TOKEN_BALANCES_QUERY_KEY = "passport.tokenBalances";
|
|
52
|
+
/**
|
|
53
|
+
* Hook to get the balance of a list of tokens for the current account
|
|
54
|
+
* @param options.tokens The list of tokens to get the balance for. It will
|
|
55
|
+
* fallback to all tokens if not provided.
|
|
56
|
+
* @param options.queryOptions The query options to pass to the
|
|
57
|
+
* `useReadContracts`
|
|
58
|
+
* @returns Tanstack's `useQuery` returnings with balance of tokens for the
|
|
59
|
+
* current account in form of typesafe object with token names as keys
|
|
60
|
+
* and balances as values.
|
|
61
|
+
* @example
|
|
62
|
+
* const mezoTokensBalance = useTokensBalances({
|
|
63
|
+
* tokens: ["mT", "mxSolvBTC"],
|
|
64
|
+
* })
|
|
65
|
+
* // Assuming the status is "success"
|
|
66
|
+
* console.log(mezoTokensBalance.data.mT) // Eg. { value: 0n ... }
|
|
67
|
+
* console.log(Object.keys(mezoTokensBalance.data)) // ["mT", "mxSolvBTC"]
|
|
68
|
+
*/
|
|
69
|
+
export function useTokensBalances(options = {}) {
|
|
70
|
+
const { tokens = BALANCE_TOKENS, ...restQueryOptions } = options;
|
|
71
|
+
const walletAccount = useWalletAccount();
|
|
72
|
+
const config = useConfig();
|
|
73
|
+
const { data: conversionRatesData } = useAssetsConversionRates();
|
|
74
|
+
return useQuery({
|
|
75
|
+
queryKey: [
|
|
76
|
+
TOKEN_BALANCES_QUERY_KEY,
|
|
77
|
+
walletAccount?.accountAddress,
|
|
78
|
+
options.tokens,
|
|
79
|
+
],
|
|
80
|
+
enabled: !!walletAccount?.accountAddress && !!conversionRatesData,
|
|
81
|
+
queryFn: async () => {
|
|
82
|
+
const isMainnet = config.state.chainId === CHAIN_ID.mainnet;
|
|
83
|
+
const contractsMap = isMainnet
|
|
84
|
+
? mainnetTokenContracts
|
|
85
|
+
: testnetTokenContracts;
|
|
86
|
+
const accountAddress = walletAccount?.accountAddress;
|
|
87
|
+
if (!accountAddress) {
|
|
88
|
+
throw new Error("Account address is not available.");
|
|
89
|
+
}
|
|
90
|
+
const tokenContracts = tokens.map((token) => {
|
|
91
|
+
const { address } = contractsMap[token];
|
|
92
|
+
return {
|
|
93
|
+
address,
|
|
94
|
+
abi: BALANCE_OF_ABI,
|
|
95
|
+
functionName: "balanceOf",
|
|
96
|
+
args: [accountAddress],
|
|
97
|
+
chainId: config.state.chainId,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
return Promise.all([
|
|
101
|
+
getBalance(config, { address: accountAddress }),
|
|
102
|
+
readContracts(config, {
|
|
103
|
+
contracts: tokenContracts,
|
|
104
|
+
}),
|
|
105
|
+
]);
|
|
106
|
+
},
|
|
107
|
+
select: (data) => {
|
|
108
|
+
const [btcBalance, tokensBalancesData] = data;
|
|
109
|
+
if (!conversionRatesData) {
|
|
110
|
+
throw new Error("Conversion rates data is not available.");
|
|
111
|
+
}
|
|
112
|
+
const parsedBtcBalance = {
|
|
113
|
+
...btcBalance,
|
|
114
|
+
symbol: getAsset("BTC").symbol,
|
|
115
|
+
usd: convertToUsd(btcBalance.value, btcBalance.decimals, conversionRatesData.rates.BTC, conversionRatesData.decimals),
|
|
116
|
+
};
|
|
117
|
+
const parsedTokensBalances = tokensBalancesData.map((item, index) => {
|
|
118
|
+
const token = tokens[index];
|
|
119
|
+
const { decimals, symbol } = getAsset(token);
|
|
120
|
+
if (item.status === "failure") {
|
|
121
|
+
throw new Error(`Failed to fetch balance of ${token} for ${walletAccount?.accountAddress}.`);
|
|
122
|
+
}
|
|
123
|
+
const tokenBalance = {
|
|
124
|
+
value: item.result,
|
|
125
|
+
decimals,
|
|
126
|
+
symbol,
|
|
127
|
+
formatted: formatUnits(item.result, decimals),
|
|
128
|
+
};
|
|
129
|
+
let usd = {
|
|
130
|
+
value: normalizePrecision(tokenBalance.value, tokenBalance.decimals, conversionRatesData.decimals),
|
|
131
|
+
formatted: formatUnits(tokenBalance.value, tokenBalance.decimals),
|
|
132
|
+
};
|
|
133
|
+
if (isBitcoinLikeCryptoAsset(tokenBalance.symbol)) {
|
|
134
|
+
usd = convertToUsd(tokenBalance.value, tokenBalance.decimals, conversionRatesData.rates.BTC, conversionRatesData.decimals);
|
|
135
|
+
}
|
|
136
|
+
if (isTTokenCryptoAsset(tokenBalance.symbol)) {
|
|
137
|
+
usd = convertToUsd(tokenBalance.value, tokenBalance.decimals, conversionRatesData.rates.mT, conversionRatesData.decimals);
|
|
138
|
+
}
|
|
139
|
+
return { ...tokenBalance, usd };
|
|
140
|
+
});
|
|
141
|
+
return [parsedBtcBalance, ...parsedTokensBalances].reduce((acc, token) => ({
|
|
142
|
+
...acc,
|
|
143
|
+
[token.symbol]: token,
|
|
144
|
+
}), {});
|
|
145
|
+
},
|
|
146
|
+
...restQueryOptions,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Hook for invalidating current user's token balances. Can be used to
|
|
151
|
+
* invalidate the balances manually, which forces the data to be re-fetched.
|
|
152
|
+
* @returns Function `invalidateTokenBalances` that invalidates token balances
|
|
153
|
+
* @example
|
|
154
|
+
* const { invalidateTokenBalances } = useInvalidateTokensBalances()
|
|
155
|
+
* (...)
|
|
156
|
+
* await invalidateTokenBalances()
|
|
157
|
+
*/
|
|
158
|
+
export function useInvalidateTokensBalances() {
|
|
159
|
+
const queryClient = useQueryClient();
|
|
160
|
+
const invalidateTokensBalancesHandler = () => queryClient.invalidateQueries({ queryKey: [TOKEN_BALANCES_QUERY_KEY] });
|
|
161
|
+
return {
|
|
162
|
+
invalidateTokensBalances: invalidateTokensBalancesHandler,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Hook for resetting current user's token balances. Can be used to reset the
|
|
167
|
+
* balances manually, which forces the data to be re-fetched.
|
|
168
|
+
* @returns Function `resetTokenBalances` that invalidates token balances
|
|
169
|
+
* @example
|
|
170
|
+
* const { resetTokenBalances } = useResetTokensBalances()
|
|
171
|
+
* (...)
|
|
172
|
+
* await resetTokenBalances()
|
|
173
|
+
*/
|
|
174
|
+
export function useResetTokensBalances() {
|
|
175
|
+
const queryClient = useQueryClient();
|
|
176
|
+
const resetTokenBalancesHandler = () => queryClient.resetQueries({ queryKey: [TOKEN_BALANCES_QUERY_KEY] });
|
|
177
|
+
return {
|
|
178
|
+
resetTokenBalances: resetTokenBalancesHandler,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=useTokensBalances.js.map
|