@mezo-org/passport 0.4.0-dev.9 → 0.5.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 +31 -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/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 +68 -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/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
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { useBitcoinAccount } from "@mezo-org/orangekit"
|
|
2
|
-
import { useGetCurrentAccount } from "."
|
|
3
|
-
import {
|
|
4
|
-
CryptoAssetKey,
|
|
5
|
-
getCryptoAsset,
|
|
6
|
-
isBitcoinLikeCryptoAsset,
|
|
7
|
-
isUsdLikeCryptoAsset,
|
|
8
|
-
} from "../utils/cryptoAssets"
|
|
9
|
-
import { fromFixedPoint } from "../utils/numbers"
|
|
10
|
-
import { useAssetsUsdConversion } from "./useAssetsUSDConversion"
|
|
11
|
-
import useWalletAccount from "./useWalletAccount"
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Formats crypto asset to balance details (balance in USD and decimals)
|
|
15
|
-
* @param type The type of crypto asset
|
|
16
|
-
* @param balance The balance of crypto asset
|
|
17
|
-
* @param btcUsdConversionRate The USD conversion rate
|
|
18
|
-
* @returns The balance details
|
|
19
|
-
*/
|
|
20
|
-
export function formatCryptoAsset(
|
|
21
|
-
type: CryptoAssetKey,
|
|
22
|
-
balance: bigint,
|
|
23
|
-
btcUsdConversionRate: number,
|
|
24
|
-
) {
|
|
25
|
-
const { decimals } = getCryptoAsset(type)
|
|
26
|
-
|
|
27
|
-
const nativeBalance = fromFixedPoint(balance, decimals, 4)
|
|
28
|
-
let balanceInUsd = 0
|
|
29
|
-
if (isBitcoinLikeCryptoAsset(type)) {
|
|
30
|
-
balanceInUsd = nativeBalance * btcUsdConversionRate
|
|
31
|
-
}
|
|
32
|
-
if (isUsdLikeCryptoAsset(type)) {
|
|
33
|
-
balanceInUsd = nativeBalance
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
type,
|
|
38
|
-
balance: nativeBalance,
|
|
39
|
-
balanceInUsd,
|
|
40
|
-
decimals,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type DropdownCryptoAsset<T = CryptoAssetKey> = {
|
|
45
|
-
type: T
|
|
46
|
-
balance: bigint
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
type DropdownDetailedCryptoAsset = ReturnType<typeof formatCryptoAsset>
|
|
50
|
-
|
|
51
|
-
export type DropdownData = {
|
|
52
|
-
mezoId: string
|
|
53
|
-
address: string
|
|
54
|
-
walletType: "bitcoin" | "evm"
|
|
55
|
-
totalBalanceInUsd: number
|
|
56
|
-
formattedNativeAssets: DropdownDetailedCryptoAsset[]
|
|
57
|
-
matsnet: {
|
|
58
|
-
mats: number
|
|
59
|
-
formattedAssets: DropdownDetailedCryptoAsset[]
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
type UseDropdownDataOptions = {
|
|
64
|
-
// This is workaround. It should be read from contracts or fetched from API.
|
|
65
|
-
evmNativeAssets?: DropdownCryptoAsset[]
|
|
66
|
-
matsnetAssets?: DropdownCryptoAsset[]
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Aggregates dropdown data for Dropdown component.
|
|
71
|
-
* @param options - Options for the dropdown data.
|
|
72
|
-
* @param options.evmNativeAssets - Native assets for EVM wallet.
|
|
73
|
-
* @param options.matsnetAssets - Matsnet tokens. Rendered as separate section.
|
|
74
|
-
* @returns Dropdown data.
|
|
75
|
-
*/
|
|
76
|
-
export default function useDropdownData(
|
|
77
|
-
options?: UseDropdownDataOptions,
|
|
78
|
-
): DropdownData | null {
|
|
79
|
-
const { evmNativeAssets = [], matsnetAssets = [] } = options || {}
|
|
80
|
-
|
|
81
|
-
const { btcBalance } = useBitcoinAccount()
|
|
82
|
-
const { address, networkFamily, isConnected } = useWalletAccount()
|
|
83
|
-
const { data: passportAccount } = useGetCurrentAccount()
|
|
84
|
-
const { data: assetsUsdConversion } = useAssetsUsdConversion()
|
|
85
|
-
|
|
86
|
-
if (!address || !isConnected || !passportAccount) {
|
|
87
|
-
return null
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const mezoId = passportAccount.mezoId!
|
|
91
|
-
|
|
92
|
-
const nativeAssets: DropdownCryptoAsset[] =
|
|
93
|
-
networkFamily === "bitcoin"
|
|
94
|
-
? [
|
|
95
|
-
{
|
|
96
|
-
type: "btc",
|
|
97
|
-
balance: BigInt(btcBalance?.total ?? 0),
|
|
98
|
-
},
|
|
99
|
-
]
|
|
100
|
-
: evmNativeAssets
|
|
101
|
-
|
|
102
|
-
const btcUsdConversionRate = Number(assetsUsdConversion?.btcUsd ?? 0)
|
|
103
|
-
|
|
104
|
-
const formattedNativeAssets = nativeAssets.map((asset) =>
|
|
105
|
-
formatCryptoAsset(asset.type, asset.balance, btcUsdConversionRate),
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
const totalBalanceInUsd = formattedNativeAssets.reduce(
|
|
109
|
-
(sum, value) => sum + value.balanceInUsd,
|
|
110
|
-
0,
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
const matsBalance = passportAccount.mats.totalMats
|
|
114
|
-
|
|
115
|
-
const matsnetFormattedAssets = matsnetAssets.map((asset) =>
|
|
116
|
-
formatCryptoAsset(asset.type, asset.balance, btcUsdConversionRate),
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
mezoId,
|
|
121
|
-
address,
|
|
122
|
-
walletType: networkFamily,
|
|
123
|
-
totalBalanceInUsd,
|
|
124
|
-
formattedNativeAssets,
|
|
125
|
-
matsnet: {
|
|
126
|
-
mats: matsBalance,
|
|
127
|
-
formattedAssets: matsnetFormattedAssets,
|
|
128
|
-
},
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BitcoinCircle,
|
|
3
|
-
EthCircle,
|
|
4
|
-
MUsdCircle,
|
|
5
|
-
TBtcCircle,
|
|
6
|
-
} from "@mezo-org/mezo-clay"
|
|
7
|
-
import { getCryptoAsset } from "./cryptoAssets"
|
|
8
|
-
|
|
9
|
-
describe("getCryptoAsset", () => {
|
|
10
|
-
it("returns the correct asset for 'btc'", () => {
|
|
11
|
-
const asset = getCryptoAsset("btc")
|
|
12
|
-
expect(asset.name).toBe("Bitcoin")
|
|
13
|
-
expect(asset.symbol).toBe("BTC")
|
|
14
|
-
expect(asset.decimals).toBe(8)
|
|
15
|
-
expect(asset.icon).toBe(BitcoinCircle)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it("returns the correct asset for 'eth'", () => {
|
|
19
|
-
const asset = getCryptoAsset("eth")
|
|
20
|
-
expect(asset.name).toBe("Ethereum")
|
|
21
|
-
expect(asset.symbol).toBe("ETH")
|
|
22
|
-
expect(asset.decimals).toBe(18)
|
|
23
|
-
expect(asset.icon).toBe(EthCircle)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it("returns the correct asset for 'tbtc'", () => {
|
|
27
|
-
const asset = getCryptoAsset("tbtc")
|
|
28
|
-
expect(asset.name).toBe("Threshold Bitcoin")
|
|
29
|
-
expect(asset.symbol).toBe("tBTC")
|
|
30
|
-
expect(asset.decimals).toBe(18)
|
|
31
|
-
expect(asset.icon).toBe(TBtcCircle)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it("returns the correct asset for 'wbtc'", () => {
|
|
35
|
-
const asset = getCryptoAsset("wbtc")
|
|
36
|
-
expect(asset.name).toBe("Wrapped Bitcoin")
|
|
37
|
-
expect(asset.symbol).toBe("wBTC")
|
|
38
|
-
expect(asset.decimals).toBe(8)
|
|
39
|
-
// FIXME: Test should expect the exact icon component
|
|
40
|
-
expect(asset.icon).toEqual(expect.any(Function))
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it("returns the correct asset for 'mbtc'", () => {
|
|
44
|
-
const asset = getCryptoAsset("mbtc")
|
|
45
|
-
expect(asset.name).toBe("Matsnet Bitcoin")
|
|
46
|
-
expect(asset.symbol).toBe("BTC")
|
|
47
|
-
expect(asset.decimals).toBe(18)
|
|
48
|
-
// FIXME: Test should expect the exact icon component
|
|
49
|
-
expect(asset.icon).toEqual(expect.any(Function))
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it("returns the correct asset for 'musd'", () => {
|
|
53
|
-
const asset = getCryptoAsset("musd")
|
|
54
|
-
expect(asset.name).toBe("Mezo USD")
|
|
55
|
-
expect(asset.symbol).toBe("mUSD")
|
|
56
|
-
expect(asset.decimals).toBe(18)
|
|
57
|
-
expect(asset.icon).toBe(MUsdCircle)
|
|
58
|
-
})
|
|
59
|
-
})
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BitcoinCircle,
|
|
3
|
-
EthCircle,
|
|
4
|
-
IconProps,
|
|
5
|
-
MUsdCircle,
|
|
6
|
-
TBtcCircle,
|
|
7
|
-
} from "@mezo-org/mezo-clay"
|
|
8
|
-
import { createElement, FC } from "react"
|
|
9
|
-
|
|
10
|
-
export type CryptoAssetKey = "btc" | "eth" | "tbtc" | "wbtc" | "mbtc" | "musd"
|
|
11
|
-
|
|
12
|
-
export type CryptoAsset = {
|
|
13
|
-
name: string
|
|
14
|
-
symbol: string
|
|
15
|
-
icon: FC<IconProps>
|
|
16
|
-
decimals: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const CRYPTO_ASSETS: Record<CryptoAssetKey, CryptoAsset> = {
|
|
20
|
-
btc: {
|
|
21
|
-
name: "Bitcoin",
|
|
22
|
-
symbol: "BTC",
|
|
23
|
-
icon: BitcoinCircle,
|
|
24
|
-
decimals: 8,
|
|
25
|
-
},
|
|
26
|
-
eth: {
|
|
27
|
-
name: "Ethereum",
|
|
28
|
-
symbol: "ETH",
|
|
29
|
-
icon: EthCircle,
|
|
30
|
-
decimals: 18,
|
|
31
|
-
},
|
|
32
|
-
tbtc: {
|
|
33
|
-
name: "Threshold Bitcoin",
|
|
34
|
-
symbol: "tBTC",
|
|
35
|
-
icon: TBtcCircle,
|
|
36
|
-
decimals: 18,
|
|
37
|
-
},
|
|
38
|
-
wbtc: {
|
|
39
|
-
name: "Wrapped Bitcoin",
|
|
40
|
-
symbol: "wBTC",
|
|
41
|
-
icon: (props) =>
|
|
42
|
-
createElement(BitcoinCircle, {
|
|
43
|
-
...props,
|
|
44
|
-
symbolColor: "#FF8A00",
|
|
45
|
-
color: "#000000",
|
|
46
|
-
}),
|
|
47
|
-
decimals: 8,
|
|
48
|
-
},
|
|
49
|
-
mbtc: {
|
|
50
|
-
name: "Matsnet Bitcoin",
|
|
51
|
-
symbol: "BTC",
|
|
52
|
-
icon: (props) =>
|
|
53
|
-
createElement(BitcoinCircle, {
|
|
54
|
-
...props,
|
|
55
|
-
symbolColor: "#000000",
|
|
56
|
-
color: "#FFC907",
|
|
57
|
-
}),
|
|
58
|
-
decimals: 18,
|
|
59
|
-
},
|
|
60
|
-
musd: {
|
|
61
|
-
name: "Mezo USD",
|
|
62
|
-
symbol: "MUSD",
|
|
63
|
-
icon: MUsdCircle,
|
|
64
|
-
decimals: 18,
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Gets details of given crypto asset
|
|
70
|
-
* @param key The key of crypto asset
|
|
71
|
-
* @returns The crypto asset details
|
|
72
|
-
*/
|
|
73
|
-
export function getCryptoAsset(key: CryptoAssetKey) {
|
|
74
|
-
return CRYPTO_ASSETS[key]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Checks if given crypto asset is Bitcoin-like
|
|
79
|
-
* @param key The key of crypto asset
|
|
80
|
-
* @returns True if crypto asset is Bitcoin-like
|
|
81
|
-
*/
|
|
82
|
-
export function isBitcoinLikeCryptoAsset(key: CryptoAssetKey) {
|
|
83
|
-
return ["btc", "tbtc", "wbtc", "mbtc"].includes(key)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Checks if given crypto asset is USD-like
|
|
88
|
-
* @param key The key of crypto asset
|
|
89
|
-
* @returns True if crypto asset is USD-like
|
|
90
|
-
*/
|
|
91
|
-
export function isUsdLikeCryptoAsset(key: CryptoAssetKey) {
|
|
92
|
-
return ["musd"].includes(key)
|
|
93
|
-
}
|