@mezo-org/passport 0.4.0-dev.6 → 0.4.0-dev.61
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.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 +20 -5
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +19 -57
- 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 +17 -8
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +35 -9
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- 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/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
- 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/{AccountAddress.js → Root/WalletAddress.js} +21 -15
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
- 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/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/index.d.ts +3 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +3 -0
- 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 +90 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +7 -8
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +82 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +157 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useDropdownData.d.ts +37 -34
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
- package/dist/src/hooks/useDropdownData.js +85 -61
- package/dist/src/hooks/useDropdownData.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/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/useWalletAccount.d.ts +2 -1
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
- package/dist/src/hooks/useWalletAccount.js +19 -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 +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -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 +62 -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.js +1 -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/cryptoAssets.d.ts +17 -1
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
- package/dist/src/utils/cryptoAssets.js +87 -31
- package/dist/src/utils/cryptoAssets.js.map +1 -1
- package/dist/src/utils/cryptoAssets.test.js +51 -33
- package/dist/src/utils/cryptoAssets.test.js.map +1 -1
- package/dist/src/utils/currency.d.ts +8 -0
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +11 -0
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +1 -0
- package/dist/src/utils/currency.test.js.map +1 -1
- package/dist/src/utils/numbers.d.ts +32 -17
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +84 -33
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +124 -22
- package/dist/src/utils/numbers.test.js.map +1 -1
- package/package.json +11 -9
- package/src/api/auth.ts +3 -1
- 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 +69 -113
- package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
- package/src/components/Dropdown/Dropdown.tsx +86 -19
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +13 -18
- 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/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +77 -20
- package/src/constants.ts +12 -4
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useAssetsConversionRates.ts +97 -0
- package/src/hooks/useAuthenticateWithWallet.ts +8 -11
- package/src/hooks/useBorrowData.ts +181 -0
- package/src/hooks/useDropdownData.ts +119 -97
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useWalletAccount.ts +33 -19
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +11 -1
- package/src/lib/contracts/index.ts +92 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +1 -1
- 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/cryptoAssets.test.ts +57 -37
- package/src/utils/cryptoAssets.ts +113 -35
- package/src/utils/currency.test.ts +2 -0
- package/src/utils/currency.ts +21 -0
- package/src/utils/numbers.test.ts +154 -23
- package/src/utils/numbers.ts +112 -34
- 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.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.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.map +0 -1
- 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/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/hooks/useAssetsUSDConversion.ts +0 -31
package/src/config.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { http } from "viem"
|
|
2
1
|
import { Chain, getDefaultConfig, WalletList } from "@rainbow-me/rainbowkit"
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
Config,
|
|
4
|
+
createConfig,
|
|
5
|
+
CreateConfigParameters,
|
|
6
|
+
http,
|
|
7
|
+
webSocket,
|
|
8
|
+
} from "wagmi"
|
|
9
|
+
import { CHAIN_ID, mezoMainnet, mezoTestnet, RPC_BY_NETWORK } from "./constants"
|
|
5
10
|
import { getOKXWallet, getUnisatWallet, getXverseWallet } from "./wallet"
|
|
6
11
|
|
|
7
12
|
type WagmiConfigParameters = Omit<
|
|
@@ -20,7 +25,8 @@ type GetDefaultConfigParameters = WagmiConfigParameters & {
|
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
const transports = {
|
|
23
|
-
[CHAIN_ID.
|
|
28
|
+
[CHAIN_ID.mainnet]: http(RPC_BY_NETWORK.mainnet.http),
|
|
29
|
+
[CHAIN_ID.testnet]: http(RPC_BY_NETWORK.testnet.http),
|
|
24
30
|
} as Pick<CreateConfigParameters, "transports">
|
|
25
31
|
|
|
26
32
|
export const defaultConfig: Required<
|
|
@@ -34,39 +40,90 @@ export const defaultConfig: Required<
|
|
|
34
40
|
> = {
|
|
35
41
|
transports,
|
|
36
42
|
walletConnectProjectId: "",
|
|
37
|
-
chains: [
|
|
43
|
+
chains: [mezoMainnet, mezoTestnet],
|
|
38
44
|
multiInjectedProviderDiscovery: true,
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
const
|
|
42
|
-
rpcUrl: RPC_BY_NETWORK.testnet,
|
|
47
|
+
const bitcoinWalletTestnetConfig = {
|
|
48
|
+
rpcUrl: RPC_BY_NETWORK.testnet.http,
|
|
43
49
|
chainId: CHAIN_ID.testnet,
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
const bitcoinWalletMainnetConfig = {
|
|
53
|
+
rpcUrl: RPC_BY_NETWORK.mainnet.http,
|
|
54
|
+
chainId: CHAIN_ID.mainnet,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const unisatWalletMezoTestnet = getUnisatWallet(
|
|
58
|
+
bitcoinWalletTestnetConfig,
|
|
59
|
+
)
|
|
60
|
+
export const okxWalletMezoTestnet = getOKXWallet(bitcoinWalletTestnetConfig)
|
|
61
|
+
export const xverseWalletMezoTestnet = getXverseWallet(
|
|
62
|
+
bitcoinWalletTestnetConfig,
|
|
63
|
+
)
|
|
49
64
|
|
|
50
|
-
export
|
|
65
|
+
export const unisatWalletMezoMainnet = getUnisatWallet(
|
|
66
|
+
bitcoinWalletMainnetConfig,
|
|
67
|
+
)
|
|
68
|
+
export const okxWalletMezoMainnet = getOKXWallet(bitcoinWalletMainnetConfig)
|
|
69
|
+
export const xverseWalletMezoMainnet = getXverseWallet(
|
|
70
|
+
bitcoinWalletMainnetConfig,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
export function getDefaultWallets(
|
|
74
|
+
network: "mainnet" | "testnet" = "mainnet",
|
|
75
|
+
): WalletList {
|
|
51
76
|
return [
|
|
52
77
|
{
|
|
53
78
|
groupName: "Bitcoin",
|
|
54
|
-
wallets:
|
|
79
|
+
wallets:
|
|
80
|
+
network === "mainnet"
|
|
81
|
+
? [
|
|
82
|
+
unisatWalletMezoMainnet,
|
|
83
|
+
okxWalletMezoMainnet,
|
|
84
|
+
xverseWalletMezoMainnet,
|
|
85
|
+
]
|
|
86
|
+
: [
|
|
87
|
+
unisatWalletMezoTestnet,
|
|
88
|
+
okxWalletMezoTestnet,
|
|
89
|
+
xverseWalletMezoTestnet,
|
|
90
|
+
],
|
|
55
91
|
},
|
|
56
92
|
]
|
|
57
93
|
}
|
|
58
94
|
|
|
59
|
-
export function getConfig({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
95
|
+
export function getConfig(config: GetDefaultConfigParameters): Config {
|
|
96
|
+
const {
|
|
97
|
+
appName,
|
|
98
|
+
walletConnectProjectId = defaultConfig.walletConnectProjectId,
|
|
99
|
+
...restParameters
|
|
100
|
+
} = config
|
|
101
|
+
|
|
102
|
+
// Wallets don't have to be differentiated by network. Viem will choose proper
|
|
103
|
+
// connector selectively based on the chainId, or by the chainId passed
|
|
104
|
+
// explicitly.
|
|
105
|
+
const wallets = config.bitcoinWallets ?? [
|
|
106
|
+
...getDefaultWallets("mainnet"),
|
|
107
|
+
...getDefaultWallets("testnet"),
|
|
108
|
+
]
|
|
109
|
+
|
|
65
110
|
return getDefaultConfig({
|
|
66
111
|
...defaultConfig,
|
|
67
112
|
appName,
|
|
68
|
-
wallets
|
|
69
|
-
projectId: walletConnectProjectId
|
|
113
|
+
wallets,
|
|
114
|
+
projectId: walletConnectProjectId,
|
|
70
115
|
...restParameters,
|
|
71
116
|
})
|
|
72
117
|
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* This config is only used to listen for Transfer events on mezo chain.
|
|
121
|
+
* Should not be exported in index for public use.
|
|
122
|
+
*/
|
|
123
|
+
export const simpleWssMezoConfig = createConfig({
|
|
124
|
+
chains: [mezoMainnet, mezoTestnet],
|
|
125
|
+
transports: {
|
|
126
|
+
[mezoMainnet.id]: webSocket(RPC_BY_NETWORK.mainnet.webSocket),
|
|
127
|
+
[mezoTestnet.id]: webSocket(RPC_BY_NETWORK.testnet.webSocket),
|
|
128
|
+
},
|
|
129
|
+
})
|
package/src/constants.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mezoMainnet, mezoTestnet } from "@mezo-org/orangekit"
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { mezoMainnet, mezoTestnet } from "@mezo-org/orangekit"
|
|
4
4
|
|
|
5
5
|
export const CHAIN_ID = {
|
|
6
|
-
testnet:
|
|
6
|
+
testnet: mezoTestnet.id,
|
|
7
|
+
mainnet: mezoMainnet.id,
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const RPC_BY_NETWORK = {
|
|
10
|
-
|
|
11
|
+
mainnet: {
|
|
12
|
+
http: mezoMainnet.rpcUrls.default.http[0],
|
|
13
|
+
webSocket: mezoMainnet.rpcUrls.default.webSocket?.[0],
|
|
14
|
+
},
|
|
15
|
+
testnet: {
|
|
16
|
+
http: mezoTestnet.rpcUrls.default.http[0],
|
|
17
|
+
webSocket: mezoTestnet.rpcUrls.default.webSocket?.[0],
|
|
18
|
+
},
|
|
11
19
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,13 +6,19 @@ export {
|
|
|
6
6
|
useSubscribeToConnectorEvent,
|
|
7
7
|
useSubscribeToWalletNetworkDoesNotMatchProviderChain,
|
|
8
8
|
} from "@mezo-org/orangekit"
|
|
9
|
+
export { useInvalidateBorrowData, useResetBorrowData } from "./useBorrowData"
|
|
9
10
|
export * from "./useGetAccountByAddress"
|
|
10
11
|
export * from "./useGetAccountByMezoId"
|
|
11
12
|
export * from "./useGetCurrentAccount"
|
|
12
13
|
export * from "./useGetSession"
|
|
13
14
|
export * from "./useLinkAccount"
|
|
15
|
+
export * from "./useRefreshPassport"
|
|
14
16
|
export * from "./useSignInWithDiscord"
|
|
15
17
|
export * from "./useSignInWithWallet"
|
|
16
18
|
export * from "./useSignOut"
|
|
17
19
|
export * from "./useSignUpWithWallet"
|
|
20
|
+
export {
|
|
21
|
+
useInvalidateTokensBalances,
|
|
22
|
+
useResetTokensBalances,
|
|
23
|
+
} from "./useTokensBalances"
|
|
18
24
|
export * from "./useUpdateMezoId"
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query"
|
|
2
|
+
import { useReadContract } from "wagmi"
|
|
3
|
+
import { ONE_SECOND_MS } from "../utils/time"
|
|
4
|
+
import { QUERY_KEYS } from "./constants"
|
|
5
|
+
import { usePortalApiClient } from "./usePortalApiClient"
|
|
6
|
+
import { priceOracleContract } from "../lib/contracts"
|
|
7
|
+
import { fromFloatToBigInt } from "../utils/numbers"
|
|
8
|
+
import { getCryptoAsset } from "../utils/cryptoAssets"
|
|
9
|
+
import { CHAIN_ID } from "../constants"
|
|
10
|
+
import { usePassportContext } from "./usePassportContext"
|
|
11
|
+
|
|
12
|
+
const BTC_TARGET_DIGITS = getCryptoAsset("BTC").decimals
|
|
13
|
+
const T_TARGET_DIGITS = getCryptoAsset("mT").decimals
|
|
14
|
+
// If the oracle has not been updated in at least 60 seconds, it is stale.
|
|
15
|
+
const MAX_PRICE_DELAY = 60 * ONE_SECOND_MS
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Scales the price by the number of digits.
|
|
19
|
+
* @dev Oracles returns prices with variable number of digits. This function
|
|
20
|
+
* scales the price to a fixed number of digits ensuring consistency.
|
|
21
|
+
* @param price - The price to scale.
|
|
22
|
+
* @param priceDigits - The number of digits in the price.
|
|
23
|
+
* @returns The scaled price.
|
|
24
|
+
*/
|
|
25
|
+
function scalePriceByDigits(price: bigint, priceDigits: number): bigint {
|
|
26
|
+
if (priceDigits > BTC_TARGET_DIGITS) {
|
|
27
|
+
return price / 10n ** BigInt(priceDigits - BTC_TARGET_DIGITS)
|
|
28
|
+
}
|
|
29
|
+
if (priceDigits < BTC_TARGET_DIGITS) {
|
|
30
|
+
return price * 10n ** BigInt(BTC_TARGET_DIGITS - priceDigits)
|
|
31
|
+
}
|
|
32
|
+
return price
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Hook to fetch assets conversion rates.
|
|
37
|
+
* @see https://github.com/mezo-org/musd/blob/f0b2030315f0d8b0fc11a9fc778856fe4673051f/solidity/contracts/PriceFeed.sol
|
|
38
|
+
* @returns {}.data.{}.price - The latest asset price.
|
|
39
|
+
* @returns {}.data.{}.digits - The latest asset price digits.
|
|
40
|
+
* @returns {}.isPending - Whether the request is pending.
|
|
41
|
+
* @returns {}.isError - Whether there was an error fetching the price.
|
|
42
|
+
*/
|
|
43
|
+
export function useAssetsConversionRates() {
|
|
44
|
+
const portalApiClient = usePortalApiClient()
|
|
45
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
46
|
+
|
|
47
|
+
const btcPrice = useReadContract({
|
|
48
|
+
...priceOracleContract,
|
|
49
|
+
functionName: "latestRoundData",
|
|
50
|
+
query: {
|
|
51
|
+
refetchInterval: ({ state }) => {
|
|
52
|
+
if (!state.data) return MAX_PRICE_DELAY
|
|
53
|
+
|
|
54
|
+
const [, , , updatedAt] = state.data ?? []
|
|
55
|
+
if (!updatedAt) return MAX_PRICE_DELAY
|
|
56
|
+
|
|
57
|
+
const age = Date.now() - Number(updatedAt) * 1000
|
|
58
|
+
|
|
59
|
+
return age > MAX_PRICE_DELAY
|
|
60
|
+
? // If the data is stale, we want to refetch as soon as possible, but
|
|
61
|
+
// not faster than once per second, to avoid excessive requests.
|
|
62
|
+
// Math.max ensures the interval is at least 1 second.
|
|
63
|
+
Math.max(ONE_SECOND_MS, MAX_PRICE_DELAY - age)
|
|
64
|
+
: MAX_PRICE_DELAY - age
|
|
65
|
+
},
|
|
66
|
+
select: (data) => {
|
|
67
|
+
const [, answer] = data
|
|
68
|
+
return scalePriceByDigits(answer, BTC_TARGET_DIGITS)
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
chainId: CHAIN_ID[environment],
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const tPrice = useQuery({
|
|
75
|
+
queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
|
|
76
|
+
queryFn: () => portalApiClient.getPortalStatistics(),
|
|
77
|
+
select: (data) =>
|
|
78
|
+
fromFloatToBigInt(data.currentUsdPerTToken, T_TARGET_DIGITS),
|
|
79
|
+
refetchInterval: MAX_PRICE_DELAY,
|
|
80
|
+
throwOnError: true,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
data: {
|
|
85
|
+
t: {
|
|
86
|
+
price: tPrice.data ?? 0n,
|
|
87
|
+
decimals: T_TARGET_DIGITS,
|
|
88
|
+
},
|
|
89
|
+
btc: {
|
|
90
|
+
price: btcPrice.data ?? 0n,
|
|
91
|
+
decimals: BTC_TARGET_DIGITS,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
isPending: tPrice.isPending || btcPrice.isPending,
|
|
95
|
+
isError: tPrice.isError || btcPrice.isError,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { useSignMessage } from "wagmi"
|
|
2
|
-
import { useBitcoinAccount } from "@mezo-org/orangekit"
|
|
3
2
|
import { MutationOptions, useMutation } from "@tanstack/react-query"
|
|
4
|
-
import { useMemo } from "react"
|
|
5
3
|
import { useCreateAccount } from "./useCreateAccount"
|
|
6
4
|
import { useCreateSession } from "./useCreateSession"
|
|
7
5
|
import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
|
|
@@ -17,32 +15,31 @@ function useAuthenticateWithWallet(
|
|
|
17
15
|
"mutationFn" | "mutationKey"
|
|
18
16
|
> = {},
|
|
19
17
|
) {
|
|
20
|
-
const {
|
|
21
|
-
|
|
18
|
+
const { walletAddress, chainId, connector, networkFamily } =
|
|
19
|
+
useWalletAccount()
|
|
22
20
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
|
|
23
21
|
const { createSessionAsync } = useCreateSession()
|
|
24
22
|
const { createAccountAsync } = useCreateAccount()
|
|
25
23
|
const { signMessageAsync } = useSignMessage()
|
|
26
|
-
const walletAddress = useMemo(
|
|
27
|
-
() => (connector?.type === "orangekit" ? btcAddress : address),
|
|
28
|
-
[btcAddress, address, connector],
|
|
29
|
-
)
|
|
30
24
|
|
|
31
25
|
const { refetch: getAccountByAddress } = useGetAccountByAddress(
|
|
32
26
|
walletAddress,
|
|
33
|
-
{
|
|
27
|
+
{
|
|
28
|
+
enabled: false,
|
|
29
|
+
retry: false,
|
|
30
|
+
},
|
|
34
31
|
)
|
|
35
32
|
|
|
36
33
|
const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
|
|
37
34
|
mutationFn: async () => {
|
|
38
|
-
if (!
|
|
35
|
+
if (!walletAddress) {
|
|
39
36
|
throw new Error("Sign in error: Wallet not connected!")
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
const nonce = await ensureNoSessionAndFetchNonce()
|
|
43
40
|
|
|
44
41
|
const messageResult = createSignInWithWalletMessage(
|
|
45
|
-
|
|
42
|
+
walletAddress,
|
|
46
43
|
nonce,
|
|
47
44
|
networkFamily,
|
|
48
45
|
chainId,
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { useAccount, useReadContracts } from "wagmi"
|
|
2
|
+
import { useCallback, useMemo } from "react"
|
|
3
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
4
|
+
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
+
import {
|
|
6
|
+
mainnetBorrowContracts,
|
|
7
|
+
testnetBorrowContracts,
|
|
8
|
+
} from "../lib/contracts"
|
|
9
|
+
import { usePassportContext } from "./usePassportContext"
|
|
10
|
+
import { CHAIN_ID } from "../constants"
|
|
11
|
+
|
|
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
|
+
|
|
18
|
+
const TROVE_MANAGER_ABI = [
|
|
19
|
+
{
|
|
20
|
+
inputs: [
|
|
21
|
+
{
|
|
22
|
+
internalType: "address",
|
|
23
|
+
name: "_borrower",
|
|
24
|
+
type: "address",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
name: "getEntireDebtAndColl",
|
|
28
|
+
outputs: [
|
|
29
|
+
{
|
|
30
|
+
internalType: "uint256",
|
|
31
|
+
name: "coll",
|
|
32
|
+
type: "uint256",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
internalType: "uint256",
|
|
36
|
+
name: "principal",
|
|
37
|
+
type: "uint256",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
internalType: "uint256",
|
|
41
|
+
name: "interest",
|
|
42
|
+
type: "uint256",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
internalType: "uint256",
|
|
46
|
+
name: "pendingCollateral",
|
|
47
|
+
type: "uint256",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
internalType: "uint256",
|
|
51
|
+
name: "pendingPrincipal",
|
|
52
|
+
type: "uint256",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
internalType: "uint256",
|
|
56
|
+
name: "pendingInterest",
|
|
57
|
+
type: "uint256",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
stateMutability: "view",
|
|
61
|
+
type: "function",
|
|
62
|
+
},
|
|
63
|
+
] as const
|
|
64
|
+
|
|
65
|
+
const BORROWER_OPERATIONS_ABI = [
|
|
66
|
+
{
|
|
67
|
+
inputs: [],
|
|
68
|
+
name: "MUSD_GAS_COMPENSATION",
|
|
69
|
+
outputs: [
|
|
70
|
+
{
|
|
71
|
+
internalType: "uint256",
|
|
72
|
+
name: "",
|
|
73
|
+
type: "uint256",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
stateMutability: "view",
|
|
77
|
+
type: "function",
|
|
78
|
+
},
|
|
79
|
+
] as const
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Query hook for getting borrow data. Returns collateral and trove debt for the
|
|
83
|
+
* connected account, based on it's evm address.
|
|
84
|
+
* @param queryOptions Query options passed to the underlying `useQuery` hook.
|
|
85
|
+
*/
|
|
86
|
+
export function useBorrowData(queryOptions = {}) {
|
|
87
|
+
const { environment = "mainnet" } = usePassportContext()
|
|
88
|
+
const { address } = useAccount()
|
|
89
|
+
|
|
90
|
+
const contractAddress = useMemo(() => {
|
|
91
|
+
if (environment === "mainnet") {
|
|
92
|
+
return {
|
|
93
|
+
troveManager: mainnetBorrowContracts.TroveManager.address,
|
|
94
|
+
borrowerOperations: mainnetBorrowContracts.BorrowerOperations.address,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
troveManager: testnetBorrowContracts.TroveManager.address,
|
|
99
|
+
borrowerOperations: testnetBorrowContracts.BorrowerOperations.address,
|
|
100
|
+
}
|
|
101
|
+
}, [environment])
|
|
102
|
+
|
|
103
|
+
const chainId = CHAIN_ID[environment]
|
|
104
|
+
|
|
105
|
+
return useReadContracts({
|
|
106
|
+
contracts: [
|
|
107
|
+
{
|
|
108
|
+
abi: TROVE_MANAGER_ABI,
|
|
109
|
+
address: contractAddress.troveManager,
|
|
110
|
+
functionName: "getEntireDebtAndColl",
|
|
111
|
+
args: [address || "0x"],
|
|
112
|
+
chainId,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
abi: BORROWER_OPERATIONS_ABI,
|
|
116
|
+
address: contractAddress.borrowerOperations,
|
|
117
|
+
functionName: "MUSD_GAS_COMPENSATION",
|
|
118
|
+
args: [],
|
|
119
|
+
chainId,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
query: {
|
|
123
|
+
enabled: !!address,
|
|
124
|
+
staleTime: 5 * ONE_MINUTE_MS,
|
|
125
|
+
retry: 1,
|
|
126
|
+
select: (data) => {
|
|
127
|
+
if (!data || data.some((item) => !item.result)) return undefined
|
|
128
|
+
|
|
129
|
+
const [collateral, principal, interest] = data[0].result!
|
|
130
|
+
const gasCompensation = data[1].result!
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
collateral,
|
|
134
|
+
// Principal includes gas compensation value which is not
|
|
135
|
+
troveDebt: principal + interest - gasCompensation,
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
...queryOptions,
|
|
139
|
+
},
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Hook for for invalidating current user's borrow data. Can be used to
|
|
145
|
+
* invalidate borrow data manually, which forces the data to be re-fetched.
|
|
146
|
+
* @returns Function `invalidateBorrowData` for invalidating the borrow data
|
|
147
|
+
*/
|
|
148
|
+
export function useInvalidateBorrowData() {
|
|
149
|
+
const queryClient = useQueryClient()
|
|
150
|
+
|
|
151
|
+
const { queryKey } = useBorrowData()
|
|
152
|
+
|
|
153
|
+
const invalidateBorrowDataHandler = useCallback(
|
|
154
|
+
() => queryClient.invalidateQueries({ queryKey }),
|
|
155
|
+
[queryClient, queryKey],
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
invalidateBorrowData: invalidateBorrowDataHandler,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Hook for for resetting current user's borrow data. Can be used to reset
|
|
165
|
+
* borrow data manually, which forces the data to be re-fetched.
|
|
166
|
+
* @returns Function `resetBorrowData` for resetting the borrow data
|
|
167
|
+
*/
|
|
168
|
+
export function useResetBorrowData() {
|
|
169
|
+
const queryClient = useQueryClient()
|
|
170
|
+
|
|
171
|
+
const { queryKey } = useBorrowData()
|
|
172
|
+
|
|
173
|
+
const resetBorrowDataHandler = useCallback(
|
|
174
|
+
() => queryClient.resetQueries({ queryKey }),
|
|
175
|
+
[queryClient, queryKey],
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
resetBorrowData: resetBorrowDataHandler,
|
|
180
|
+
}
|
|
181
|
+
}
|