@mezo-org/passport 0.4.0-dev.82 → 0.4.0-dev.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/Dropdown/Content.d.ts +0 -15
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +3 -3
- package/dist/src/components/Dropdown/Content.js.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.d.ts +0 -4
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +10 -36
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.d.ts +8 -7
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.js +36 -28
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -1
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +2 -1
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -1
- package/dist/src/components/Dropdown/NestedViewLayout.js +13 -15
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -1
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +1 -4
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Receive/Receive.js +30 -19
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +2 -5
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +13 -12
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +2 -4
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountBalance.js +24 -8
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -1
- 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 +2 -3
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +34 -39
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -1
- package/dist/src/components/Dropdown/Root/Root.d.ts +0 -15
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/Root.js +22 -34
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -1
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +2 -6
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/WalletAddress.js +37 -34
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -1
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +2 -4
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +60 -16
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -1
- 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/config.d.ts +0 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +1 -9
- package/dist/src/config.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +8 -13
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.js +44 -67
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +30 -4
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -1
- package/dist/src/hooks/useBorrowData.js +53 -11
- package/dist/src/hooks/useBorrowData.js.map +1 -1
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +3 -3
- 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.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +3 -3
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/useTokensBalances.d.ts +36 -35
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
- package/dist/src/hooks/useTokensBalances.js +93 -52
- package/dist/src/hooks/useTokensBalances.js.map +1 -1
- package/dist/src/hooks/useWalletAccount.d.ts +8 -6
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
- package/dist/src/hooks/useWalletAccount.js +9 -6
- package/dist/src/hooks/useWalletAccount.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +1 -1
- package/dist/src/lib/contracts/index.d.ts.map +1 -1
- package/dist/src/lib/contracts/index.js +4 -0
- package/dist/src/lib/contracts/index.js.map +1 -1
- 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/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 +6 -3
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +13 -10
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +44 -2
- package/dist/src/utils/currency.test.js.map +1 -1
- package/dist/src/utils/numbers.d.ts +13 -53
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +16 -118
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +24 -142
- package/dist/src/utils/numbers.test.js.map +1 -1
- package/package.json +2 -1
- package/src/components/Dropdown/Content.tsx +3 -48
- package/src/components/Dropdown/Dropdown.tsx +7 -58
- package/src/components/Dropdown/ListingItem.tsx +155 -59
- package/src/components/Dropdown/NestedViewLayout.tsx +32 -20
- package/src/components/Dropdown/Receive/Receive.tsx +57 -32
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +33 -35
- package/src/components/Dropdown/Root/AccountBalance.tsx +54 -16
- 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 +63 -46
- package/src/components/Dropdown/Root/Root.tsx +28 -98
- package/src/components/Dropdown/Root/WalletAddress.tsx +87 -89
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +112 -30
- package/src/components/Dropdown/SlotNumber.tsx +131 -0
- package/src/config.ts +1 -11
- package/src/hooks/useAssetsConversionRates.ts +49 -67
- package/src/hooks/useAuthenticateWithWallet.ts +7 -5
- package/src/hooks/useBorrowData.ts +71 -12
- package/src/hooks/useCreateAccount.ts +5 -4
- package/src/hooks/useGetCurrentAccount.ts +5 -7
- package/src/hooks/useLinkAccount.ts +5 -4
- package/src/hooks/useTokensBalances.ts +152 -74
- package/src/hooks/useWalletAccount.ts +19 -13
- package/src/lib/contracts/index.ts +8 -1
- package/src/provider.ts +11 -3
- package/src/utils/assets.test.ts +57 -0
- package/src/utils/assets.ts +103 -0
- package/src/utils/currency.test.ts +76 -2
- package/src/utils/currency.ts +20 -15
- package/src/utils/numbers.test.ts +29 -180
- package/src/utils/numbers.ts +22 -171
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +0 -11
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +0 -1
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js +0 -9
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +0 -1
- package/dist/src/hooks/useDropdownData.d.ts +0 -47
- package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
- package/dist/src/hooks/useDropdownData.js +0 -97
- package/dist/src/hooks/useDropdownData.js.map +0 -1
- package/dist/src/utils/cryptoAssets.d.ts +0 -44
- package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
- package/dist/src/utils/cryptoAssets.js +0 -129
- 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 -67
- package/dist/src/utils/cryptoAssets.test.js.map +0 -1
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +0 -26
- package/src/hooks/useDropdownData.ts +0 -152
- package/src/utils/cryptoAssets.test.ts +0 -79
- package/src/utils/cryptoAssets.ts +0 -171
|
@@ -1,36 +1,20 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query"
|
|
2
|
-
import {
|
|
2
|
+
import { useConfig } from "wagmi"
|
|
3
|
+
import { readContract } from "wagmi/actions"
|
|
4
|
+
import { parseUnits } from "viem"
|
|
3
5
|
import { ONE_SECOND_MS } from "../utils/time"
|
|
4
|
-
import { QUERY_KEYS } from "./constants"
|
|
5
6
|
import { usePortalApiClient } from "./usePortalApiClient"
|
|
6
7
|
import { priceOracleContract } from "../lib/contracts"
|
|
7
|
-
import { fromFloatToBigInt } from "../utils/numbers"
|
|
8
|
-
import { getCryptoAsset } from "../utils/cryptoAssets"
|
|
9
8
|
import { CHAIN_ID } from "../constants"
|
|
10
9
|
import { usePassportContext } from "./usePassportContext"
|
|
10
|
+
import { normalizePrecision } from "../utils/numbers"
|
|
11
|
+
|
|
12
|
+
export const CONVERSION_RATE_DECIMALS = 18
|
|
11
13
|
|
|
12
|
-
const BTC_TARGET_DIGITS = getCryptoAsset("BTC").decimals
|
|
13
|
-
const T_TARGET_DIGITS = getCryptoAsset("mT").decimals
|
|
14
14
|
// If the oracle has not been updated in at least 60 seconds, it is stale.
|
|
15
15
|
const MAX_PRICE_DELAY = 60 * ONE_SECOND_MS
|
|
16
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
|
-
}
|
|
17
|
+
export const QUERY_KEY = "passport.assetsConversionRates"
|
|
34
18
|
|
|
35
19
|
/**
|
|
36
20
|
* Hook to fetch assets conversion rates.
|
|
@@ -43,55 +27,53 @@ function scalePriceByDigits(price: bigint, priceDigits: number): bigint {
|
|
|
43
27
|
export function useAssetsConversionRates() {
|
|
44
28
|
const portalApiClient = usePortalApiClient()
|
|
45
29
|
const { environment = "mainnet" } = usePassportContext()
|
|
30
|
+
const config = useConfig()
|
|
46
31
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
return useQuery({
|
|
33
|
+
queryKey: [QUERY_KEY],
|
|
34
|
+
queryFn: async () =>
|
|
35
|
+
Promise.all([
|
|
36
|
+
portalApiClient.getPortalStatistics(),
|
|
37
|
+
readContract(config, {
|
|
38
|
+
...priceOracleContract,
|
|
39
|
+
functionName: "latestRoundData",
|
|
40
|
+
chainId: CHAIN_ID[environment],
|
|
41
|
+
}),
|
|
42
|
+
]),
|
|
43
|
+
select: ([portalStatistics, btcPriceData]) => {
|
|
44
|
+
const tTokenConversionRate = portalStatistics.currentUsdPerTToken
|
|
45
|
+
const [, btcConversionRate] = btcPriceData
|
|
56
46
|
|
|
57
|
-
|
|
47
|
+
const tPrice = parseUnits(tTokenConversionRate, CONVERSION_RATE_DECIMALS)
|
|
48
|
+
const btcPrice = normalizePrecision(
|
|
49
|
+
btcConversionRate,
|
|
50
|
+
CONVERSION_RATE_DECIMALS,
|
|
51
|
+
)
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
select: (data) => {
|
|
67
|
-
const [, answer] = data
|
|
68
|
-
return scalePriceByDigits(answer, BTC_TARGET_DIGITS)
|
|
69
|
-
},
|
|
53
|
+
return {
|
|
54
|
+
rates: {
|
|
55
|
+
mT: tPrice,
|
|
56
|
+
BTC: btcPrice,
|
|
57
|
+
},
|
|
58
|
+
decimals: CONVERSION_RATE_DECIMALS,
|
|
59
|
+
}
|
|
70
60
|
},
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
refetchInterval: ({ state }) => {
|
|
62
|
+
if (!state.data) return MAX_PRICE_DELAY
|
|
73
63
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
fromFloatToBigInt(data.currentUsdPerTToken, T_TARGET_DIGITS),
|
|
79
|
-
refetchInterval: MAX_PRICE_DELAY,
|
|
80
|
-
throwOnError: true,
|
|
81
|
-
})
|
|
64
|
+
const [, btcPriceData] = state.data
|
|
65
|
+
const [, , , updatedAt] = btcPriceData
|
|
66
|
+
|
|
67
|
+
if (!updatedAt) return MAX_PRICE_DELAY
|
|
82
68
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
decimals: BTC_TARGET_DIGITS,
|
|
92
|
-
},
|
|
69
|
+
const age = Date.now() - Number(updatedAt) * 1000
|
|
70
|
+
|
|
71
|
+
return age > MAX_PRICE_DELAY
|
|
72
|
+
? // If the data is stale, we want to refetch as soon as possible, but
|
|
73
|
+
// not faster than once per second, to avoid excessive requests.
|
|
74
|
+
// Math.max ensures the interval is at least 1 second.
|
|
75
|
+
Math.max(ONE_SECOND_MS, MAX_PRICE_DELAY - age)
|
|
76
|
+
: MAX_PRICE_DELAY - age
|
|
93
77
|
},
|
|
94
|
-
|
|
95
|
-
isError: tPrice.isError || btcPrice.isError,
|
|
96
|
-
}
|
|
78
|
+
})
|
|
97
79
|
}
|
|
@@ -23,10 +23,12 @@ function useAuthenticateWithWallet(
|
|
|
23
23
|
> = {},
|
|
24
24
|
) {
|
|
25
25
|
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
data: {
|
|
27
|
+
walletAddress,
|
|
28
|
+
chainId: walletChainId,
|
|
29
|
+
connector,
|
|
30
|
+
networkFamily,
|
|
31
|
+
} = {},
|
|
30
32
|
} = useWalletAccount()
|
|
31
33
|
const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
|
|
32
34
|
const { createSessionAsync } = useCreateSession()
|
|
@@ -52,7 +54,7 @@ function useAuthenticateWithWallet(
|
|
|
52
54
|
const messageResult = createSignInWithWalletMessage(
|
|
53
55
|
walletAddress,
|
|
54
56
|
nonce,
|
|
55
|
-
networkFamily
|
|
57
|
+
networkFamily!,
|
|
56
58
|
chainId ?? walletChainId,
|
|
57
59
|
)
|
|
58
60
|
const signatureResult = await signMessageAsync({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useReadContracts } from "wagmi"
|
|
2
2
|
import { useCallback, useMemo } from "react"
|
|
3
3
|
import { useQueryClient } from "@tanstack/react-query"
|
|
4
|
+
import { formatUnits } from "viem"
|
|
4
5
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
6
|
import {
|
|
6
7
|
mainnetBorrowContracts,
|
|
@@ -8,7 +9,12 @@ import {
|
|
|
8
9
|
} from "../lib/contracts"
|
|
9
10
|
import { usePassportContext } from "./usePassportContext"
|
|
10
11
|
import { CHAIN_ID } from "../constants"
|
|
11
|
-
import { bigIntMax } from "../utils/numbers"
|
|
12
|
+
import { bigIntMax, normalizePrecision } from "../utils/numbers"
|
|
13
|
+
import useWalletAccount from "./useWalletAccount"
|
|
14
|
+
import { getAsset } from "../utils/assets"
|
|
15
|
+
import { convertToUsd } from "../utils/currency"
|
|
16
|
+
|
|
17
|
+
const DEBT_AND_COLL_PRECISION = 18
|
|
12
18
|
|
|
13
19
|
// Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
|
|
14
20
|
// support importing JSON as const yet so types cannot be inferred from the
|
|
@@ -79,6 +85,22 @@ const BORROWER_OPERATIONS_ABI = [
|
|
|
79
85
|
},
|
|
80
86
|
] as const
|
|
81
87
|
|
|
88
|
+
const PRICE_FEED_ABI = [
|
|
89
|
+
{
|
|
90
|
+
inputs: [],
|
|
91
|
+
name: "fetchPrice",
|
|
92
|
+
outputs: [
|
|
93
|
+
{
|
|
94
|
+
internalType: "uint256",
|
|
95
|
+
name: "",
|
|
96
|
+
type: "uint256",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
stateMutability: "view",
|
|
100
|
+
type: "function",
|
|
101
|
+
},
|
|
102
|
+
] as const
|
|
103
|
+
|
|
82
104
|
/**
|
|
83
105
|
* Query hook for getting borrow data. Returns collateral and trove debt for the
|
|
84
106
|
* connected account, based on it's evm address.
|
|
@@ -86,18 +108,20 @@ const BORROWER_OPERATIONS_ABI = [
|
|
|
86
108
|
*/
|
|
87
109
|
export function useBorrowData(queryOptions = {}) {
|
|
88
110
|
const { environment = "mainnet" } = usePassportContext()
|
|
89
|
-
const {
|
|
111
|
+
const { data: walletAccountData } = useWalletAccount()
|
|
90
112
|
|
|
91
113
|
const contractAddress = useMemo(() => {
|
|
92
114
|
if (environment === "mainnet") {
|
|
93
115
|
return {
|
|
94
116
|
troveManager: mainnetBorrowContracts.TroveManager.address,
|
|
95
117
|
borrowerOperations: mainnetBorrowContracts.BorrowerOperations.address,
|
|
118
|
+
priceFeed: mainnetBorrowContracts.PriceFeed.address,
|
|
96
119
|
}
|
|
97
120
|
}
|
|
98
121
|
return {
|
|
99
122
|
troveManager: testnetBorrowContracts.TroveManager.address,
|
|
100
123
|
borrowerOperations: testnetBorrowContracts.BorrowerOperations.address,
|
|
124
|
+
priceFeed: testnetBorrowContracts.PriceFeed.address,
|
|
101
125
|
}
|
|
102
126
|
}, [environment])
|
|
103
127
|
|
|
@@ -109,36 +133,71 @@ export function useBorrowData(queryOptions = {}) {
|
|
|
109
133
|
abi: TROVE_MANAGER_ABI,
|
|
110
134
|
address: contractAddress.troveManager,
|
|
111
135
|
functionName: "getEntireDebtAndColl",
|
|
112
|
-
args:
|
|
136
|
+
args: walletAccountData.accountAddress
|
|
137
|
+
? [walletAccountData.accountAddress]
|
|
138
|
+
: ["0x" as `0x${string}}`],
|
|
113
139
|
chainId,
|
|
114
140
|
},
|
|
115
141
|
{
|
|
116
142
|
abi: BORROWER_OPERATIONS_ABI,
|
|
117
143
|
address: contractAddress.borrowerOperations,
|
|
118
144
|
functionName: "MUSD_GAS_COMPENSATION",
|
|
119
|
-
|
|
145
|
+
chainId,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
abi: PRICE_FEED_ABI,
|
|
149
|
+
address: contractAddress.priceFeed,
|
|
150
|
+
functionName: "fetchPrice",
|
|
120
151
|
chainId,
|
|
121
152
|
},
|
|
122
153
|
],
|
|
123
154
|
query: {
|
|
124
|
-
enabled: !!
|
|
155
|
+
enabled: !!walletAccountData,
|
|
125
156
|
staleTime: 5 * ONE_MINUTE_MS,
|
|
126
157
|
retry: 1,
|
|
127
158
|
select: (data) => {
|
|
128
|
-
if (!data || data.some((item) => !item.result))
|
|
159
|
+
if (!data || data.some((item) => !item.result))
|
|
160
|
+
throw new Error("No borrow data available")
|
|
129
161
|
|
|
130
|
-
const [
|
|
162
|
+
const [rawCollateral, principal, interest] = data[0].result!
|
|
131
163
|
const gasCompensation = data[1].result!
|
|
164
|
+
const collateralPrice = data[2].result!
|
|
165
|
+
|
|
166
|
+
const btcDetails = getAsset("BTC")
|
|
167
|
+
|
|
168
|
+
const collateral = {
|
|
169
|
+
value: rawCollateral,
|
|
170
|
+
decimals: btcDetails.decimals,
|
|
171
|
+
symbol: btcDetails.symbol,
|
|
172
|
+
formatted: formatUnits(rawCollateral, DEBT_AND_COLL_PRECISION),
|
|
173
|
+
usd: convertToUsd(
|
|
174
|
+
rawCollateral,
|
|
175
|
+
DEBT_AND_COLL_PRECISION,
|
|
176
|
+
collateralPrice,
|
|
177
|
+
DEBT_AND_COLL_PRECISION,
|
|
178
|
+
),
|
|
179
|
+
}
|
|
132
180
|
|
|
133
|
-
const
|
|
134
|
-
|
|
181
|
+
const debtInUsdValue = bigIntMax(
|
|
182
|
+
normalizePrecision(
|
|
183
|
+
principal + interest - gasCompensation,
|
|
184
|
+
DEBT_AND_COLL_PRECISION,
|
|
185
|
+
),
|
|
135
186
|
0n, // Ensure that debt is not negative
|
|
136
187
|
)
|
|
188
|
+
const formattedDebtInUsd = formatUnits(
|
|
189
|
+
debtInUsdValue,
|
|
190
|
+
DEBT_AND_COLL_PRECISION,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
const debtInUsd = {
|
|
194
|
+
value: debtInUsdValue,
|
|
195
|
+
formatted: formattedDebtInUsd,
|
|
196
|
+
}
|
|
137
197
|
|
|
138
198
|
return {
|
|
139
199
|
collateral,
|
|
140
|
-
|
|
141
|
-
troveDebt,
|
|
200
|
+
debtInUsd,
|
|
142
201
|
}
|
|
143
202
|
},
|
|
144
203
|
...queryOptions,
|
|
@@ -18,7 +18,7 @@ export function useCreateAccount(
|
|
|
18
18
|
) {
|
|
19
19
|
const queryClient = useQueryClient()
|
|
20
20
|
const authApiClient = useAuthApiClient()
|
|
21
|
-
const
|
|
21
|
+
const walletAccount = useWalletAccount()
|
|
22
22
|
|
|
23
23
|
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
24
24
|
|
|
@@ -27,12 +27,13 @@ export function useCreateAccount(
|
|
|
27
27
|
createAccountMutationFnParameters: CreateAccountRequest,
|
|
28
28
|
) => {
|
|
29
29
|
if (createAccountMutationFnParameters.type === "wallet") {
|
|
30
|
-
if (!connector) {
|
|
30
|
+
if (!walletAccount.data?.connector) {
|
|
31
31
|
throw new Error("Connector not defined.")
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const bitcoinPublicKey =
|
|
35
|
-
|
|
34
|
+
const bitcoinPublicKey = await getBitcoinPublicKeyFromConnector(
|
|
35
|
+
walletAccount.data.connector,
|
|
36
|
+
)
|
|
36
37
|
|
|
37
38
|
// Creating bitcoin mezo account
|
|
38
39
|
if (bitcoinPublicKey) {
|
|
@@ -24,16 +24,15 @@ export function useGetCurrentAccount(
|
|
|
24
24
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
25
25
|
queryFn: async () => {
|
|
26
26
|
const currentAccount = await authApiClient.getCurrentAccount()
|
|
27
|
+
if (!currentAccount) {
|
|
28
|
+
throw new Error("No current account found")
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
const linkedWallets = currentAccount?.linkedAccounts?.filter(
|
|
28
32
|
(account) => account.type === "wallet",
|
|
29
33
|
)
|
|
30
34
|
if (!linkedWallets || linkedWallets.length === 0) {
|
|
31
|
-
|
|
32
|
-
...currentAccount,
|
|
33
|
-
mats: {
|
|
34
|
-
totalMats: 0,
|
|
35
|
-
},
|
|
36
|
-
}
|
|
35
|
+
throw new Error("No linked wallets found for the current account")
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
const addresses = linkedWallets.map(
|
|
@@ -42,7 +41,6 @@ export function useGetCurrentAccount(
|
|
|
42
41
|
const mats = await Promise.all(
|
|
43
42
|
addresses.map((address) => portalApiClient.getPortalMats(address)),
|
|
44
43
|
)
|
|
45
|
-
|
|
46
44
|
const totalMats = mats.reduce(
|
|
47
45
|
(sumMats, currentMats) => sumMats + currentMats.totalMats,
|
|
48
46
|
0,
|
|
@@ -26,7 +26,7 @@ export function useLinkAccount(
|
|
|
26
26
|
) {
|
|
27
27
|
const queryClient = useQueryClient()
|
|
28
28
|
const authApiClient = useAuthApiClient()
|
|
29
|
-
const
|
|
29
|
+
const walletAccount = useWalletAccount()
|
|
30
30
|
|
|
31
31
|
const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
|
|
32
32
|
|
|
@@ -35,12 +35,13 @@ export function useLinkAccount(
|
|
|
35
35
|
linkAccountMutationFnParameters: LinkAccountMutationFnParameters,
|
|
36
36
|
) => {
|
|
37
37
|
if (linkAccountMutationFnParameters.type === "wallet") {
|
|
38
|
-
if (!connector) {
|
|
38
|
+
if (!walletAccount.data?.connector) {
|
|
39
39
|
throw new Error("Connector not defined.")
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const bitcoinPublicKey =
|
|
43
|
-
|
|
42
|
+
const bitcoinPublicKey = await getBitcoinPublicKeyFromConnector(
|
|
43
|
+
walletAccount.data.connector,
|
|
44
|
+
)
|
|
44
45
|
|
|
45
46
|
// Linking bitcoin account
|
|
46
47
|
if (bitcoinPublicKey) {
|