@mezo-org/passport 0.4.0-dev.5 → 0.4.0-dev.51
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 +36 -59
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +22 -48
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +27 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +61 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/endpoint-error.d.ts +4 -0
- package/dist/src/api/endpoint-error.d.ts.map +1 -0
- package/dist/src/api/endpoint-error.js +6 -0
- package/dist/src/api/endpoint-error.js.map +1 -0
- package/dist/src/api/fetch-error copy.d.ts +5 -0
- package/dist/src/api/fetch-error copy.d.ts.map +1 -0
- package/dist/src/api/fetch-error copy.js +8 -0
- package/dist/src/api/fetch-error copy.js.map +1 -0
- package/dist/src/api/fetch-error.d.ts +5 -0
- package/dist/src/api/fetch-error.d.ts.map +1 -0
- package/dist/src/api/fetch-error.js +8 -0
- package/dist/src/api/fetch-error.js.map +1 -0
- package/dist/src/api/index.d.ts +3 -0
- package/dist/src/api/index.d.ts.map +1 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/api/portal.d.ts +26 -0
- package/dist/src/api/portal.d.ts.map +1 -0
- package/dist/src/api/portal.js +26 -0
- package/dist/src/api/portal.js.map +1 -0
- package/dist/src/assets/DefaultAvatar.d.ts +5 -0
- package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
- package/dist/src/assets/DefaultAvatar.js +21 -0
- package/dist/src/assets/DefaultAvatar.js.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +8 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +23 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +27 -0
- package/dist/src/components/Dropdown/Content.js.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts +27 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +68 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +34 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +57 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +64 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +44 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.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/components/Dropdown/index.d.ts +3 -0
- package/dist/src/components/Dropdown/index.d.ts.map +1 -0
- package/dist/src/components/Dropdown/index.js +2 -0
- package/dist/src/components/Dropdown/index.js.map +1 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +2 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/config.d.ts +17 -5
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +51 -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/constants.d.ts +1 -0
- package/dist/src/hooks/constants.d.ts.map +1 -1
- package/dist/src/hooks/constants.js +1 -0
- package/dist/src/hooks/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +3 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +3 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +89 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
- package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +12 -102
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +28 -17
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBitcoinPriceConversion copy.d.ts +2 -0
- package/dist/src/hooks/useBitcoinPriceConversion copy.d.ts.map +1 -0
- package/dist/src/hooks/useBitcoinPriceConversion copy.js +43 -0
- package/dist/src/hooks/useBitcoinPriceConversion copy.js.map +1 -0
- package/dist/src/hooks/useBitcoinPriceConversion.d.ts +103 -0
- package/dist/src/hooks/useBitcoinPriceConversion.d.ts.map +1 -0
- package/dist/src/hooks/useBitcoinPriceConversion.js +50 -0
- package/dist/src/hooks/useBitcoinPriceConversion.js.map +1 -0
- package/dist/src/hooks/useBitcoinPriceFeed.d.ts +15 -0
- package/dist/src/hooks/useBitcoinPriceFeed.d.ts.map +1 -0
- package/dist/src/hooks/useBitcoinPriceFeed.js +67 -0
- package/dist/src/hooks/useBitcoinPriceFeed.js.map +1 -0
- package/dist/src/hooks/useBorrowData.d.ts +60 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +122 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts +23 -173
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +7 -4
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useCreateSession.d.ts +12 -101
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
- package/dist/src/hooks/useCreateSession.js +10 -8
- package/dist/src/hooks/useCreateSession.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +47 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +99 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useGetAccountByAddress.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts +16 -2
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +25 -3
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/hooks/useGetSession.d.ts +1 -1
- package/dist/src/hooks/useGetSession.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +15 -175
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +7 -4
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
- package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
- package/dist/src/hooks/usePortalApiClient.js +6 -0
- package/dist/src/hooks/usePortalApiClient.js.map +1 -0
- 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/useSignInWithDiscord.d.ts +12 -100
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithDiscord.js +6 -3
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +12 -100
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.js +2 -2
- package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
- package/dist/src/hooks/useSignOut.d.ts +12 -28
- package/dist/src/hooks/useSignOut.d.ts.map +1 -1
- package/dist/src/hooks/useSignOut.js +7 -4
- package/dist/src/hooks/useSignOut.js.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +12 -100
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.js +2 -2
- package/dist/src/hooks/useSignUpWithWallet.js.map +1 -1
- package/dist/src/hooks/useTokensBalances.d.ts +74 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +140 -0
- package/dist/src/hooks/useTokensBalances.js.map +1 -0
- package/dist/src/hooks/useUpdateMezoId.d.ts +30 -136
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useUpdateMezoId.js +7 -4
- package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
- package/dist/src/hooks/useWalletAccount.d.ts +13 -0
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
- package/dist/src/hooks/useWalletAccount.js +29 -0
- package/dist/src/hooks/useWalletAccount.js.map +1 -0
- 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 +58 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/lib/contracts/price-oracle.d.ts +43 -0
- package/dist/src/lib/contracts/price-oracle.d.ts.map +1 -0
- package/dist/src/lib/contracts/price-oracle.js +52 -0
- package/dist/src/lib/contracts/price-oracle.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 +10 -13
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +11 -20
- 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 +15 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +37 -0
- package/dist/src/utils/address.js.map +1 -0
- package/dist/src/utils/address.test.d.ts +2 -0
- package/dist/src/utils/address.test.d.ts.map +1 -0
- package/dist/src/utils/address.test.js +40 -0
- package/dist/src/utils/address.test.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +44 -0
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.js +132 -0
- package/dist/src/utils/cryptoAssets.js.map +1 -0
- package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
- package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.test.js +67 -0
- package/dist/src/utils/cryptoAssets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +14 -0
- package/dist/src/utils/currency.d.ts.map +1 -0
- package/dist/src/utils/currency.js +27 -0
- package/dist/src/utils/currency.js.map +1 -0
- package/dist/src/utils/currency.test.d.ts +2 -0
- package/dist/src/utils/currency.test.d.ts.map +1 -0
- package/dist/src/utils/currency.test.js +34 -0
- package/dist/src/utils/currency.test.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +58 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +132 -0
- package/dist/src/utils/numbers.js.map +1 -0
- package/dist/src/utils/numbers.test.d.ts +2 -0
- package/dist/src/utils/numbers.test.d.ts.map +1 -0
- package/dist/src/utils/numbers.test.js +170 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/package.json +14 -8
- package/src/api/auth.ts +73 -128
- package/src/api/client.ts +87 -0
- package/src/api/fetch-error.ts +8 -0
- package/src/api/index.ts +2 -0
- package/src/api/portal.ts +53 -0
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
- package/src/components/Dropdown/Content.tsx +98 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +148 -0
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +41 -0
- package/src/components/Dropdown/Receive/Receive.tsx +119 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
- package/src/components/Dropdown/Root/Root.tsx +147 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +91 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/config.ts +77 -20
- package/src/constants.ts +12 -4
- package/src/hooks/constants.ts +1 -0
- package/src/hooks/index.ts +6 -1
- package/src/hooks/useAssetsConversionRates.ts +96 -0
- package/src/hooks/useAuthenticateWithWallet.ts +44 -23
- package/src/hooks/useBorrowData.ts +143 -0
- package/src/hooks/useCreateAccount.ts +19 -5
- package/src/hooks/useCreateSession.ts +22 -9
- package/src/hooks/useDropdownData.ts +149 -0
- package/src/hooks/useGetAccountByAddress.ts +2 -2
- package/src/hooks/useGetAccountByMezoId.ts +2 -2
- package/src/hooks/useGetCurrentAccount.ts +46 -6
- package/src/hooks/useGetSession.ts +1 -1
- package/src/hooks/useLinkAccount.ts +18 -5
- package/src/hooks/usePortalApiClient.ts +6 -0
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useSignInWithDiscord.ts +14 -5
- package/src/hooks/useSignInWithWallet.ts +9 -2
- package/src/hooks/useSignOut.ts +18 -4
- package/src/hooks/useSignUpWithWallet.ts +9 -2
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useUpdateMezoId.ts +19 -4
- package/src/hooks/useWalletAccount.ts +55 -0
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +12 -1
- package/src/lib/contracts/index.ts +90 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +30 -37
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +48 -0
- package/src/utils/address.ts +45 -0
- package/src/utils/cryptoAssets.test.ts +79 -0
- package/src/utils/cryptoAssets.ts +173 -0
- package/src/utils/currency.test.ts +38 -0
- package/src/utils/currency.ts +32 -0
- package/src/utils/numbers.test.ts +220 -0
- package/src/utils/numbers.ts +188 -0
|
@@ -1,20 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
|
-
import { QUERY_KEYS } from "./constants"
|
|
1
|
+
import { UseBaseQueryOptions, useQuery } from "@tanstack/react-query"
|
|
4
2
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
-
import {
|
|
3
|
+
import { QUERY_KEYS } from "./constants"
|
|
4
|
+
import { useAuthApiClient } from "./useAuthApiClient"
|
|
5
|
+
import { usePortalApiClient } from "./usePortalApiClient"
|
|
6
|
+
import type { GetCurrentAccountResponse } from "../api"
|
|
7
|
+
|
|
8
|
+
type GetCurrentAccountResponseWithMats = GetCurrentAccountResponse & {
|
|
9
|
+
mats: {
|
|
10
|
+
totalMats: number
|
|
11
|
+
}
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
export function useGetCurrentAccount(
|
|
8
15
|
queryOptions: Omit<
|
|
9
|
-
UseBaseQueryOptions<
|
|
16
|
+
UseBaseQueryOptions<GetCurrentAccountResponseWithMats>,
|
|
10
17
|
"queryKey" | "queryFn"
|
|
11
18
|
> = {},
|
|
12
19
|
) {
|
|
13
20
|
const authApiClient = useAuthApiClient()
|
|
21
|
+
const portalApiClient = usePortalApiClient()
|
|
14
22
|
|
|
15
23
|
return useQuery({
|
|
16
24
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
17
|
-
queryFn: () =>
|
|
25
|
+
queryFn: async () => {
|
|
26
|
+
const currentAccount = await authApiClient.getCurrentAccount()
|
|
27
|
+
const linkedWallets = currentAccount?.linkedAccounts?.filter(
|
|
28
|
+
(account) => account.type === "wallet",
|
|
29
|
+
)
|
|
30
|
+
if (!linkedWallets || linkedWallets.length === 0) {
|
|
31
|
+
return {
|
|
32
|
+
...currentAccount,
|
|
33
|
+
mats: {
|
|
34
|
+
totalMats: 0,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const addresses = linkedWallets.map(
|
|
40
|
+
(account) => account.btcAddress || account.evmAddress,
|
|
41
|
+
)
|
|
42
|
+
const mats = await Promise.all(
|
|
43
|
+
addresses.map((address) => portalApiClient.getPortalMats(address)),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const totalMats = mats.reduce(
|
|
47
|
+
(sumMats, currentMats) => sumMats + currentMats.totalMats,
|
|
48
|
+
0,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...currentAccount,
|
|
53
|
+
mats: {
|
|
54
|
+
totalMats,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
},
|
|
18
58
|
staleTime: ONE_MINUTE_MS,
|
|
19
59
|
retry: 1,
|
|
20
60
|
...queryOptions,
|
|
@@ -2,7 +2,7 @@ import { useQuery, UseBaseQueryOptions } from "@tanstack/react-query"
|
|
|
2
2
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
3
|
import { QUERY_KEYS } from "./constants"
|
|
4
4
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
-
import { GetSessionResponse } from "../api
|
|
5
|
+
import type { GetSessionResponse } from "../api"
|
|
6
6
|
|
|
7
7
|
export function useGetSession(
|
|
8
8
|
code?: string,
|
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useQueryClient,
|
|
3
|
+
useMutation,
|
|
4
|
+
MutationOptions,
|
|
5
|
+
DefaultError,
|
|
6
|
+
} from "@tanstack/react-query"
|
|
2
7
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
|
-
import { LinkAccountRequest } from "../api
|
|
8
|
+
import type { LinkAccountRequest, LinkAccountResponse } from "../api"
|
|
4
9
|
import { QUERY_KEYS } from "./constants"
|
|
5
10
|
|
|
6
|
-
export function useLinkAccount(
|
|
11
|
+
export function useLinkAccount(
|
|
12
|
+
mutationOptions: Omit<
|
|
13
|
+
MutationOptions<LinkAccountResponse, DefaultError, LinkAccountRequest>,
|
|
14
|
+
"mutationFn" | "mutationKey"
|
|
15
|
+
> = {},
|
|
16
|
+
) {
|
|
7
17
|
const queryClient = useQueryClient()
|
|
8
18
|
const authApiClient = useAuthApiClient()
|
|
9
19
|
|
|
20
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
21
|
+
|
|
10
22
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
11
23
|
mutationFn: (linkAccountRequest: LinkAccountRequest) =>
|
|
12
24
|
authApiClient.linkAccount(linkAccountRequest),
|
|
13
|
-
onSuccess: () => {
|
|
25
|
+
onSuccess: (data, variables, context) => {
|
|
14
26
|
queryClient.resetQueries({ queryKey: [QUERY_KEYS.ACCOUNT] })
|
|
27
|
+
if (customOnSuccess) customOnSuccess(data, variables, context)
|
|
15
28
|
},
|
|
16
|
-
...
|
|
29
|
+
...restMutationOptions,
|
|
17
30
|
})
|
|
18
31
|
|
|
19
32
|
return { linkAccount: mutate, linkAccountAsync: mutateAsync, ...rest }
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Hook to refresh the passport using query invalidation mechanism.
|
|
10
|
+
* By calling the refresh function, the latest data will be refetched as soon as possible.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { refreshCurrentAccount, refreshUsdConversion } = useRefreshPassport()
|
|
14
|
+
*
|
|
15
|
+
* // Call this function to refresh the current account
|
|
16
|
+
* const handlerefreshCurrentAccount = async () => {
|
|
17
|
+
* await refreshCurrentAccount()
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
export function useRefreshPassport() {
|
|
21
|
+
const { address } = useAccount()
|
|
22
|
+
const queryClient = useQueryClient()
|
|
23
|
+
const { invalidateBorrowData } = useInvalidateBorrowData()
|
|
24
|
+
const { invalidateTokensBalances } = useInvalidateTokensBalances()
|
|
25
|
+
const { queryKey: nativeTokenQueryKey } = useBalance({ address })
|
|
26
|
+
|
|
27
|
+
const refreshCurrentAccount = useCallback(
|
|
28
|
+
() =>
|
|
29
|
+
queryClient.invalidateQueries({
|
|
30
|
+
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
31
|
+
}),
|
|
32
|
+
[queryClient],
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const refreshUsdConversion = useCallback(
|
|
36
|
+
() =>
|
|
37
|
+
queryClient.invalidateQueries({
|
|
38
|
+
queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
|
|
39
|
+
}),
|
|
40
|
+
[queryClient],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const refreshTokensBalances = useCallback(async () => {
|
|
44
|
+
await queryClient.invalidateQueries({
|
|
45
|
+
queryKey: nativeTokenQueryKey,
|
|
46
|
+
})
|
|
47
|
+
await invalidateTokensBalances()
|
|
48
|
+
}, [queryClient, nativeTokenQueryKey, invalidateTokensBalances])
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
refreshCurrentAccount,
|
|
52
|
+
refreshUsdConversion,
|
|
53
|
+
refreshBorrowData: invalidateBorrowData,
|
|
54
|
+
refreshTokensBalances,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import { useMutation } from "@tanstack/react-query"
|
|
1
|
+
import { MutationOptions, useMutation } from "@tanstack/react-query"
|
|
2
2
|
import { useCreateSession } from "./useCreateSession"
|
|
3
3
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
4
|
+
import type { AuthenticationProviderRedirectResponse } from "../api"
|
|
4
5
|
|
|
5
|
-
function useSignInWithDiscord(
|
|
6
|
+
function useSignInWithDiscord(
|
|
7
|
+
mutationOptions: Omit<
|
|
8
|
+
MutationOptions<AuthenticationProviderRedirectResponse>,
|
|
9
|
+
"mutationFn" | "mutationKey"
|
|
10
|
+
> = {},
|
|
11
|
+
) {
|
|
6
12
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
|
|
7
13
|
const { createSessionAsync } = useCreateSession()
|
|
8
14
|
|
|
9
15
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
10
|
-
mutationFn: async () => {
|
|
16
|
+
mutationFn: async (): Promise<AuthenticationProviderRedirectResponse> => {
|
|
11
17
|
await ensureNoSessionAndFetchNonce()
|
|
12
18
|
|
|
13
|
-
return createSessionAsync({
|
|
19
|
+
return (await createSessionAsync({
|
|
14
20
|
type: "discord",
|
|
15
|
-
})
|
|
21
|
+
})) as AuthenticationProviderRedirectResponse
|
|
22
|
+
// ^ By passing type: "discord" we know for sure the return type is
|
|
23
|
+
// AuthenticationProviderRedirectResponse
|
|
16
24
|
},
|
|
25
|
+
...mutationOptions,
|
|
17
26
|
})
|
|
18
27
|
|
|
19
28
|
return {
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { MutationOptions } from "@tanstack/react-query"
|
|
1
2
|
import { useAuthenticateWithWallet } from "./useAuthenticateWithWallet"
|
|
3
|
+
import type { Session } from "../api"
|
|
2
4
|
|
|
3
|
-
function useSignInWithWallet(
|
|
5
|
+
function useSignInWithWallet(
|
|
6
|
+
mutationOptions: Omit<
|
|
7
|
+
MutationOptions<Session>,
|
|
8
|
+
"mutationFn" | "mutationKey"
|
|
9
|
+
> = {},
|
|
10
|
+
) {
|
|
4
11
|
const { authenticateWithWallet, authenticateWithWalletAsync, ...rest } =
|
|
5
|
-
useAuthenticateWithWallet()
|
|
12
|
+
useAuthenticateWithWallet(false, mutationOptions)
|
|
6
13
|
|
|
7
14
|
return {
|
|
8
15
|
signInWithWallet: authenticateWithWallet,
|
package/src/hooks/useSignOut.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
MutationOptions,
|
|
3
|
+
useMutation,
|
|
4
|
+
useQueryClient,
|
|
5
|
+
} from "@tanstack/react-query"
|
|
2
6
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
7
|
import { QUERY_KEYS } from "./constants"
|
|
8
|
+
import type { DeleteSessionResponse } from "../api"
|
|
4
9
|
|
|
5
|
-
export function useSignOut(
|
|
10
|
+
export function useSignOut(
|
|
11
|
+
mutationOptions: Omit<
|
|
12
|
+
MutationOptions<DeleteSessionResponse>,
|
|
13
|
+
"mutationFn" | "mutationKey"
|
|
14
|
+
> = {},
|
|
15
|
+
) {
|
|
6
16
|
const queryClient = useQueryClient()
|
|
7
17
|
const authApiClient = useAuthApiClient()
|
|
8
18
|
|
|
19
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
20
|
+
|
|
9
21
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
10
22
|
mutationFn: () => authApiClient.deleteSession(),
|
|
11
|
-
onSuccess: () => {
|
|
23
|
+
onSuccess: (data, variables, context) => {
|
|
12
24
|
queryClient.resetQueries({ queryKey: [QUERY_KEYS.SESSION] })
|
|
13
25
|
queryClient.resetQueries({
|
|
14
26
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
15
27
|
})
|
|
28
|
+
|
|
29
|
+
if (customOnSuccess) customOnSuccess(data, variables, context)
|
|
16
30
|
},
|
|
17
|
-
...
|
|
31
|
+
...restMutationOptions,
|
|
18
32
|
})
|
|
19
33
|
|
|
20
34
|
return { signOut: mutate, signOutAsync: mutateAsync, ...rest }
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { MutationOptions } from "@tanstack/react-query"
|
|
1
2
|
import { useAuthenticateWithWallet } from "./useAuthenticateWithWallet"
|
|
3
|
+
import type { Session } from "../api"
|
|
2
4
|
|
|
3
|
-
function useSignUpWithWallet(
|
|
5
|
+
function useSignUpWithWallet(
|
|
6
|
+
mutationOptions: Omit<
|
|
7
|
+
MutationOptions<Session>,
|
|
8
|
+
"mutationFn" | "mutationKey"
|
|
9
|
+
> = {},
|
|
10
|
+
) {
|
|
4
11
|
const { authenticateWithWallet, authenticateWithWalletAsync, ...rest } =
|
|
5
|
-
useAuthenticateWithWallet(
|
|
12
|
+
useAuthenticateWithWallet(true, mutationOptions)
|
|
6
13
|
|
|
7
14
|
return {
|
|
8
15
|
signUpWithWallet: authenticateWithWallet,
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { useReadContracts } from "wagmi"
|
|
2
|
+
import { useCallback, useMemo } from "react"
|
|
3
|
+
import { Abi } from "viem"
|
|
4
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
5
|
+
import { usePassportContext } from "./usePassportContext"
|
|
6
|
+
import {
|
|
7
|
+
mainnetTokenContracts,
|
|
8
|
+
testnetTokenContracts,
|
|
9
|
+
MezoChainToken,
|
|
10
|
+
} from "../lib/contracts"
|
|
11
|
+
import useWalletAccount from "./useWalletAccount"
|
|
12
|
+
import { CHAIN_ID } from "../constants"
|
|
13
|
+
|
|
14
|
+
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
15
|
+
// support importing JSON as const yet so types cannot be inferred from the
|
|
16
|
+
// imported contract. As a workaround there is minimal ABI definition that can
|
|
17
|
+
// be asserted types from.
|
|
18
|
+
// Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
|
|
19
|
+
|
|
20
|
+
const BALANCE_OF_ABI = [
|
|
21
|
+
{
|
|
22
|
+
inputs: [
|
|
23
|
+
{
|
|
24
|
+
internalType: "address",
|
|
25
|
+
name: "account",
|
|
26
|
+
type: "address",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
name: "balanceOf",
|
|
30
|
+
outputs: [
|
|
31
|
+
{
|
|
32
|
+
internalType: "uint256",
|
|
33
|
+
name: "",
|
|
34
|
+
type: "uint256",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
stateMutability: "view",
|
|
38
|
+
type: "function",
|
|
39
|
+
},
|
|
40
|
+
] as const satisfies Abi
|
|
41
|
+
|
|
42
|
+
const BALANCE_TOKENS: MezoChainToken[] = [
|
|
43
|
+
"mcbBTC",
|
|
44
|
+
"mDAI",
|
|
45
|
+
"mFBTC",
|
|
46
|
+
"mSolvBTC",
|
|
47
|
+
"mswBTC",
|
|
48
|
+
"mT",
|
|
49
|
+
"mUSDC",
|
|
50
|
+
"mUSDe",
|
|
51
|
+
"mUSDT",
|
|
52
|
+
"mxSolvBTC",
|
|
53
|
+
"MUSD",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
type UseMezoChainTokensBalancesOptions<T> = {
|
|
57
|
+
tokens?: T
|
|
58
|
+
queryOptions?: object
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Hook to get the balance of a list of tokens for the current account
|
|
63
|
+
* @param options.tokens The list of tokens to get the balance for. It will
|
|
64
|
+
* fallback to all tokens if not provided.
|
|
65
|
+
* @param options.queryOptions The query options to pass to the
|
|
66
|
+
* `useReadContracts`
|
|
67
|
+
* @returns Tanstack's `useQuery` returnings with balance of tokens for the
|
|
68
|
+
* current account in form of typesafe object with token names as keys
|
|
69
|
+
* and balances as values.
|
|
70
|
+
* @dev In case of error data fallbacks to `0n`. To determine if an error
|
|
71
|
+
* occurred, check the `isError` property.
|
|
72
|
+
* @example
|
|
73
|
+
* const mezoTokensBalance = useTokensBalances({
|
|
74
|
+
* tokens: ["mT", "mxSolvBTC"],
|
|
75
|
+
* })
|
|
76
|
+
* console.log(mezoTokensBalance?.data.mT) // Eg. 0n
|
|
77
|
+
* console.log(Object.keys(mezoTokensBalance?.data)) // ["mT", "mxSolvBTC"]
|
|
78
|
+
*/
|
|
79
|
+
export function useTokensBalances<T extends MezoChainToken[]>(
|
|
80
|
+
options: UseMezoChainTokensBalancesOptions<T> = {},
|
|
81
|
+
) {
|
|
82
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
83
|
+
|
|
84
|
+
const { accountAddress } = useWalletAccount()
|
|
85
|
+
|
|
86
|
+
const contractsMap = useMemo(() => {
|
|
87
|
+
const contracts =
|
|
88
|
+
environment === "mainnet" ? mainnetTokenContracts : testnetTokenContracts
|
|
89
|
+
|
|
90
|
+
const tokenContracts = Object.fromEntries(
|
|
91
|
+
Object.entries(contracts).filter(([key]) =>
|
|
92
|
+
BALANCE_TOKENS.includes(key as MezoChainToken),
|
|
93
|
+
),
|
|
94
|
+
) as typeof contracts
|
|
95
|
+
|
|
96
|
+
return tokenContracts
|
|
97
|
+
}, [environment])
|
|
98
|
+
|
|
99
|
+
const { tokens = Object.keys(contractsMap) as T, queryOptions = {} } = options
|
|
100
|
+
|
|
101
|
+
const contracts = useMemo(() => {
|
|
102
|
+
if (!accountAddress) return []
|
|
103
|
+
|
|
104
|
+
return tokens.map((token) => {
|
|
105
|
+
const { address } = contractsMap[token]
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
address,
|
|
109
|
+
abi: BALANCE_OF_ABI,
|
|
110
|
+
functionName: "balanceOf",
|
|
111
|
+
args: [accountAddress],
|
|
112
|
+
chainId: CHAIN_ID[environment],
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
}, [accountAddress, tokens, contractsMap, environment])
|
|
116
|
+
|
|
117
|
+
return useReadContracts({
|
|
118
|
+
contracts,
|
|
119
|
+
query: {
|
|
120
|
+
select: (data) =>
|
|
121
|
+
data.reduce(
|
|
122
|
+
(acc, item) => {
|
|
123
|
+
const token = tokens[data.indexOf(item)]
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
...acc,
|
|
127
|
+
[token]: item.result ?? 0n,
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{} as Record<T[number], bigint>,
|
|
131
|
+
),
|
|
132
|
+
...queryOptions,
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Hook for invalidating current user's token balances. Can be used to
|
|
139
|
+
* invalidate the balances manually, which forces the data to be re-fetched.
|
|
140
|
+
* @param tokens The list of tokens (as string arrays) for which we want to
|
|
141
|
+
* invalidate query for.
|
|
142
|
+
* @returns Function `invalidateTokenBalances` that invalidates token balances
|
|
143
|
+
* @example
|
|
144
|
+
* const { invalidateTokenBalances } = useInvalidateTokensBalances(["mT", "mUSD"])
|
|
145
|
+
* (...)
|
|
146
|
+
* await invalidateTokenBalances()
|
|
147
|
+
*/
|
|
148
|
+
export function useInvalidateTokensBalances(tokens?: MezoChainToken[]) {
|
|
149
|
+
const queryClient = useQueryClient()
|
|
150
|
+
|
|
151
|
+
const { queryKey } = useTokensBalances({ tokens })
|
|
152
|
+
|
|
153
|
+
const invalidateTokensBalancesHandler = useCallback(
|
|
154
|
+
() => queryClient.invalidateQueries({ queryKey }),
|
|
155
|
+
[queryClient, queryKey],
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
invalidateTokensBalances: invalidateTokensBalancesHandler,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Hook for resetting current user's token balances. Can be used to reset the
|
|
165
|
+
* balances manually, which forces the data to be re-fetched.
|
|
166
|
+
* @param tokens The list of tokens (as string arrays) for which we want to
|
|
167
|
+
* reset query for.
|
|
168
|
+
* @returns Function `resetTokenBalances` that invalidates token balances
|
|
169
|
+
* @example
|
|
170
|
+
* const { resetTokenBalances } = useResetTokensBalances(["mT", "mUSD"])
|
|
171
|
+
* (...)
|
|
172
|
+
* await resetTokenBalances()
|
|
173
|
+
*/
|
|
174
|
+
export function useResetTokensBalances(tokens?: MezoChainToken[]) {
|
|
175
|
+
const queryClient = useQueryClient()
|
|
176
|
+
|
|
177
|
+
const { queryKey } = useTokensBalances({ tokens })
|
|
178
|
+
|
|
179
|
+
const resetTokenBalancesHandler = useCallback(
|
|
180
|
+
() => queryClient.resetQueries({ queryKey }),
|
|
181
|
+
[queryClient, queryKey],
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
resetTokenBalances: resetTokenBalancesHandler,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useQueryClient,
|
|
3
|
+
useMutation,
|
|
4
|
+
MutationOptions,
|
|
5
|
+
DefaultError,
|
|
6
|
+
} from "@tanstack/react-query"
|
|
2
7
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
8
|
import { QUERY_KEYS } from "./constants"
|
|
9
|
+
import type { UpdateMezoIdResponse } from "../api"
|
|
4
10
|
|
|
5
|
-
export function useUpdateMezoId(
|
|
11
|
+
export function useUpdateMezoId(
|
|
12
|
+
mutationOptions: Omit<
|
|
13
|
+
MutationOptions<UpdateMezoIdResponse, DefaultError, string>,
|
|
14
|
+
"mutationFn" | "mutationKey"
|
|
15
|
+
> = {},
|
|
16
|
+
) {
|
|
6
17
|
const queryClient = useQueryClient()
|
|
7
18
|
const authApiClient = useAuthApiClient()
|
|
8
19
|
|
|
20
|
+
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
21
|
+
|
|
9
22
|
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
10
23
|
mutationFn: (newMezoId: string) => authApiClient.updateMezoId(newMezoId),
|
|
11
|
-
onSuccess: () => {
|
|
24
|
+
onSuccess: (data, variables, context) => {
|
|
12
25
|
queryClient.resetQueries({ queryKey: [QUERY_KEYS.ACCOUNT] })
|
|
26
|
+
|
|
27
|
+
if (customOnSuccess) customOnSuccess(data, variables, context)
|
|
13
28
|
},
|
|
14
|
-
...
|
|
29
|
+
...restMutationOptions,
|
|
15
30
|
})
|
|
16
31
|
|
|
17
32
|
return { updateMezoId: mutate, updateMezoIdAsync: mutateAsync, ...rest }
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { OrangeKitBitcoinProvider } from "@mezo-org/orangekit"
|
|
2
|
+
import { useQuery } from "@tanstack/react-query"
|
|
3
|
+
import { useMemo } from "react"
|
|
4
|
+
import { Address } from "viem"
|
|
5
|
+
import { Connector, useAccount } from "wagmi"
|
|
6
|
+
|
|
7
|
+
type UseWalletAccountReturn = {
|
|
8
|
+
accountAddress?: Address
|
|
9
|
+
walletAddress?: string
|
|
10
|
+
isConnected: boolean
|
|
11
|
+
networkFamily: "bitcoin" | "evm"
|
|
12
|
+
connector?: Connector
|
|
13
|
+
chainId?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type OrangeKitConnector = {
|
|
17
|
+
getBitcoinProvider: () => OrangeKitBitcoinProvider
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function useWalletAccount(): UseWalletAccountReturn {
|
|
21
|
+
const { address: evmAddress, connector, chainId } = useAccount()
|
|
22
|
+
|
|
23
|
+
const networkFamily = useMemo(
|
|
24
|
+
() => (connector?.type !== "orangekit" ? "evm" : "bitcoin"),
|
|
25
|
+
[connector],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const { data: btcData } = useQuery({
|
|
29
|
+
queryKey: [connector?.id],
|
|
30
|
+
queryFn: async () => {
|
|
31
|
+
const bitcoinProvider = (
|
|
32
|
+
connector as unknown as OrangeKitConnector
|
|
33
|
+
).getBitcoinProvider()
|
|
34
|
+
|
|
35
|
+
const address = await bitcoinProvider.getAddress()
|
|
36
|
+
const balance = await bitcoinProvider.getBalance()
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
address,
|
|
40
|
+
balance,
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const { address: btcAddress } = btcData || {}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
accountAddress: evmAddress,
|
|
49
|
+
walletAddress: btcAddress ?? evmAddress,
|
|
50
|
+
isConnected: networkFamily === "bitcoin" ? !!btcAddress : !!evmAddress,
|
|
51
|
+
networkFamily,
|
|
52
|
+
connector,
|
|
53
|
+
chainId,
|
|
54
|
+
} as const
|
|
55
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useMemo } from "react"
|
|
2
|
+
import { useAccount, useWatchContractEvent } from "wagmi"
|
|
3
|
+
import {
|
|
4
|
+
mainnetTokenContracts,
|
|
5
|
+
MezoChainToken,
|
|
6
|
+
testnetTokenContracts,
|
|
7
|
+
} from "../lib/contracts"
|
|
8
|
+
import { usePassportContext } from "./usePassportContext"
|
|
9
|
+
import { CHAIN_ID } from "../constants"
|
|
10
|
+
import { useRefreshPassport } from "./useRefreshPassport"
|
|
11
|
+
import { simpleWssMezoConfig } from "../config"
|
|
12
|
+
|
|
13
|
+
function useWatchTransferEvents(token: MezoChainToken) {
|
|
14
|
+
const { address: userAddress } = useAccount()
|
|
15
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
16
|
+
const { refreshTokensBalances, refreshBorrowData } = useRefreshPassport()
|
|
17
|
+
|
|
18
|
+
const contract = useMemo(() => {
|
|
19
|
+
const contracts =
|
|
20
|
+
environment === "mainnet" ? mainnetTokenContracts : testnetTokenContracts
|
|
21
|
+
|
|
22
|
+
return contracts[token]
|
|
23
|
+
}, [environment, token])
|
|
24
|
+
|
|
25
|
+
useWatchContractEvent({
|
|
26
|
+
address: contract.address,
|
|
27
|
+
abi: contract.abi,
|
|
28
|
+
eventName: "Transfer",
|
|
29
|
+
args: {
|
|
30
|
+
from: userAddress,
|
|
31
|
+
},
|
|
32
|
+
chainId: CHAIN_ID[environment],
|
|
33
|
+
enabled: !!userAddress,
|
|
34
|
+
config: simpleWssMezoConfig,
|
|
35
|
+
onLogs() {
|
|
36
|
+
console.log(`[${token}] Transfer from: ${userAddress}`)
|
|
37
|
+
refreshTokensBalances()
|
|
38
|
+
refreshBorrowData()
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
useWatchContractEvent({
|
|
43
|
+
address: contract.address,
|
|
44
|
+
abi: contract.abi,
|
|
45
|
+
eventName: "Transfer",
|
|
46
|
+
args: {
|
|
47
|
+
to: userAddress,
|
|
48
|
+
},
|
|
49
|
+
chainId: CHAIN_ID[environment],
|
|
50
|
+
enabled: !!userAddress,
|
|
51
|
+
config: simpleWssMezoConfig,
|
|
52
|
+
onLogs() {
|
|
53
|
+
console.log(`[${token}] Transfer to: ${userAddress}`)
|
|
54
|
+
refreshTokensBalances()
|
|
55
|
+
refreshBorrowData()
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function useWatchTransferEventsForAllTokens() {
|
|
61
|
+
useWatchTransferEvents("mcbBTC")
|
|
62
|
+
useWatchTransferEvents("mDAI")
|
|
63
|
+
useWatchTransferEvents("mFBTC")
|
|
64
|
+
useWatchTransferEvents("mSolvBTC")
|
|
65
|
+
useWatchTransferEvents("mswBTC")
|
|
66
|
+
useWatchTransferEvents("mT")
|
|
67
|
+
useWatchTransferEvents("mUSDC")
|
|
68
|
+
useWatchTransferEvents("mUSDe")
|
|
69
|
+
useWatchTransferEvents("mUSDT")
|
|
70
|
+
useWatchTransferEvents("mxSolvBTC")
|
|
71
|
+
useWatchTransferEvents("MUSD")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { useWatchTransferEvents, useWatchTransferEventsForAllTokens }
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./components"
|
|
2
|
+
export {
|
|
3
|
+
defaultConfig,
|
|
4
|
+
unisatWalletMezoMainnet,
|
|
5
|
+
unisatWalletMezoTestnet,
|
|
6
|
+
okxWalletMezoMainnet,
|
|
7
|
+
okxWalletMezoTestnet,
|
|
8
|
+
xverseWalletMezoMainnet,
|
|
9
|
+
xverseWalletMezoTestnet,
|
|
10
|
+
getDefaultWallets,
|
|
11
|
+
getConfig,
|
|
12
|
+
} from "./config"
|
|
2
13
|
export * from "./constants"
|
|
3
14
|
export * from "./hooks"
|
|
4
15
|
export * from "./provider"
|