@mezo-org/passport 0.4.0-dev.81 → 0.4.0-dev.83

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.
Files changed (187) hide show
  1. package/dist/src/api/auth.d.ts +1 -1
  2. package/dist/src/api/auth.d.ts.map +1 -1
  3. package/dist/src/components/Dropdown/Content.d.ts +0 -15
  4. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  5. package/dist/src/components/Dropdown/Content.js +3 -3
  6. package/dist/src/components/Dropdown/Content.js.map +1 -1
  7. package/dist/src/components/Dropdown/Dropdown.d.ts +0 -4
  8. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  9. package/dist/src/components/Dropdown/Dropdown.js +10 -33
  10. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  11. package/dist/src/components/Dropdown/ListingItem.d.ts +8 -7
  12. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -1
  13. package/dist/src/components/Dropdown/ListingItem.js +36 -28
  14. package/dist/src/components/Dropdown/ListingItem.js.map +1 -1
  15. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +2 -1
  16. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -1
  17. package/dist/src/components/Dropdown/NestedViewLayout.js +13 -15
  18. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -1
  19. package/dist/src/components/Dropdown/Receive/Receive.d.ts +1 -4
  20. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -1
  21. package/dist/src/components/Dropdown/Receive/Receive.js +36 -19
  22. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -1
  23. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +2 -5
  24. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -1
  25. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +28 -12
  26. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -1
  27. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +2 -4
  28. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -1
  29. package/dist/src/components/Dropdown/Root/AccountBalance.js +24 -8
  30. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -1
  31. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
  32. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  33. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
  34. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  35. package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
  36. package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
  37. package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
  38. package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
  39. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
  40. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
  42. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +2 -3
  44. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -1
  45. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +34 -39
  46. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -1
  47. package/dist/src/components/Dropdown/Root/Root.d.ts +0 -15
  48. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -1
  49. package/dist/src/components/Dropdown/Root/Root.js +22 -34
  50. package/dist/src/components/Dropdown/Root/Root.js.map +1 -1
  51. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +2 -6
  52. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -1
  53. package/dist/src/components/Dropdown/Root/WalletAddress.js +43 -34
  54. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -1
  55. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +2 -4
  56. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -1
  57. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +60 -16
  58. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -1
  59. package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
  60. package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
  61. package/dist/src/components/Dropdown/SlotNumber.js +67 -0
  62. package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
  63. package/dist/src/config.d.ts +1 -11
  64. package/dist/src/config.d.ts.map +1 -1
  65. package/dist/src/config.js +3 -40
  66. package/dist/src/config.js.map +1 -1
  67. package/dist/src/constants.d.ts +0 -2
  68. package/dist/src/constants.d.ts.map +1 -1
  69. package/dist/src/constants.js +0 -2
  70. package/dist/src/constants.js.map +1 -1
  71. package/dist/src/hooks/useAssetsConversionRates.d.ts +8 -13
  72. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
  73. package/dist/src/hooks/useAssetsConversionRates.js +44 -67
  74. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
  75. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  76. package/dist/src/hooks/useAuthenticateWithWallet.js +1 -1
  77. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  78. package/dist/src/hooks/useBorrowData.d.ts +31 -5
  79. package/dist/src/hooks/useBorrowData.d.ts.map +1 -1
  80. package/dist/src/hooks/useBorrowData.js +53 -11
  81. package/dist/src/hooks/useBorrowData.js.map +1 -1
  82. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  83. package/dist/src/hooks/useCreateAccount.js +3 -3
  84. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  85. package/dist/src/hooks/useGetCurrentAccount.d.ts +2 -2
  86. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  87. package/dist/src/hooks/useGetCurrentAccount.js +4 -6
  88. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  89. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  90. package/dist/src/hooks/useLinkAccount.js +3 -3
  91. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  92. package/dist/src/hooks/useTokensBalances.d.ts +36 -35
  93. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
  94. package/dist/src/hooks/useTokensBalances.js +93 -52
  95. package/dist/src/hooks/useTokensBalances.js.map +1 -1
  96. package/dist/src/hooks/useWalletAccount.d.ts +8 -10
  97. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  98. package/dist/src/hooks/useWalletAccount.js +22 -19
  99. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  100. package/dist/src/index.d.ts +1 -1
  101. package/dist/src/index.d.ts.map +1 -1
  102. package/dist/src/index.js +1 -1
  103. package/dist/src/index.js.map +1 -1
  104. package/dist/src/lib/contracts/index.d.ts +1 -1
  105. package/dist/src/lib/contracts/index.d.ts.map +1 -1
  106. package/dist/src/lib/contracts/index.js +4 -0
  107. package/dist/src/lib/contracts/index.js.map +1 -1
  108. package/dist/src/provider.d.ts +7 -1
  109. package/dist/src/provider.d.ts.map +1 -1
  110. package/dist/src/provider.js +4 -1
  111. package/dist/src/provider.js.map +1 -1
  112. package/dist/src/utils/assets.d.ts +145 -0
  113. package/dist/src/utils/assets.d.ts.map +1 -0
  114. package/dist/src/utils/assets.js +100 -0
  115. package/dist/src/utils/assets.js.map +1 -0
  116. package/dist/src/utils/assets.test.d.ts +2 -0
  117. package/dist/src/utils/assets.test.d.ts.map +1 -0
  118. package/dist/src/utils/assets.test.js +46 -0
  119. package/dist/src/utils/assets.test.js.map +1 -0
  120. package/dist/src/utils/currency.d.ts +6 -3
  121. package/dist/src/utils/currency.d.ts.map +1 -1
  122. package/dist/src/utils/currency.js +13 -10
  123. package/dist/src/utils/currency.js.map +1 -1
  124. package/dist/src/utils/currency.test.js +44 -2
  125. package/dist/src/utils/currency.test.js.map +1 -1
  126. package/dist/src/utils/numbers.d.ts +13 -53
  127. package/dist/src/utils/numbers.d.ts.map +1 -1
  128. package/dist/src/utils/numbers.js +16 -118
  129. package/dist/src/utils/numbers.js.map +1 -1
  130. package/dist/src/utils/numbers.test.js +24 -142
  131. package/dist/src/utils/numbers.test.js.map +1 -1
  132. package/package.json +2 -1
  133. package/src/api/auth.ts +1 -1
  134. package/src/components/Dropdown/Content.tsx +3 -48
  135. package/src/components/Dropdown/Dropdown.tsx +7 -55
  136. package/src/components/Dropdown/ListingItem.tsx +155 -59
  137. package/src/components/Dropdown/NestedViewLayout.tsx +32 -20
  138. package/src/components/Dropdown/Receive/Receive.tsx +69 -32
  139. package/src/components/Dropdown/Root/AccountAddressActions.tsx +64 -35
  140. package/src/components/Dropdown/Root/AccountBalance.tsx +54 -16
  141. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  142. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  143. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  144. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +63 -46
  145. package/src/components/Dropdown/Root/Root.tsx +28 -98
  146. package/src/components/Dropdown/Root/WalletAddress.tsx +95 -89
  147. package/src/components/Dropdown/Root/WelcomeBlock.tsx +109 -29
  148. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  149. package/src/config.ts +3 -59
  150. package/src/constants.ts +0 -6
  151. package/src/hooks/useAssetsConversionRates.ts +49 -67
  152. package/src/hooks/useAuthenticateWithWallet.ts +7 -5
  153. package/src/hooks/useBorrowData.ts +71 -12
  154. package/src/hooks/useCreateAccount.ts +5 -4
  155. package/src/hooks/useGetCurrentAccount.ts +5 -7
  156. package/src/hooks/useLinkAccount.ts +5 -4
  157. package/src/hooks/useTokensBalances.ts +152 -74
  158. package/src/hooks/useWalletAccount.ts +27 -36
  159. package/src/index.ts +0 -1
  160. package/src/lib/contracts/index.ts +8 -1
  161. package/src/provider.ts +11 -3
  162. package/src/utils/assets.test.ts +57 -0
  163. package/src/utils/assets.ts +103 -0
  164. package/src/utils/currency.test.ts +76 -2
  165. package/src/utils/currency.ts +20 -15
  166. package/src/utils/numbers.test.ts +29 -180
  167. package/src/utils/numbers.ts +22 -171
  168. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +0 -11
  169. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +0 -1
  170. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +0 -9
  171. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +0 -1
  172. package/dist/src/hooks/useDropdownData.d.ts +0 -47
  173. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  174. package/dist/src/hooks/useDropdownData.js +0 -97
  175. package/dist/src/hooks/useDropdownData.js.map +0 -1
  176. package/dist/src/utils/cryptoAssets.d.ts +0 -44
  177. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  178. package/dist/src/utils/cryptoAssets.js +0 -129
  179. package/dist/src/utils/cryptoAssets.js.map +0 -1
  180. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  181. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  182. package/dist/src/utils/cryptoAssets.test.js +0 -67
  183. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  184. package/src/components/Dropdown/Root/AccountAssetItem.tsx +0 -26
  185. package/src/hooks/useDropdownData.ts +0 -152
  186. package/src/utils/cryptoAssets.test.ts +0 -79
  187. package/src/utils/cryptoAssets.ts +0 -171
@@ -1,32 +1,33 @@
1
1
  import {
2
2
  Block,
3
- HeadingSmall,
4
- LabelSmall,
3
+ BlockProps,
4
+ HeadingMedium,
5
+ LabelLarge,
5
6
  Mats,
7
+ mergeOverrides,
8
+ Skeleton,
6
9
  useStyletron,
7
10
  } from "@mezo-org/mezo-clay"
8
11
  import React from "react"
9
12
  import DefaultAvatar from "../../../assets/DefaultAvatar"
13
+ import { useGetCurrentAccount } from "../../../hooks"
14
+ import { formatNumberToCompactString } from "../../../utils/numbers"
15
+ import AccountError from "./AccountError"
16
+ import { usePassportContext } from "../../../hooks/usePassportContext"
17
+ import SlotNumber from "../SlotNumber"
10
18
 
11
19
  const DOT_DELIMITER_REGEX = /(?=\.)/
12
20
 
13
- type WelcomeBlockProps = {
14
- mezoId: string
15
- matsBalance: string
16
- }
17
-
18
- export default function WelcomeBlock(props: WelcomeBlockProps) {
19
- const { mezoId, matsBalance } = props
20
-
21
- const [name, nameSuffix] = mezoId.split(DOT_DELIMITER_REGEX)
21
+ function WelcomeBlockSkeleton() {
22
22
  const [, theme] = useStyletron()
23
23
 
24
24
  return (
25
25
  <Block
26
26
  display="flex"
27
27
  alignItems="center"
28
- padding={`${theme.sizing.scale600} 0`}
29
- marginBottom={theme.sizing.scale300}
28
+ padding={theme.sizing.scale600}
29
+ paddingTop={theme.sizing.scale900}
30
+ paddingBottom={theme.sizing.scale800}
30
31
  overrides={{
31
32
  Block: {
32
33
  style: {
@@ -35,12 +36,12 @@ export default function WelcomeBlock(props: WelcomeBlockProps) {
35
36
  },
36
37
  }}
37
38
  >
38
- <Block
39
- as={DefaultAvatar}
39
+ <Skeleton
40
+ animation
40
41
  width={theme.sizing.scale1200}
41
42
  height={theme.sizing.scale1200}
42
43
  overrides={{
43
- Block: {
44
+ Root: {
44
45
  style: {
45
46
  borderRadius: "100%",
46
47
  },
@@ -51,6 +52,7 @@ export default function WelcomeBlock(props: WelcomeBlockProps) {
51
52
  <Block
52
53
  display="flex"
53
54
  flexDirection="column"
55
+ flex={1}
54
56
  overrides={{
55
57
  Block: {
56
58
  style: {
@@ -59,32 +61,110 @@ export default function WelcomeBlock(props: WelcomeBlockProps) {
59
61
  },
60
62
  }}
61
63
  >
62
- <HeadingSmall as="span">
63
- <Block as="span">{name}</Block>
64
- <Block as="span" color={theme.colors.gray500}>
65
- {nameSuffix}
64
+ <Skeleton animation width="60%" height={theme.sizing.scale900} />
65
+ <Skeleton animation width="40%" height={theme.sizing.scale800} />
66
+ </Block>
67
+ </Block>
68
+ )
69
+ }
70
+
71
+ type WelcomeBlockProps = BlockProps
72
+
73
+ export default function WelcomeBlock(props: WelcomeBlockProps) {
74
+ const { overrides, ...restProps } = props
75
+ const { accountDataRefetchInterval } = usePassportContext()
76
+
77
+ const { data, isError, isPending } = useGetCurrentAccount({
78
+ staleTime: accountDataRefetchInterval,
79
+ refetchInterval: accountDataRefetchInterval,
80
+ })
81
+ const [, theme] = useStyletron()
82
+
83
+ if (isError) {
84
+ return (
85
+ <AccountError
86
+ padding={theme.sizing.scale600}
87
+ paddingTop={theme.sizing.scale900}
88
+ paddingBottom={theme.sizing.scale800}
89
+ marginBottom={theme.sizing.scale300}
90
+ topic="account information"
91
+ />
92
+ )
93
+ }
94
+
95
+ if (isPending) {
96
+ return <WelcomeBlockSkeleton />
97
+ }
98
+
99
+ const [mezoId, mezoIdSuffix] = data.mezoId.split(DOT_DELIMITER_REGEX)
100
+
101
+ return (
102
+ <Block
103
+ display="flex"
104
+ alignItems="center"
105
+ paddingLeft={theme.sizing.scale600}
106
+ paddingRight={theme.sizing.scale600}
107
+ paddingTop={theme.sizing.scale900}
108
+ paddingBottom={theme.sizing.scale800}
109
+ overrides={mergeOverrides(overrides, {
110
+ Block: {
111
+ style: {
112
+ gap: theme.sizing.scale600,
113
+ },
114
+ },
115
+ })}
116
+ {...restProps}
117
+ >
118
+ <Block
119
+ as={DefaultAvatar}
120
+ width={theme.sizing.scale1200}
121
+ height={theme.sizing.scale1200}
122
+ overrides={{
123
+ Block: {
124
+ style: {
125
+ borderRadius: "100%",
126
+ },
127
+ },
128
+ }}
129
+ />
130
+
131
+ <Block display="flex" flexDirection="column">
132
+ <HeadingMedium as="span">
133
+ <Block as="span">{mezoId}</Block>
134
+ <Block as="span" color={theme.colors.contentSecondary}>
135
+ {mezoIdSuffix}
66
136
  </Block>
67
- </HeadingSmall>
137
+ </HeadingMedium>
68
138
 
69
- <LabelSmall
139
+ <Block
70
140
  display="flex"
71
141
  alignItems="center"
72
- margin={0}
73
- color={theme.colors.contentTertiary}
74
142
  overrides={{
75
143
  Block: {
76
144
  style: {
77
- gap: theme.sizing.scale400,
145
+ gap: theme.sizing.scale100,
78
146
  },
79
147
  },
80
148
  }}
81
149
  >
82
150
  <Mats
83
- color={theme.colors.contentPrimary}
84
- size={theme.sizing.scale500}
151
+ size={theme.sizing.scale600}
152
+ overrides={{
153
+ Svg: {
154
+ style: {
155
+ margin: theme.sizing.scale100, // To reduce gap
156
+ },
157
+ },
158
+ }}
85
159
  />
86
- {matsBalance} mats
87
- </LabelSmall>
160
+
161
+ <LabelLarge color={theme.colors.contentPrimary}>
162
+ <SlotNumber formatFunction={formatNumberToCompactString}>
163
+ {data.mats.totalMats}
164
+ </SlotNumber>{" "}
165
+ mats
166
+ </LabelLarge>
167
+ </Block>
88
168
  </Block>
89
169
  </Block>
90
170
  )
@@ -0,0 +1,131 @@
1
+ /* eslint-disable react/no-array-index-key */
2
+ import React, { useMemo } from "react"
3
+ import { AnimatePresence, motion } from "motion/react"
4
+ import { Block, useStyletron } from "@mezo-org/mezo-clay"
5
+
6
+ type SlotNumberProps = {
7
+ className?: string
8
+ children: number
9
+ formatFunction?: (value: number) => string
10
+ }
11
+
12
+ type SlotNumberDigitProps = {
13
+ className?: string
14
+ children: number
15
+ }
16
+
17
+ function SlotNumberDigit(props: SlotNumberDigitProps) {
18
+ const { children: value, ...restProps } = props
19
+
20
+ const [css] = useStyletron()
21
+
22
+ const digits = [...Array(10).keys()]
23
+
24
+ return (
25
+ <AnimatePresence initial={false}>
26
+ <motion.div
27
+ initial={{
28
+ y: "100%",
29
+ }}
30
+ animate={{
31
+ y: "0%",
32
+ }}
33
+ layout="position"
34
+ className={css({
35
+ position: "relative",
36
+ })}
37
+ {...restProps}
38
+ >
39
+ <Block
40
+ overrides={{
41
+ Block: {
42
+ style: {
43
+ visibility: "hidden",
44
+ },
45
+ },
46
+ }}
47
+ >
48
+ {value}
49
+ </Block>
50
+
51
+ <motion.div
52
+ className={css({
53
+ display: "flex",
54
+ flexDirection: "column",
55
+ position: "absolute",
56
+ inset: 0,
57
+ height: "fit-content",
58
+ })}
59
+ initial={false}
60
+ animate={{ y: `${(value / 10) * -100}%` }}
61
+ transition={{
62
+ type: "spring",
63
+ damping: 16,
64
+ stiffness: 220,
65
+ }}
66
+ >
67
+ {digits.map((digit) => (
68
+ <Block as="span" key={digit}>
69
+ {digit}
70
+ </Block>
71
+ ))}
72
+ </motion.div>
73
+ </motion.div>
74
+ </AnimatePresence>
75
+ )
76
+ }
77
+
78
+ /**
79
+ * SlotNumber component displays a number with animated digits.
80
+ *
81
+ * @typedef {object} SlotNumberProps
82
+ * @property {number} children - The number to display.
83
+ * @property {function} [formatFunction] - Optional function to format the number.
84
+ * @property {BlockProps} [restProps] - Additional properties for the Block component.
85
+ * @see https://pyszkowski.dev/writings/slot-number
86
+ * @returns {JSX.Element} The rendered SlotNumber component.
87
+ */
88
+ function SlotNumber(props: SlotNumberProps) {
89
+ const { children: value, formatFunction, ...restProps } = props
90
+
91
+ const [css] = useStyletron()
92
+
93
+ const characters = useMemo(() => {
94
+ const formattedValue = formatFunction
95
+ ? formatFunction(value)
96
+ : value.toString()
97
+
98
+ return formattedValue
99
+ .split("")
100
+ .map((character) => (/^[0-9]$/.test(character) ? +character : character))
101
+ .reverse()
102
+ }, [formatFunction, value])
103
+
104
+ return (
105
+ <motion.div
106
+ layout
107
+ className={css({
108
+ display: "inline-flex",
109
+ flexDirection: "row-reverse",
110
+ justifyContent: "flex-end",
111
+ overflow: "hidden",
112
+ userSelect: "none",
113
+ })}
114
+ {...restProps}
115
+ >
116
+ {characters.map((character, index) =>
117
+ typeof character === "number" ? (
118
+ <SlotNumberDigit key={`slot-number-character-${index}`}>
119
+ {character}
120
+ </SlotNumberDigit>
121
+ ) : (
122
+ <motion.span layout key={`slot-number-character-${index}`}>
123
+ {character}
124
+ </motion.span>
125
+ ),
126
+ )}
127
+ </motion.div>
128
+ )
129
+ }
130
+
131
+ export default SlotNumber
package/src/config.ts CHANGED
@@ -1,9 +1,4 @@
1
- import {
2
- Chain,
3
- getDefaultConfig,
4
- RainbowKitWalletConnectParameters,
5
- WalletList,
6
- } from "@rainbow-me/rainbowkit"
1
+ import { Chain, getDefaultConfig, WalletList } from "@rainbow-me/rainbowkit"
7
2
  import {
8
3
  Config,
9
4
  createConfig,
@@ -12,14 +7,7 @@ import {
12
7
  webSocket,
13
8
  } from "wagmi"
14
9
  import { walletConnectWallet } from "@rainbow-me/rainbowkit/wallets"
15
- import {
16
- CHAIN_ID,
17
- MEZO_LOGO,
18
- mezoMainnet,
19
- mezoTestnet,
20
- RPC_BY_NETWORK,
21
- WALLET_CONNECT_SAFE_WALLET_ID,
22
- } from "./constants"
10
+ import { CHAIN_ID, mezoMainnet, mezoTestnet, RPC_BY_NETWORK } from "./constants"
23
11
  import { getOKXWallet, getUnisatWallet, getXverseWallet } from "./wallet"
24
12
 
25
13
  type WagmiConfigParameters = Omit<
@@ -84,50 +72,6 @@ export const xverseWalletMezoMainnet = getXverseWallet(
84
72
  bitcoinWalletMainnetConfig,
85
73
  )
86
74
 
87
- type WalletConnectWalletOptions = {
88
- projectId: string
89
- options?: RainbowKitWalletConnectParameters
90
- }
91
-
92
- /**
93
- * Creates a RainbowKit's WalletConnect wallet with Safe Wallets (Ethereum and Mezo). It has disabled Explorer.
94
- * @param opts - Options for the WalletConnect wallet.
95
- * @returns A WalletConnect wallet configured for Safe Wallets.
96
- */
97
- export const safeWalletConnectWallet = (opts: WalletConnectWalletOptions) => {
98
- const { projectId, options } = opts
99
-
100
- return walletConnectWallet({
101
- projectId,
102
- options: {
103
- ...options,
104
- qrModalOptions: {
105
- ...options?.qrModalOptions,
106
- desktopWallets: [
107
- ...(options?.qrModalOptions?.desktopWallets || []),
108
- {
109
- id: "mezo",
110
- name: "Mezo Safe",
111
- links: {
112
- native: "",
113
- universal: "https://safe.mezo.org/",
114
- },
115
- },
116
- ],
117
- walletImages: {
118
- ...options?.qrModalOptions?.walletImages,
119
- mezo: MEZO_LOGO,
120
- },
121
- explorerExcludedWalletIds: "ALL",
122
- explorerRecommendedWalletIds: [
123
- ...(options?.qrModalOptions?.explorerRecommendedWalletIds || []),
124
- WALLET_CONNECT_SAFE_WALLET_ID,
125
- ],
126
- },
127
- },
128
- })
129
- }
130
-
131
75
  export function getDefaultWallets(
132
76
  network: "mainnet" | "testnet" = "mainnet",
133
77
  ): WalletList {
@@ -149,7 +93,7 @@ export function getDefaultWallets(
149
93
  },
150
94
  {
151
95
  groupName: "Ethereum",
152
- wallets: [safeWalletConnectWallet],
96
+ wallets: [walletConnectWallet],
153
97
  },
154
98
  ]
155
99
  }
package/src/constants.ts CHANGED
@@ -17,9 +17,3 @@ export const RPC_BY_NETWORK = {
17
17
  webSocket: mezoTestnet.rpcUrls.default.webSocket?.[0],
18
18
  },
19
19
  }
20
-
21
- export const MEZO_LOGO =
22
- "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAQ5QTFRF9TlR9TpS9kRa91Zr92d6+HCC+G+B9klf9TtT9UBX9lJn92V4915x9k9k9T5V+6ax/dLY//b3//7+//////j5/drf+7C6+HSF+pmm/MrQ/vDx//39//n6/urs/MPK+YKR9UJZ92F0/eDk+HiI/LfA/vHz+Y6c+qGt/vP0+6+59kdd9TxU+HqK/uzu/czS9k1j+pik+7S9+YeW/dfc9kVb+YWU//z8/L3F91lt/cvS/MLJ9lRp+Yya/dbb/L/H/d3h/uHl91xw//T2/MbN/uPm+HKD+pCe+pWi/d/j/ufq/ujq9kth/MfO91tv/c7U+7O89lVq+6mz92N19kpg+G1/+p2p+6Ov+pKf+6y3+Gt92yHguQAAAx9JREFUeJzt1tlPE0EcB/CdUtouRxuKQItgCyVNpG3SKoWKqOHBxKQGCf6Z4hGNT8Yjno00UAERJcoCEWuIIgj0iHUtuwWW3ZlpSYq8fOelM/Pb3fnsHL8tEU64EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgKPfoZSCmWTpcZGQvGAlZPOYAPXm3fEVRoYyRmN9MZDdVRAiHQOgK5s/aDjIZ/3wbdnMfsNJVjJC2XIkgN1N1rRtsZHMaZoBQla1YVszeVdVgL17Rd91JqcRnFs06cKF/E4VAQHLsrHTS5J71ahhRYqrJC9WD2BppS1pT7Y0zbHlHCXsSJeZg8oBYs8qtd//TVJ+Bz9Swyb/qyoBhj4wAr1vd1+9K8/IC46lQnUA7jwrEtgorkIrc5jgBG8VKgZ4/7APdaEnKQ7MMMMh8rQKgFo7J2hpWolyjjxvJ1YM8P/gRcNfWFtAKZHEVuWAq0te5Xe96VD3/DYPIISmua/S3i6rD53VL6TxtmsTvCdF0q4pXrx/a44XHiAPywKuv+E8IFr7oKuBng/U4t/x8M59dF4qC7jxkn2/N1U8bKPTG+wrLt+NE84bhB/re4wAD3O/CJHXym4eSzEFNvOS0NvMXoXadHlA4+k1Q59avJ9+q5WLy6xjFWq+LQh9jhQj7Ou4Ux5AWhg5Ldh0b6/a0MqYg05l6HgNYx8UcoZsRjk8dU5qzotsJQ4aYwvUnej8qk5NPC3RwrZfxrNMO71DEkWwP/8lpYsyB2JsvFTrc1F2os9zy9hJA9i7LYa/Fpr5V8uwbEj+4oVxea9OWQW5LSNVBhBsI/rTEq3RJxBhdH1Wd1fguSYdmzr00x2YoC0tI4H6Nv9qL7o0JRmv6dtekzVNU/jR4fGCkz81zf7vk9SRWBn8pvmJtQRucUin3tOuEdt3zpa+gT5n6rwhydbVm7Pq8+WY9T7jbLE/IfYr6c2IIDyTXdMy6xoyuNGb8Dhe+DsnJVo8nnRbLTPDFtNCkhbmA/5TAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAODEAf8AjIbLgSYY+/AAAAAASUVORK5CYII="
23
-
24
- export const WALLET_CONNECT_SAFE_WALLET_ID =
25
- "225affb176778569276e484e1b92637ad061b01e13a048b35a9d280c3b58970f"
@@ -1,36 +1,20 @@
1
1
  import { useQuery } from "@tanstack/react-query"
2
- import { useReadContract } from "wagmi"
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
- 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
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
- const age = Date.now() - Number(updatedAt) * 1000
47
+ const tPrice = parseUnits(tTokenConversionRate, CONVERSION_RATE_DECIMALS)
48
+ const btcPrice = normalizePrecision(
49
+ btcConversionRate,
50
+ CONVERSION_RATE_DECIMALS,
51
+ )
58
52
 
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
- },
53
+ return {
54
+ rates: {
55
+ mT: tPrice,
56
+ BTC: btcPrice,
57
+ },
58
+ decimals: CONVERSION_RATE_DECIMALS,
59
+ }
70
60
  },
71
- chainId: CHAIN_ID[environment],
72
- })
61
+ refetchInterval: ({ state }) => {
62
+ if (!state.data) return MAX_PRICE_DELAY
73
63
 
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
- })
64
+ const [, btcPriceData] = state.data
65
+ const [, , , updatedAt] = btcPriceData
66
+
67
+ if (!updatedAt) return MAX_PRICE_DELAY
82
68
 
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
- },
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
- isPending: tPrice.isPending || btcPrice.isPending,
95
- isError: tPrice.isError || btcPrice.isError,
96
- }
78
+ })
97
79
  }
@@ -23,10 +23,12 @@ function useAuthenticateWithWallet(
23
23
  > = {},
24
24
  ) {
25
25
  const {
26
- walletAddress,
27
- chainId: walletChainId,
28
- connector,
29
- networkFamily,
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({