@mezo-org/passport 0.4.0-dev.2 → 0.4.0-dev.20

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 (263) hide show
  1. package/dist/src/api/auth.d.ts +57 -52
  2. package/dist/src/api/auth.d.ts.map +1 -1
  3. package/dist/src/api/auth.js +22 -53
  4. package/dist/src/api/auth.js.map +1 -1
  5. package/dist/src/api/client.d.ts +24 -0
  6. package/dist/src/api/client.d.ts.map +1 -0
  7. package/dist/src/api/client.js +54 -0
  8. package/dist/src/api/client.js.map +1 -0
  9. package/dist/src/api/fetch-error.d.ts +5 -0
  10. package/dist/src/api/fetch-error.d.ts.map +1 -0
  11. package/dist/src/api/fetch-error.js +8 -0
  12. package/dist/src/api/fetch-error.js.map +1 -0
  13. package/dist/src/api/index.d.ts +3 -0
  14. package/dist/src/api/index.d.ts.map +1 -0
  15. package/dist/src/api/index.js +3 -0
  16. package/dist/src/api/index.js.map +1 -0
  17. package/dist/src/api/portal.d.ts +32 -0
  18. package/dist/src/api/portal.d.ts.map +1 -0
  19. package/dist/src/api/portal.js +23 -0
  20. package/dist/src/api/portal.js.map +1 -0
  21. package/dist/src/assets/DefaultAvatar.d.ts +5 -0
  22. package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
  23. package/dist/src/assets/DefaultAvatar.js +21 -0
  24. package/dist/src/assets/DefaultAvatar.js.map +1 -0
  25. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +8 -0
  26. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
  27. package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
  28. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
  29. package/dist/src/components/Dropdown/Content.d.ts +9 -0
  30. package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/Content.js +25 -0
  32. package/dist/src/components/Dropdown/Content.js.map +1 -0
  33. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
  34. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
  36. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
  37. package/dist/src/components/Dropdown/Dropdown.d.ts +27 -0
  38. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Dropdown.js +64 -0
  40. package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
  41. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
  42. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
  44. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  45. package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
  46. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
  48. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  49. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
  50. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
  52. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  53. package/dist/src/components/Dropdown/Root/AccountAssets.d.ts +13 -0
  54. package/dist/src/components/Dropdown/Root/AccountAssets.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/Root/AccountAssets.js +43 -0
  56. package/dist/src/components/Dropdown/Root/AccountAssets.js.map +1 -0
  57. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +7 -0
  58. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/Root/AccountBalance.js +16 -0
  60. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  61. package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
  62. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  63. package/dist/src/components/Dropdown/Root/Root.js +64 -0
  64. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  65. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
  66. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  67. package/dist/src/components/Dropdown/Root/WalletAddress.js +65 -0
  68. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  69. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +8 -0
  70. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  71. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +43 -0
  72. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  73. package/dist/src/components/Dropdown/index.d.ts +3 -0
  74. package/dist/src/components/Dropdown/index.d.ts.map +1 -0
  75. package/dist/src/components/Dropdown/index.js +2 -0
  76. package/dist/src/components/Dropdown/index.js.map +1 -0
  77. package/dist/src/components/index.d.ts +2 -0
  78. package/dist/src/components/index.d.ts.map +1 -0
  79. package/dist/src/components/index.js +2 -0
  80. package/dist/src/components/index.js.map +1 -0
  81. package/dist/src/hooks/constants.d.ts +3 -3
  82. package/dist/src/hooks/constants.js +4 -4
  83. package/dist/src/hooks/constants.js.map +1 -1
  84. package/dist/src/hooks/index.d.ts +2 -4
  85. package/dist/src/hooks/index.d.ts.map +1 -1
  86. package/dist/src/hooks/index.js +2 -4
  87. package/dist/src/hooks/index.js.map +1 -1
  88. package/dist/src/hooks/useAssetsUSDConversion.d.ts +8 -0
  89. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +1 -0
  90. package/dist/src/hooks/useAssetsUSDConversion.js +21 -0
  91. package/dist/src/hooks/useAssetsUSDConversion.js.map +1 -0
  92. package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
  93. package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
  94. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +73 -0
  95. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -0
  96. package/dist/src/hooks/useAuthenticateWithWallet.js +69 -0
  97. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -0
  98. package/dist/src/hooks/useCreateAccount.d.ts +41 -137
  99. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  100. package/dist/src/hooks/useCreateAccount.js +8 -10
  101. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  102. package/dist/src/hooks/useCreateSession.d.ts +12 -182
  103. package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
  104. package/dist/src/hooks/useCreateSession.js +12 -18
  105. package/dist/src/hooks/useCreateSession.js.map +1 -1
  106. package/dist/src/hooks/useDropdownData.d.ts +45 -0
  107. package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
  108. package/dist/src/hooks/useDropdownData.js +80 -0
  109. package/dist/src/hooks/useDropdownData.js.map +1 -0
  110. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts +5 -0
  111. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -0
  112. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +34 -0
  113. package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -0
  114. package/dist/src/hooks/useGetAccountByAddress.d.ts +3 -5
  115. package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
  116. package/dist/src/hooks/useGetAccountByAddress.js +3 -4
  117. package/dist/src/hooks/useGetAccountByAddress.js.map +1 -1
  118. package/dist/src/hooks/useGetAccountByMezoId.d.ts +3 -5
  119. package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
  120. package/dist/src/hooks/useGetAccountByMezoId.js +3 -4
  121. package/dist/src/hooks/useGetAccountByMezoId.js.map +1 -1
  122. package/dist/src/hooks/useGetCurrentAccount.d.ts +14 -8
  123. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  124. package/dist/src/hooks/useGetCurrentAccount.js +28 -6
  125. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  126. package/dist/src/hooks/useGetSession.d.ts +3 -20
  127. package/dist/src/hooks/useGetSession.d.ts.map +1 -1
  128. package/dist/src/hooks/useGetSession.js +2 -2
  129. package/dist/src/hooks/useGetSession.js.map +1 -1
  130. package/dist/src/hooks/useLinkAccount.d.ts +15 -121
  131. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  132. package/dist/src/hooks/useLinkAccount.js +8 -21
  133. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  134. package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
  135. package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
  136. package/dist/src/hooks/usePortalApiClient.js +6 -0
  137. package/dist/src/hooks/usePortalApiClient.js.map +1 -0
  138. package/dist/src/hooks/useRefreshPassport.d.ts +17 -0
  139. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  140. package/dist/src/hooks/useRefreshPassport.js +29 -0
  141. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  142. package/dist/src/hooks/useSignInWithDiscord.d.ts +12 -181
  143. package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
  144. package/dist/src/hooks/useSignInWithDiscord.js +11 -22
  145. package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
  146. package/dist/src/hooks/useSignInWithWallet.d.ts +12 -181
  147. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  148. package/dist/src/hooks/useSignInWithWallet.js +6 -44
  149. package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
  150. package/dist/src/hooks/useSignOut.d.ts +12 -28
  151. package/dist/src/hooks/useSignOut.d.ts.map +1 -1
  152. package/dist/src/hooks/useSignOut.js +11 -6
  153. package/dist/src/hooks/useSignOut.js.map +1 -1
  154. package/dist/src/hooks/useSignUpWithWallet.d.ts +73 -0
  155. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -0
  156. package/dist/src/hooks/useSignUpWithWallet.js +11 -0
  157. package/dist/src/hooks/useSignUpWithWallet.js.map +1 -0
  158. package/dist/src/hooks/useUpdateMezoId.d.ts +30 -82
  159. package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
  160. package/dist/src/hooks/useUpdateMezoId.js +8 -12
  161. package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
  162. package/dist/src/hooks/useWalletAccount.d.ts +12 -0
  163. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
  164. package/dist/src/hooks/useWalletAccount.js +28 -0
  165. package/dist/src/hooks/useWalletAccount.js.map +1 -0
  166. package/dist/src/index.d.ts +1 -0
  167. package/dist/src/index.d.ts.map +1 -1
  168. package/dist/src/index.js +1 -0
  169. package/dist/src/index.js.map +1 -1
  170. package/dist/src/provider.d.ts +10 -13
  171. package/dist/src/provider.d.ts.map +1 -1
  172. package/dist/src/provider.js +11 -20
  173. package/dist/src/provider.js.map +1 -1
  174. package/dist/src/stores/dropdownStore.d.ts +12 -0
  175. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  176. package/dist/src/stores/dropdownStore.js +13 -0
  177. package/dist/src/stores/dropdownStore.js.map +1 -0
  178. package/dist/src/utils/address.d.ts +15 -0
  179. package/dist/src/utils/address.d.ts.map +1 -0
  180. package/dist/src/utils/address.js +37 -0
  181. package/dist/src/utils/address.js.map +1 -0
  182. package/dist/src/utils/address.test.d.ts +2 -0
  183. package/dist/src/utils/address.test.d.ts.map +1 -0
  184. package/dist/src/utils/address.test.js +40 -0
  185. package/dist/src/utils/address.test.js.map +1 -0
  186. package/dist/src/utils/cryptoAssets.d.ts +28 -0
  187. package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
  188. package/dist/src/utils/cryptoAssets.js +73 -0
  189. package/dist/src/utils/cryptoAssets.js.map +1 -0
  190. package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
  191. package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
  192. package/dist/src/utils/cryptoAssets.test.js +50 -0
  193. package/dist/src/utils/cryptoAssets.test.js.map +1 -0
  194. package/dist/src/utils/currency.d.ts +14 -0
  195. package/dist/src/utils/currency.d.ts.map +1 -0
  196. package/dist/src/utils/currency.js +27 -0
  197. package/dist/src/utils/currency.js.map +1 -0
  198. package/dist/src/utils/currency.test.d.ts +2 -0
  199. package/dist/src/utils/currency.test.d.ts.map +1 -0
  200. package/dist/src/utils/currency.test.js +34 -0
  201. package/dist/src/utils/currency.test.js.map +1 -0
  202. package/dist/src/utils/numbers.d.ts +45 -0
  203. package/dist/src/utils/numbers.d.ts.map +1 -0
  204. package/dist/src/utils/numbers.js +86 -0
  205. package/dist/src/utils/numbers.js.map +1 -0
  206. package/dist/src/utils/numbers.test.d.ts +2 -0
  207. package/dist/src/utils/numbers.test.d.ts.map +1 -0
  208. package/dist/src/utils/numbers.test.js +170 -0
  209. package/dist/src/utils/numbers.test.js.map +1 -0
  210. package/package.json +10 -4
  211. package/src/api/auth.ts +104 -129
  212. package/src/api/client.ts +78 -0
  213. package/src/api/fetch-error.ts +8 -0
  214. package/src/api/index.ts +2 -0
  215. package/src/api/portal.ts +56 -0
  216. package/src/assets/DefaultAvatar.tsx +74 -0
  217. package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
  218. package/src/components/Dropdown/Content.tsx +62 -0
  219. package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
  220. package/src/components/Dropdown/Dropdown.tsx +124 -0
  221. package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
  222. package/src/components/Dropdown/README.md +55 -0
  223. package/src/components/Dropdown/Receive/Receive.tsx +119 -0
  224. package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
  225. package/src/components/Dropdown/Root/AccountAssets.tsx +108 -0
  226. package/src/components/Dropdown/Root/AccountBalance.tsx +35 -0
  227. package/src/components/Dropdown/Root/Root.tsx +141 -0
  228. package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
  229. package/src/components/Dropdown/Root/WelcomeBlock.tsx +91 -0
  230. package/src/components/Dropdown/index.ts +2 -0
  231. package/src/components/index.ts +1 -0
  232. package/src/hooks/constants.ts +4 -4
  233. package/src/hooks/index.ts +2 -4
  234. package/src/hooks/useAssetsUSDConversion.ts +31 -0
  235. package/src/hooks/useAuthenticateWithWallet.ts +98 -0
  236. package/src/hooks/useCreateAccount.ts +20 -11
  237. package/src/hooks/useCreateSession.ts +24 -18
  238. package/src/hooks/useDropdownData.ts +160 -0
  239. package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +46 -0
  240. package/src/hooks/useGetAccountByAddress.ts +11 -5
  241. package/src/hooks/useGetAccountByMezoId.ts +11 -5
  242. package/src/hooks/useGetCurrentAccount.ts +53 -7
  243. package/src/hooks/useGetSession.ts +10 -3
  244. package/src/hooks/useLinkAccount.ts +19 -31
  245. package/src/hooks/usePortalApiClient.ts +6 -0
  246. package/src/hooks/useRefreshPassport.ts +40 -0
  247. package/src/hooks/useSignInWithDiscord.ts +19 -28
  248. package/src/hooks/useSignInWithWallet.ts +14 -55
  249. package/src/hooks/useSignOut.ts +22 -6
  250. package/src/hooks/useSignUpWithWallet.ts +21 -0
  251. package/src/hooks/useUpdateMezoId.ts +20 -12
  252. package/src/hooks/useWalletAccount.ts +53 -0
  253. package/src/index.ts +1 -0
  254. package/src/provider.ts +30 -37
  255. package/src/stores/dropdownStore.ts +20 -0
  256. package/src/utils/address.test.ts +48 -0
  257. package/src/utils/address.ts +45 -0
  258. package/src/utils/cryptoAssets.test.ts +61 -0
  259. package/src/utils/cryptoAssets.ts +93 -0
  260. package/src/utils/currency.test.ts +38 -0
  261. package/src/utils/currency.ts +32 -0
  262. package/src/utils/numbers.test.ts +220 -0
  263. package/src/utils/numbers.ts +120 -0
@@ -0,0 +1,141 @@
1
+ import {
2
+ Block,
3
+ Button,
4
+ LogOut01,
5
+ Mats,
6
+ ParagraphSmall,
7
+ useStyletron,
8
+ } from "@mezo-org/mezo-clay"
9
+ import React, { useCallback } from "react"
10
+ import { useDisconnect } from "wagmi"
11
+ import { useSignOut } from "../../../hooks"
12
+ import { DropdownData } from "../../../hooks/useDropdownData"
13
+ import WalletAddress from "./WalletAddress"
14
+ import AccountAssets from "./AccountAssets"
15
+ import AccountBalance from "./AccountBalance"
16
+ import WelcomeBlock from "./WelcomeBlock"
17
+ import AccountAddressActions from "./AccountAddressActions"
18
+
19
+ function MatsnetLabel() {
20
+ const [, theme] = useStyletron()
21
+ return (
22
+ <ParagraphSmall color={theme.colors.contentTertiary}>
23
+ <Mats
24
+ color="currentColor"
25
+ size={theme.sizing.scale400}
26
+ overrides={{
27
+ Svg: {
28
+ style: {
29
+ marginRight: theme.sizing.scale300,
30
+ },
31
+ },
32
+ }}
33
+ />
34
+ Matsnet Assets
35
+ </ParagraphSmall>
36
+ )
37
+ }
38
+
39
+ type RootProps = DropdownData & {
40
+ onSignOut?: () => void
41
+ }
42
+
43
+ export default function Root(props: RootProps) {
44
+ const {
45
+ mezoId,
46
+ walletAddress,
47
+ accountAddress,
48
+ walletType,
49
+ totalBalanceInUsd,
50
+ formattedNativeAssets,
51
+ matsnet,
52
+ onSignOut,
53
+ } = props
54
+
55
+ const [, theme] = useStyletron()
56
+
57
+ const { disconnect } = useDisconnect()
58
+ const { signOut } = useSignOut()
59
+
60
+ const handleLogOut = useCallback(() => {
61
+ if (onSignOut) {
62
+ onSignOut()
63
+ return
64
+ }
65
+
66
+ signOut()
67
+ disconnect()
68
+ }, [signOut, disconnect, onSignOut])
69
+
70
+ return (
71
+ <Block
72
+ display="inline-flex"
73
+ flexDirection="column"
74
+ padding={theme.sizing.scale600}
75
+ >
76
+ <WelcomeBlock mezoId={mezoId} matsBalance={matsnet.mats} />
77
+
78
+ <AccountAddressActions address={accountAddress} />
79
+
80
+ <Block
81
+ display="flex"
82
+ flexDirection="column"
83
+ backgroundColor={theme.colors.backgroundSecondary}
84
+ overflow="hidden"
85
+ overrides={{
86
+ Block: { style: { borderRadius: theme.borders.radius300 } },
87
+ }}
88
+ >
89
+ <WalletAddress address={walletAddress} type={walletType} />
90
+
91
+ <AccountBalance amount={totalBalanceInUsd} />
92
+
93
+ <AccountAssets label="Assets" assets={formattedNativeAssets} />
94
+ </Block>
95
+
96
+ {matsnet.formattedAssets.length > 0 && (
97
+ <Block
98
+ marginTop={theme.sizing.scale600}
99
+ backgroundColor={theme.colors.backgroundSecondary}
100
+ overflow="hidden"
101
+ overrides={{
102
+ Block: { style: { borderRadius: theme.borders.radius300 } },
103
+ }}
104
+ >
105
+ <AccountAssets
106
+ label={<MatsnetLabel />}
107
+ assets={matsnet.formattedAssets}
108
+ />
109
+ </Block>
110
+ )}
111
+
112
+ <Block
113
+ marginTop={theme.sizing.scale700}
114
+ padding={`0 ${theme.sizing.scale100}`}
115
+ >
116
+ <Button
117
+ size="small"
118
+ kind="tertiary"
119
+ startEnhancer={<LogOut01 color="currentColor" size={12} />}
120
+ onClick={() => handleLogOut()}
121
+ overrides={{
122
+ Root: {
123
+ style: {
124
+ ":hover": {
125
+ backgroundColor: theme.colors.backgroundSecondary,
126
+ boxShadow: "none",
127
+ },
128
+ ":active": {
129
+ backgroundColor: theme.colors.backgroundSecondary,
130
+ color: theme.colors.contentPrimary,
131
+ },
132
+ },
133
+ },
134
+ }}
135
+ >
136
+ Log out
137
+ </Button>
138
+ </Block>
139
+ </Block>
140
+ )
141
+ }
@@ -0,0 +1,128 @@
1
+ import {
2
+ Block,
3
+ Copy03 as CopyIcon,
4
+ LinkExternal02 as LinkIcon,
5
+ ParagraphSmall,
6
+ useStyletron,
7
+ } from "@mezo-org/mezo-clay"
8
+ import React, { useCallback, useState } from "react"
9
+ import { useCopyToClipboard } from "usehooks-ts"
10
+ import { usePassportContext } from "../../../hooks/usePassportContext"
11
+ import { getAddressExplorerUrl, trimAddress } from "../../../utils/address"
12
+ import { getCryptoAsset } from "../../../utils/cryptoAssets"
13
+
14
+ type WalletAddressProps = {
15
+ address: string
16
+ type: "bitcoin" | "evm"
17
+ }
18
+
19
+ export default function WalletAddress(props: WalletAddressProps) {
20
+ const { address, type } = props
21
+
22
+ const { environment } = usePassportContext()
23
+ const blockExplorerUrl = getAddressExplorerUrl(
24
+ address,
25
+ type,
26
+ environment === "testnet",
27
+ )
28
+ const trimmedAddress = trimAddress(address)
29
+ const { icon: accountIcon } = getCryptoAsset(
30
+ type === "bitcoin" ? "btc" : "eth",
31
+ )
32
+
33
+ const [, theme] = useStyletron()
34
+
35
+ const [, copy] = useCopyToClipboard()
36
+ const [isCopiedMessageVisible, setIsCopiedMessageVisible] = useState(false)
37
+ const handleCopyAddress = useCallback(() => {
38
+ copy(address)
39
+ setIsCopiedMessageVisible(true)
40
+
41
+ setTimeout(() => {
42
+ setIsCopiedMessageVisible(false)
43
+ }, 2000)
44
+ }, [copy, address])
45
+
46
+ return (
47
+ <Block
48
+ as="button"
49
+ onClick={handleCopyAddress}
50
+ display="flex"
51
+ alignItems="center"
52
+ backgroundColor="transparent"
53
+ padding={`${theme.sizing.scale600} ${theme.sizing.scale500}`}
54
+ overrides={{
55
+ Block: {
56
+ style: {
57
+ borderWidth: 0,
58
+ cursor: "pointer",
59
+ ":hover": {
60
+ backgroundColor: theme.colors.backgroundTertiary,
61
+ },
62
+ },
63
+ },
64
+ }}
65
+ >
66
+ <Block as={accountIcon} size={theme.sizing.scale600} />
67
+ {isCopiedMessageVisible ? (
68
+ <ParagraphSmall
69
+ margin={0}
70
+ marginLeft={theme.sizing.scale300}
71
+ color={theme.colors.gray800}
72
+ >
73
+ Copied address to clipboard
74
+ </ParagraphSmall>
75
+ ) : (
76
+ <Block
77
+ as="a"
78
+ marginLeft={theme.sizing.scale300}
79
+ href={blockExplorerUrl}
80
+ target="_blank"
81
+ overrides={{
82
+ Block: {
83
+ style: {
84
+ color: "inherit",
85
+ textDecoration: "none",
86
+ ":hover": {
87
+ textDecoration: "underline",
88
+ },
89
+ },
90
+ },
91
+ }}
92
+ >
93
+ <ParagraphSmall
94
+ display="flex"
95
+ alignItems="center"
96
+ margin={0}
97
+ color={theme.colors.gray800}
98
+ >
99
+ {trimmedAddress}
100
+ <LinkIcon
101
+ display="inline"
102
+ size={theme.sizing.scale550}
103
+ overrides={{
104
+ Svg: {
105
+ style: {
106
+ stroke: "currentColor",
107
+ marginLeft: theme.sizing.scale200,
108
+ },
109
+ },
110
+ }}
111
+ />
112
+ </ParagraphSmall>
113
+ </Block>
114
+ )}
115
+ <CopyIcon
116
+ size={theme.sizing.scale550}
117
+ overrides={{
118
+ Svg: {
119
+ style: {
120
+ marginLeft: "auto",
121
+ stroke: "currentColor",
122
+ },
123
+ },
124
+ }}
125
+ />
126
+ </Block>
127
+ )
128
+ }
@@ -0,0 +1,91 @@
1
+ import {
2
+ Block,
3
+ HeadingSmall,
4
+ LabelSmall,
5
+ Mats,
6
+ useStyletron,
7
+ } from "@mezo-org/mezo-clay"
8
+ import React from "react"
9
+ import DefaultAvatar from "../../../assets/DefaultAvatar"
10
+
11
+ const DOT_DELIMITER_REGEX = /(?=\.)/
12
+
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)
22
+ const [, theme] = useStyletron()
23
+
24
+ return (
25
+ <Block
26
+ display="flex"
27
+ alignItems="center"
28
+ padding={`${theme.sizing.scale600} 0`}
29
+ marginBottom={theme.sizing.scale300}
30
+ overrides={{
31
+ Block: {
32
+ style: {
33
+ gap: theme.sizing.scale600,
34
+ },
35
+ },
36
+ }}
37
+ >
38
+ <Block
39
+ as={DefaultAvatar}
40
+ width={theme.sizing.scale1200}
41
+ height={theme.sizing.scale1200}
42
+ overrides={{
43
+ Block: {
44
+ style: {
45
+ borderRadius: "100%",
46
+ },
47
+ },
48
+ }}
49
+ />
50
+
51
+ <Block
52
+ display="flex"
53
+ flexDirection="column"
54
+ overrides={{
55
+ Block: {
56
+ style: {
57
+ gap: theme.sizing.scale100,
58
+ },
59
+ },
60
+ }}
61
+ >
62
+ <HeadingSmall as="span">
63
+ <Block as="span">{name}</Block>
64
+ <Block as="span" color={theme.colors.gray500}>
65
+ {nameSuffix}
66
+ </Block>
67
+ </HeadingSmall>
68
+
69
+ <LabelSmall
70
+ display="flex"
71
+ alignItems="center"
72
+ margin={0}
73
+ color={theme.colors.contentTertiary}
74
+ overrides={{
75
+ Block: {
76
+ style: {
77
+ gap: theme.sizing.scale300,
78
+ },
79
+ },
80
+ }}
81
+ >
82
+ <Mats
83
+ color={theme.colors.contentPrimary}
84
+ size={theme.sizing.scale600}
85
+ />
86
+ {matsBalance}
87
+ </LabelSmall>
88
+ </Block>
89
+ </Block>
90
+ )
91
+ }
@@ -0,0 +1,2 @@
1
+ export { Dropdown } from "./Dropdown"
2
+ export type { DropdownProps } from "./Dropdown"
@@ -0,0 +1 @@
1
+ export { Dropdown, DropdownProps } from "./Dropdown"
@@ -1,6 +1,6 @@
1
1
  export const QUERY_KEYS = {
2
- ACCOUNT_BY_ADDRESS: "getAccountByAddress",
3
- ACCOUNT_BY_MEZO_ID: "getAccountByMezoId",
4
- SESSION: "getSession",
5
- CURRENT_ACCOUNT: "getCurrentAccount",
2
+ ACCOUNT: "account",
3
+ SESSION: "session",
4
+ CURRENT: "current",
5
+ ASSETS_USD_CONVERSION: "assetsUsdConversion",
6
6
  }
@@ -6,16 +6,14 @@ export {
6
6
  useSubscribeToConnectorEvent,
7
7
  useSubscribeToWalletNetworkDoesNotMatchProviderChain,
8
8
  } from "@mezo-org/orangekit"
9
- export * from "./constants"
10
- export * from "./useAuthApiClient"
11
- export * from "./useCreateAccount"
12
9
  export * from "./useGetAccountByAddress"
13
10
  export * from "./useGetAccountByMezoId"
14
11
  export * from "./useGetCurrentAccount"
15
12
  export * from "./useGetSession"
16
13
  export * from "./useLinkAccount"
17
- export * from "./usePassportContext"
18
14
  export * from "./useSignInWithDiscord"
19
15
  export * from "./useSignInWithWallet"
20
16
  export * from "./useSignOut"
17
+ export * from "./useSignUpWithWallet"
21
18
  export * from "./useUpdateMezoId"
19
+ export * from "./useRefreshPassport"
@@ -0,0 +1,31 @@
1
+ import { UseBaseQueryOptions, useQuery } from "@tanstack/react-query"
2
+ import { ONE_MINUTE_MS } from "../utils/time"
3
+ import { QUERY_KEYS } from "./constants"
4
+ import { usePortalApiClient } from "./usePortalApiClient"
5
+
6
+ type AssetsUsdConversion = {
7
+ btcUsd: string
8
+ ethUsd: string
9
+ }
10
+
11
+ export function useAssetsUsdConversion(
12
+ useQueryOptions: Partial<UseBaseQueryOptions<AssetsUsdConversion>> = {},
13
+ ) {
14
+ const portalApiClient = usePortalApiClient()
15
+
16
+ return useQuery({
17
+ queryKey: [QUERY_KEYS.ASSETS_USD_CONVERSION],
18
+ queryFn: async () => {
19
+ const { currentUsdPerBtc, currentUsdPerEth } =
20
+ await portalApiClient.getPortalStatistics()
21
+
22
+ return {
23
+ btcUsd: currentUsdPerBtc,
24
+ ethUsd: currentUsdPerEth,
25
+ }
26
+ },
27
+ staleTime: 30 * ONE_MINUTE_MS,
28
+ retry: 1,
29
+ ...useQueryOptions,
30
+ })
31
+ }
@@ -0,0 +1,98 @@
1
+ import { useSignMessage } from "wagmi"
2
+ import { MutationOptions, useMutation } from "@tanstack/react-query"
3
+ import { useCreateAccount } from "./useCreateAccount"
4
+ import { useCreateSession } from "./useCreateSession"
5
+ import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce"
6
+ import { createSignInWithWalletMessage } from "../utils/siww"
7
+ import { useGetAccountByAddress } from "./useGetAccountByAddress"
8
+ import type { Session } from "../api"
9
+ import useWalletAccount from "./useWalletAccount"
10
+
11
+ function useAuthenticateWithWallet(
12
+ shouldCreateAccount = false,
13
+ mutationOptions: Omit<
14
+ MutationOptions<Session>,
15
+ "mutationFn" | "mutationKey"
16
+ > = {},
17
+ ) {
18
+ const { address, chainId, connector, networkFamily } = useWalletAccount()
19
+ const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce()
20
+ const { createSessionAsync } = useCreateSession()
21
+ const { createAccountAsync } = useCreateAccount()
22
+ const { signMessageAsync } = useSignMessage()
23
+
24
+ const { refetch: getAccountByAddress } = useGetAccountByAddress(address, {
25
+ enabled: false,
26
+ retry: false,
27
+ })
28
+
29
+ const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
30
+ mutationFn: async () => {
31
+ if (!address) {
32
+ throw new Error("Sign in error: Wallet not connected!")
33
+ }
34
+
35
+ const nonce = await ensureNoSessionAndFetchNonce()
36
+
37
+ const messageResult = createSignInWithWalletMessage(
38
+ address,
39
+ nonce,
40
+ networkFamily,
41
+ chainId,
42
+ )
43
+ const signatureResult = await signMessageAsync({
44
+ message: messageResult,
45
+ connector,
46
+ })
47
+
48
+ if (shouldCreateAccount) {
49
+ const getAccountByAddressResult = await getAccountByAddress()
50
+
51
+ if (getAccountByAddressResult.data) {
52
+ throw new Error(
53
+ "Wallet authentication failed: Account creation failed. Account already exists.",
54
+ )
55
+ }
56
+
57
+ if (getAccountByAddressResult.error) {
58
+ throw new Error(
59
+ `Wallet authentication failed: Account creation failed. Could not verify if account already exists: ${getAccountByAddressResult.error}`,
60
+ )
61
+ }
62
+
63
+ // Fetch was successful, but no account was found
64
+ try {
65
+ const createAccountResult = await createAccountAsync({
66
+ type: "wallet",
67
+ message: messageResult,
68
+ signature: signatureResult,
69
+ })
70
+
71
+ if (!createAccountResult) {
72
+ throw new Error("Failed to create new account")
73
+ }
74
+ } catch (error) {
75
+ throw new Error(
76
+ `Wallet authentication failed: Account creation failed: ${error}`,
77
+ )
78
+ }
79
+ }
80
+
81
+ return (await createSessionAsync({
82
+ type: "wallet",
83
+ message: messageResult,
84
+ signature: signatureResult,
85
+ })) as Session
86
+ // ^ By passing type: "wallet" we know for sure the return type is Session
87
+ },
88
+ ...mutationOptions,
89
+ })
90
+
91
+ return {
92
+ authenticateWithWallet: mutate,
93
+ authenticateWithWalletAsync: mutateAsync,
94
+ ...signInMutationRestParameters,
95
+ }
96
+ }
97
+
98
+ export { useAuthenticateWithWallet }
@@ -1,26 +1,35 @@
1
- import { useQueryClient, useMutation } from "@tanstack/react-query"
1
+ import {
2
+ useQueryClient,
3
+ useMutation,
4
+ MutationOptions,
5
+ DefaultError,
6
+ } from "@tanstack/react-query"
2
7
  import { useAuthApiClient } from "./useAuthApiClient"
3
8
  import { QUERY_KEYS } from "./constants"
4
- import { CreateAccountRequest } from "../api/auth"
9
+ import type { CreateAccountRequest, CreateAccountResponse } from "../api"
5
10
 
6
- export function useCreateAccount(useMutationOptions = {}) {
11
+ export function useCreateAccount(
12
+ mutationOptions: Omit<
13
+ MutationOptions<CreateAccountResponse, DefaultError, CreateAccountRequest>,
14
+ "mutationFn" | "mutationKey"
15
+ > = {},
16
+ ) {
7
17
  const queryClient = useQueryClient()
8
18
  const authApiClient = useAuthApiClient()
9
19
 
20
+ const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
21
+
10
22
  const { mutate, mutateAsync, ...rest } = useMutation({
11
23
  mutationFn: (createAccountRequest: CreateAccountRequest) =>
12
24
  authApiClient.createAccount(createAccountRequest),
13
- onSuccess: () => {
14
- queryClient.resetQueries({
15
- queryKey: [QUERY_KEYS.ACCOUNT_BY_ADDRESS],
16
- exact: false,
17
- })
25
+ onSuccess: (data, variables, context) => {
18
26
  queryClient.resetQueries({
19
- queryKey: [QUERY_KEYS.ACCOUNT_BY_MEZO_ID],
20
- exact: false,
27
+ queryKey: [QUERY_KEYS.ACCOUNT],
21
28
  })
29
+
30
+ if (customOnSuccess) customOnSuccess(data, variables, context)
22
31
  },
23
- ...useMutationOptions,
32
+ ...restMutationOptions,
24
33
  })
25
34
 
26
35
  return { createAccount: mutate, createAccountAsync: mutateAsync, ...rest }
@@ -1,37 +1,43 @@
1
- import { useQueryClient, useMutation } from "@tanstack/react-query"
1
+ import {
2
+ useQueryClient,
3
+ useMutation,
4
+ MutationOptions,
5
+ DefaultError,
6
+ } from "@tanstack/react-query"
2
7
  import { useAuthApiClient } from "./useAuthApiClient"
3
- import { CreateSessionRequest } from "../api/auth"
8
+ import type { CreateSessionRequest, CreateSessionResponse } from "../api"
4
9
  import { QUERY_KEYS } from "./constants"
5
10
 
6
11
  /**
7
12
  * This hook is not exposed for external consumers. For creating session they
8
13
  * should use `useSignIn` hook related to the authentication method.
9
14
  */
10
- export function useCreateSession(useMutationOptions = {}) {
15
+ export function useCreateSession(
16
+ mutationOptions: Omit<
17
+ MutationOptions<CreateSessionResponse, DefaultError, CreateSessionRequest>,
18
+ "mutationFn" | "mutationKey"
19
+ > = {},
20
+ ) {
11
21
  const queryClient = useQueryClient()
12
22
  const authApiClient = useAuthApiClient()
13
23
 
24
+ const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
25
+
14
26
  const { mutate, mutateAsync, ...rest } = useMutation({
15
27
  mutationFn: (createSessionRequest: CreateSessionRequest) =>
16
28
  authApiClient.createSession(createSessionRequest),
17
- onSuccess: (data) => {
18
- // Since `getSession` query also has code in it's query keys we can't
19
- // set query data for a specific query, because we don't know if the
20
- // code was used or not. Because of that we just reset all getSession
21
- // queries
29
+ onSuccess: (data, variables, context) => {
30
+ // Since `getSession` query also has code in its query keys we can't set
31
+ // query data for a specific query, because we don't know if the code was
32
+ // used or not. Because of that we just reset all getSession queries
33
+ queryClient.resetQueries({ queryKey: [QUERY_KEYS.SESSION] })
22
34
  queryClient.resetQueries({
23
- queryKey: [QUERY_KEYS.SESSION],
24
- exact: false,
35
+ queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
25
36
  })
26
- if ("user" in data) {
27
- queryClient.setQueryData([QUERY_KEYS.CURRENT_ACCOUNT], data.user)
28
- } else {
29
- queryClient.resetQueries({
30
- queryKey: [QUERY_KEYS.CURRENT_ACCOUNT],
31
- })
32
- }
37
+
38
+ if (customOnSuccess) customOnSuccess(data, variables, context)
33
39
  },
34
- ...useMutationOptions,
40
+ ...restMutationOptions,
35
41
  })
36
42
 
37
43
  return { createSession: mutate, createSessionAsync: mutateAsync, ...rest }