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

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 (262) hide show
  1. package/README.md +18 -22
  2. package/dist/src/api/auth.d.ts +7 -3
  3. package/dist/src/api/auth.d.ts.map +1 -1
  4. package/dist/src/api/auth.js +3 -1
  5. package/dist/src/api/auth.js.map +1 -1
  6. package/dist/src/api/client.d.ts +4 -1
  7. package/dist/src/api/client.d.ts.map +1 -1
  8. package/dist/src/api/client.js +9 -2
  9. package/dist/src/api/client.js.map +1 -1
  10. package/dist/src/api/portal.d.ts +3 -9
  11. package/dist/src/api/portal.d.ts.map +1 -1
  12. package/dist/src/api/portal.js +8 -5
  13. package/dist/src/api/portal.js.map +1 -1
  14. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
  15. package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
  16. package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
  17. package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
  18. package/dist/src/components/Dropdown/Content.d.ts +19 -5
  19. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  20. package/dist/src/components/Dropdown/Content.js +19 -61
  21. package/dist/src/components/Dropdown/Content.js.map +1 -1
  22. package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
  23. package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
  24. package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
  25. package/dist/src/components/Dropdown/Dropdown.d.ts +13 -6
  26. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  27. package/dist/src/components/Dropdown/Dropdown.js +32 -9
  28. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  29. package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
  30. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/ListingItem.js +34 -0
  32. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  33. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
  34. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
  36. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  37. package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
  38. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
  40. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
  42. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
  44. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  45. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
  46. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
  48. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
  49. package/dist/src/components/Dropdown/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
  50. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
  52. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  53. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
  54. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
  56. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  57. package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
  58. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/Root/Root.js +57 -0
  60. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  61. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
  62. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  63. package/dist/src/components/Dropdown/{AccountAddress.js → Root/WalletAddress.js} +21 -15
  64. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  65. package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
  66. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  67. package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
  68. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  69. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  70. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  71. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  72. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  73. package/dist/src/config.d.ts +29 -6
  74. package/dist/src/config.d.ts.map +1 -1
  75. package/dist/src/config.js +88 -15
  76. package/dist/src/config.js.map +1 -1
  77. package/dist/src/constants.d.ts +13 -3
  78. package/dist/src/constants.d.ts.map +1 -1
  79. package/dist/src/constants.js +14 -4
  80. package/dist/src/constants.js.map +1 -1
  81. package/dist/src/hooks/index.d.ts +4 -0
  82. package/dist/src/hooks/index.d.ts.map +1 -1
  83. package/dist/src/hooks/index.js +4 -0
  84. package/dist/src/hooks/index.js.map +1 -1
  85. package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
  86. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  87. package/dist/src/hooks/useAssetsConversionRates.js +90 -0
  88. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  89. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
  90. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  91. package/dist/src/hooks/useAuthenticateWithWallet.js +8 -7
  92. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  93. package/dist/src/hooks/useBorrowData.d.ts +82 -0
  94. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  95. package/dist/src/hooks/useBorrowData.js +159 -0
  96. package/dist/src/hooks/useBorrowData.js.map +1 -0
  97. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  98. package/dist/src/hooks/useCreateAccount.js +22 -1
  99. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  100. package/dist/src/hooks/useDropdownData.d.ts +37 -34
  101. package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
  102. package/dist/src/hooks/useDropdownData.js +85 -61
  103. package/dist/src/hooks/useDropdownData.js.map +1 -1
  104. package/dist/src/hooks/useLinkAccount.d.ts +19 -13
  105. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  106. package/dist/src/hooks/useLinkAccount.js +20 -1
  107. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  108. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  109. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  110. package/dist/src/hooks/useRefreshPassport.js +44 -0
  111. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  112. package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
  113. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  114. package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
  115. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
  116. package/dist/src/hooks/useTokensBalances.d.ts +74 -0
  117. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  118. package/dist/src/hooks/useTokensBalances.js +140 -0
  119. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  120. package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
  121. package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
  122. package/dist/src/hooks/useValidateMezoId.js +24 -0
  123. package/dist/src/hooks/useValidateMezoId.js.map +1 -0
  124. package/dist/src/hooks/useWalletAccount.d.ts +2 -1
  125. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  126. package/dist/src/hooks/useWalletAccount.js +19 -15
  127. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  128. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  129. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  130. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  131. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  132. package/dist/src/index.d.ts +2 -1
  133. package/dist/src/index.d.ts.map +1 -1
  134. package/dist/src/index.js +2 -1
  135. package/dist/src/index.js.map +1 -1
  136. package/dist/src/lib/contracts/index.d.ts +13 -0
  137. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  138. package/dist/src/lib/contracts/index.js +62 -0
  139. package/dist/src/lib/contracts/index.js.map +1 -0
  140. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  141. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  142. package/dist/src/lib/contracts/priceOracle.js +52 -0
  143. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  144. package/dist/src/provider.js +1 -1
  145. package/dist/src/provider.js.map +1 -1
  146. package/dist/src/stores/dropdownStore.d.ts +12 -0
  147. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  148. package/dist/src/stores/dropdownStore.js +13 -0
  149. package/dist/src/stores/dropdownStore.js.map +1 -0
  150. package/dist/src/utils/address.d.ts +1 -1
  151. package/dist/src/utils/address.d.ts.map +1 -1
  152. package/dist/src/utils/address.js +2 -0
  153. package/dist/src/utils/address.js.map +1 -1
  154. package/dist/src/utils/address.test.js +8 -5
  155. package/dist/src/utils/address.test.js.map +1 -1
  156. package/dist/src/utils/cryptoAssets.d.ts +17 -1
  157. package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
  158. package/dist/src/utils/cryptoAssets.js +87 -31
  159. package/dist/src/utils/cryptoAssets.js.map +1 -1
  160. package/dist/src/utils/cryptoAssets.test.js +51 -33
  161. package/dist/src/utils/cryptoAssets.test.js.map +1 -1
  162. package/dist/src/utils/currency.d.ts +8 -0
  163. package/dist/src/utils/currency.d.ts.map +1 -1
  164. package/dist/src/utils/currency.js +11 -0
  165. package/dist/src/utils/currency.js.map +1 -1
  166. package/dist/src/utils/currency.test.js +1 -0
  167. package/dist/src/utils/currency.test.js.map +1 -1
  168. package/dist/src/utils/mezoId.d.ts +7 -0
  169. package/dist/src/utils/mezoId.d.ts.map +1 -0
  170. package/dist/src/utils/mezoId.js +41 -0
  171. package/dist/src/utils/mezoId.js.map +1 -0
  172. package/dist/src/utils/numbers.d.ts +39 -17
  173. package/dist/src/utils/numbers.d.ts.map +1 -1
  174. package/dist/src/utils/numbers.js +91 -33
  175. package/dist/src/utils/numbers.js.map +1 -1
  176. package/dist/src/utils/numbers.test.js +144 -22
  177. package/dist/src/utils/numbers.test.js.map +1 -1
  178. package/dist/src/utils/siww.d.ts +1 -0
  179. package/dist/src/utils/siww.d.ts.map +1 -1
  180. package/dist/src/utils/siww.js +50 -12
  181. package/dist/src/utils/siww.js.map +1 -1
  182. package/dist/src/utils/wagmi.d.ts +3 -0
  183. package/dist/src/utils/wagmi.d.ts.map +1 -0
  184. package/dist/src/utils/wagmi.js +7 -0
  185. package/dist/src/utils/wagmi.js.map +1 -0
  186. package/dist/src/wallet/index.d.ts +1 -1
  187. package/dist/src/wallet/index.d.ts.map +1 -1
  188. package/dist/src/wallet/index.js +1 -1
  189. package/dist/src/wallet/index.js.map +1 -1
  190. package/package.json +10 -8
  191. package/src/api/auth.ts +8 -4
  192. package/src/api/client.ts +11 -2
  193. package/src/api/portal.ts +11 -14
  194. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  195. package/src/components/Dropdown/Content.tsx +67 -117
  196. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  197. package/src/components/Dropdown/Dropdown.tsx +75 -15
  198. package/src/components/Dropdown/ListingItem.tsx +80 -0
  199. package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
  200. package/src/components/Dropdown/README.md +10 -18
  201. package/src/components/Dropdown/Receive/Receive.tsx +119 -0
  202. package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
  203. package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
  204. package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
  205. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
  206. package/src/components/Dropdown/Root/Root.tsx +147 -0
  207. package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
  208. package/src/components/Dropdown/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
  209. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  210. package/src/config.ts +135 -21
  211. package/src/constants.ts +18 -4
  212. package/src/hooks/index.ts +7 -0
  213. package/src/hooks/useAssetsConversionRates.ts +97 -0
  214. package/src/hooks/useAuthenticateWithWallet.ts +33 -12
  215. package/src/hooks/useBorrowData.ts +187 -0
  216. package/src/hooks/useCreateAccount.ts +28 -2
  217. package/src/hooks/useDropdownData.ts +119 -97
  218. package/src/hooks/useLinkAccount.ts +36 -4
  219. package/src/hooks/useRefreshPassport.ts +56 -0
  220. package/src/hooks/useSignInWithWallet.ts +2 -2
  221. package/src/hooks/useSignUpWithWallet.ts +2 -2
  222. package/src/hooks/useTokensBalances.ts +187 -0
  223. package/src/hooks/useValidateMezoId.ts +31 -0
  224. package/src/hooks/useWalletAccount.ts +29 -19
  225. package/src/hooks/useWatchTransferEvents.ts +74 -0
  226. package/src/index.ts +13 -1
  227. package/src/lib/contracts/index.ts +92 -0
  228. package/src/lib/contracts/priceOracle.ts +53 -0
  229. package/src/provider.ts +1 -1
  230. package/src/stores/dropdownStore.ts +20 -0
  231. package/src/utils/address.test.ts +10 -6
  232. package/src/utils/address.ts +5 -3
  233. package/src/utils/cryptoAssets.test.ts +57 -37
  234. package/src/utils/cryptoAssets.ts +113 -35
  235. package/src/utils/currency.test.ts +2 -0
  236. package/src/utils/currency.ts +21 -0
  237. package/src/utils/mezoId.ts +51 -0
  238. package/src/utils/numbers.test.ts +181 -23
  239. package/src/utils/numbers.ts +121 -34
  240. package/src/utils/siww.ts +71 -16
  241. package/src/utils/wagmi.ts +12 -0
  242. package/src/wallet/index.ts +3 -2
  243. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  244. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  245. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  246. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  247. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  248. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  249. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  250. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  251. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  252. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  253. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  254. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  255. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  256. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  257. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  258. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  259. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  260. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  261. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  262. package/src/hooks/useAssetsUSDConversion.ts +0 -31
package/src/api/auth.ts CHANGED
@@ -38,7 +38,7 @@ export type AuthenticationProviderRedirectResponse = {
38
38
  redirectTo: string
39
39
  }
40
40
 
41
- type SignatureData = {
41
+ export type SignatureData = {
42
42
  message: string
43
43
  signature: string
44
44
  }
@@ -62,12 +62,14 @@ export type GetAccountByMezoIdOrAddressResponse = {
62
62
  linkedAccounts?: Extract<LinkedAccount, { type: "wallet" }>[]
63
63
  }
64
64
 
65
- export type LinkAccountRequest = CreateSessionRequest
65
+ export type LinkAccountRequest = CreateAccountRequest | { type: "discord" }
66
66
  export type LinkAccountResponse =
67
67
  | Account
68
68
  | AuthenticationProviderRedirectResponse
69
69
 
70
- export type CreateAccountRequest = { type: "wallet" } & SignatureData
70
+ export type CreateAccountRequest = { type: "wallet" } & SignatureData & {
71
+ bitcoinPublicKey?: string
72
+ }
71
73
  export type CreateAccountResponse = Account
72
74
 
73
75
  export type UpdateMezoIdResponse = Account
@@ -82,7 +84,9 @@ export class AuthApiClient extends ApiClient {
82
84
  environment: keyof typeof AUTH_API_ENDPOINTS_BY_ENV = "mainnet",
83
85
  apiUrl?: string,
84
86
  ) {
85
- super(apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment])
87
+ super({
88
+ apiUrl: apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment],
89
+ })
86
90
  }
87
91
 
88
92
  async getSession(code?: string) {
package/src/api/client.ts CHANGED
@@ -5,10 +5,19 @@ type RequestHandlerOptions = Omit<RequestInit, "credentials" | "body"> & {
5
5
  queryParams?: Record<string, string | undefined>
6
6
  }
7
7
 
8
+ const ENDS_WITH_VERSIONING_REGEX = /\/v\d+(?=\/|$)/
9
+ const TRAILING_SLASH_REGEX = /\/$/
10
+
8
11
  export abstract class ApiClient {
9
12
  private apiUrl: string
10
13
 
11
- constructor(apiUrl: string) {
14
+ constructor(opts: { apiUrl: string; removeVersioning?: boolean }) {
15
+ const { apiUrl, removeVersioning = false } = opts
16
+
17
+ if (removeVersioning) {
18
+ this.apiUrl = apiUrl.replace(ENDS_WITH_VERSIONING_REGEX, "")
19
+ return
20
+ }
12
21
  this.apiUrl = apiUrl
13
22
  }
14
23
 
@@ -33,7 +42,7 @@ export abstract class ApiClient {
33
42
  const { method, body, queryParams = {}, ...restOptions } = options
34
43
 
35
44
  // If last character in apiUrl is forward slash we are removing it
36
- const authApiUrlRoute = this.apiUrl.replace(/\/$/, "")
45
+ const authApiUrlRoute = this.apiUrl.replace(TRAILING_SLASH_REGEX, "")
37
46
  const url = new URL(`${authApiUrlRoute}${endpoint}`)
38
47
 
39
48
  // Removes falsy values (e.g. null, undefined etc.) from query params and
package/src/api/portal.ts CHANGED
@@ -6,25 +6,19 @@ type PortalStatistics = {
6
6
  tvl: number
7
7
  currentUsdPerBtc: string
8
8
  currentUsdPerEth: string
9
+ currentUsdPerTToken: string
9
10
  usdPerBtc24hChange: string
10
11
  }
11
12
 
12
13
  type PortalMats = {
13
- address: string
14
14
  totalMats: number
15
- matsFromDeposits: number
16
- matsFromReferrals: number
17
- matsFromSecondaryReferrals: number
18
- netMatsTransferred: number
19
- dailyMats: number
20
- dailyMatsFromDeposits: number
21
- dailyMatsFromReferrals: number
22
- dailyMatsFromSecondaryReferrals: number
15
+ inactiveMats: number
16
+ matsActivated: boolean
23
17
  }
24
18
 
25
19
  export const PORTAL_API_ENDPOINTS_BY_ENV = {
26
- mainnet: "https://api.mezo.org/api/v1",
27
- testnet: "https://api.test.mezo.org/api/v1",
20
+ mainnet: "https://api.mezo.org/api/",
21
+ testnet: "https://api.test.mezo.org/api/",
28
22
  }
29
23
 
30
24
  export class PortalApiClient extends ApiClient {
@@ -32,11 +26,14 @@ export class PortalApiClient extends ApiClient {
32
26
  environment: keyof typeof PORTAL_API_ENDPOINTS_BY_ENV = "mainnet",
33
27
  apiUrl?: string,
34
28
  ) {
35
- super(apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment])
29
+ super({
30
+ apiUrl: apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment],
31
+ removeVersioning: true,
32
+ })
36
33
  }
37
34
 
38
35
  async getPortalStatistics() {
39
- const data = await this.handleRequest<PortalStatistics>("/statistics", {
36
+ const data = await this.handleRequest<PortalStatistics>("/v1/statistics", {
40
37
  method: "GET",
41
38
  })
42
39
 
@@ -45,7 +42,7 @@ export class PortalApiClient extends ApiClient {
45
42
 
46
43
  async getPortalMats(address: string) {
47
44
  const data = await this.handleRequest<PortalMats>(
48
- `/accounts/${address}/mats`,
45
+ `/v2/account/${address}/mats`,
49
46
  {
50
47
  method: "GET",
51
48
  },
@@ -1,54 +1,74 @@
1
- import { Block, ButtonProps, useStyletron } from "@mezo-org/mezo-clay"
2
- import React, { forwardRef, ReactNode } from "react"
1
+ import { Block, Button, ButtonProps, useStyletron } from "@mezo-org/mezo-clay"
2
+ import React, { forwardRef, ReactNode, useMemo } from "react"
3
3
 
4
- type ConnectedTriggerProps = Omit<ButtonProps, "children"> & {
4
+ type ConnectedTriggerProps = Omit<ButtonProps, "children" | "size"> & {
5
5
  avatar: ReactNode
6
+ size?: "medium" | "large"
6
7
  }
7
8
 
8
9
  const ConnectedTrigger = forwardRef<HTMLButtonElement, ConnectedTriggerProps>(
9
10
  (props, ref) => {
10
- const { onClick, avatar, ...restProps } = props
11
+ const { onClick, avatar, size = "medium", ...restProps } = props
11
12
 
12
13
  const [, theme] = useStyletron()
13
14
 
15
+ const avatarSize = useMemo(() => {
16
+ const sizeMap = {
17
+ medium: theme.sizing.scale950,
18
+ large: theme.sizing.scale1400,
19
+ }
20
+
21
+ return sizeMap[size]
22
+ }, [theme, size])
23
+
24
+ const buttonPadding = useMemo(() => {
25
+ const paddingMap = {
26
+ medium: theme.sizing.scale0,
27
+ large: theme.sizing.scale100,
28
+ }
29
+
30
+ return paddingMap[size]
31
+ }, [theme, size])
32
+
14
33
  return (
15
- <Block
16
- as="button"
34
+ <Button
17
35
  overrides={{
18
- Block: {
36
+ BaseButton: {
19
37
  props: { ref, ...restProps },
20
38
  style: {
21
- border: "none",
22
- background: "none",
23
- padding: 0,
24
- margin: 0,
25
- cursor: "pointer",
39
+ borderRadius: "100%",
40
+ overflow: "hidden",
41
+ padding: buttonPadding,
26
42
  },
27
43
  },
28
44
  }}
29
45
  onClick={onClick}
30
46
  >
31
- <Block
32
- width={theme.sizing.scale950}
33
- height={theme.sizing.scale950}
34
- overrides={{
35
- Block: {
36
- style: {
37
- borderRadius: "100%",
38
- border: `2px solid ${theme.colors.contentPrimary}`,
39
- boxSizing: "border-box",
40
- overflow: "hidden",
47
+ {typeof avatar === "string" ? (
48
+ <Block
49
+ width={avatarSize}
50
+ height={avatarSize}
51
+ as="img"
52
+ src={avatar}
53
+ alt=""
54
+ />
55
+ ) : (
56
+ <Block
57
+ width={avatarSize}
58
+ height={avatarSize}
59
+ overrides={{
60
+ Block: {
61
+ style: {
62
+ borderRadius: "100%",
63
+ overflow: "hidden",
64
+ },
41
65
  },
42
- },
43
- }}
44
- >
45
- {typeof avatar === "string" ? (
46
- <Block as="img" src={avatar} alt="" />
47
- ) : (
48
- avatar
49
- )}
50
- </Block>
51
- </Block>
66
+ }}
67
+ >
68
+ {avatar}
69
+ </Block>
70
+ )}
71
+ </Button>
52
72
  )
53
73
  },
54
74
  )
@@ -1,78 +1,64 @@
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 AccountAddress from "./AccountAddress"
14
- import AccountAssets from "./AccountAssets"
15
- import AccountBalance from "./AccountBalance"
16
- import WelcomeBlock from "./WelcomeBlock"
1
+ import { Block, useStyletron } from "@mezo-org/mezo-clay"
2
+ import React, { useEffect } from "react"
3
+ import useDropdownStore, { DropdownView } from "../../stores/dropdownStore"
4
+ import Root from "./Root/Root"
5
+ import Receive from "./Receive/Receive"
6
+ import { DetailedCryptoAsset } from "../../utils/cryptoAssets"
7
+ import TestnetTopBanner from "./TestnetTopBanner"
17
8
 
18
- function MatsnetLabel() {
19
- const [, theme] = useStyletron()
20
- return (
21
- <ParagraphSmall color={theme.colors.contentTertiary}>
22
- <Mats
23
- color="currentColor"
24
- size={theme.sizing.scale400}
25
- overrides={{
26
- Svg: {
27
- style: {
28
- marginRight: theme.sizing.scale300,
29
- },
30
- },
31
- }}
32
- />
33
- Matsnet Assets
34
- </ParagraphSmall>
35
- )
36
- }
37
-
38
- type DropdownContentProps = {
39
- data: DropdownData
9
+ type ContentProps = {
10
+ mezoId: string
11
+ matsBalance: number
12
+ accountAddress: string
13
+ walletAddress: string
14
+ walletType: "bitcoin" | "evm"
15
+ usdTotalBalance: number
16
+ usdTroveDebt: number
17
+ usdCollateral: number
18
+ assets: {
19
+ btc: DetailedCryptoAsset
20
+ musd: DetailedCryptoAsset
21
+ }
22
+ otherAssetsCount: number
23
+ otherAssetsUsdTotal: number
40
24
  onSignOut?: () => void
25
+ onOtherAssetsClick?: () => void
41
26
  }
42
27
 
43
- export default function DropdownContent(props: DropdownContentProps) {
44
- const { data, onSignOut } = props
45
-
46
- const [, theme] = useStyletron()
47
-
28
+ function Content(props: ContentProps) {
48
29
  const {
49
30
  mezoId,
50
- address,
31
+ accountAddress,
32
+ walletAddress,
51
33
  walletType,
52
- totalBalanceInUsd,
53
- formattedNativeAssets,
54
- matsnet,
55
- } = data
34
+ usdTotalBalance,
35
+ assets,
36
+ matsBalance,
37
+ usdTroveDebt,
38
+ usdCollateral,
39
+ otherAssetsCount,
40
+ otherAssetsUsdTotal,
41
+ onSignOut,
42
+ onOtherAssetsClick,
43
+ } = props
56
44
 
57
- const { disconnect } = useDisconnect()
58
- const { signOut } = useSignOut()
45
+ const [_, theme] = useStyletron()
59
46
 
60
- const handleLogOut = useCallback(() => {
61
- if (onSignOut) {
62
- onSignOut()
63
- return
64
- }
47
+ const currentView = useDropdownStore((state) => state.view)
48
+ const setView = useDropdownStore((state) => state.setView)
65
49
 
66
- signOut()
67
- disconnect()
68
- }, [signOut, disconnect, onSignOut])
50
+ useEffect(
51
+ () => () => {
52
+ setView(DropdownView.ROOT)
53
+ },
54
+ [setView],
55
+ )
69
56
 
70
57
  return (
71
58
  <Block
72
59
  display="inline-flex"
73
60
  flexDirection="column"
74
61
  backgroundColor={theme.colors.backgroundPrimary}
75
- padding={theme.sizing.scale500}
76
62
  width="100%"
77
63
  overrides={{
78
64
  Block: {
@@ -82,67 +68,31 @@ export default function DropdownContent(props: DropdownContentProps) {
82
68
  },
83
69
  }}
84
70
  >
85
- <WelcomeBlock mezoId={mezoId} matsBalance={matsnet.mats} />
86
-
87
- <Block
88
- display="flex"
89
- flexDirection="column"
90
- backgroundColor={theme.colors.backgroundSecondary}
91
- overflow="hidden"
92
- overrides={{
93
- Block: { style: { borderRadius: theme.borders.radius300 } },
94
- }}
95
- >
96
- <AccountAddress address={address} type={walletType} />
97
-
98
- <AccountBalance amount={totalBalanceInUsd} />
71
+ <TestnetTopBanner />
99
72
 
100
- <AccountAssets label="Assets" assets={formattedNativeAssets} />
101
- </Block>
102
-
103
- {matsnet.formattedAssets.length > 0 && (
104
- <Block
105
- marginTop={theme.sizing.scale600}
106
- backgroundColor={theme.colors.backgroundSecondary}
107
- overflow="hidden"
108
- overrides={{
109
- Block: { style: { borderRadius: theme.borders.radius300 } },
110
- }}
111
- >
112
- <AccountAssets
113
- label={<MatsnetLabel />}
114
- assets={matsnet.formattedAssets}
115
- />
116
- </Block>
73
+ {currentView === DropdownView.ROOT && (
74
+ <Root
75
+ mezoId={mezoId}
76
+ accountAddress={accountAddress}
77
+ walletAddress={walletAddress}
78
+ walletType={walletType}
79
+ usdTotalBalance={usdTotalBalance}
80
+ assets={assets}
81
+ matsBalance={matsBalance}
82
+ usdTroveDebt={usdTroveDebt}
83
+ usdCollateral={usdCollateral}
84
+ otherAssetsCount={otherAssetsCount}
85
+ otherAssetsUsdTotal={otherAssetsUsdTotal}
86
+ onSignOut={onSignOut}
87
+ onOtherAssetsClick={onOtherAssetsClick}
88
+ />
117
89
  )}
118
90
 
119
- <Block
120
- marginTop={theme.sizing.scale700}
121
- padding={`0 ${theme.sizing.scale100}`}
122
- >
123
- <Button
124
- size="small"
125
- kind="tertiary"
126
- startEnhancer={<LogOut01 color="currentColor" size={12} />}
127
- onClick={() => handleLogOut()}
128
- overrides={{
129
- Root: {
130
- style: {
131
- ":hover": {
132
- backgroundColor: theme.colors.backgroundSecondary,
133
- boxShadow: "none",
134
- },
135
- ":active": {
136
- backgroundColor: theme.colors.backgroundSecondary,
137
- color: theme.colors.contentPrimary,
138
- },
139
- },
140
- },
141
- }}
142
- >
143
- Log out
144
- </Button>
145
- </Block>
91
+ {currentView === DropdownView.RECEIVE && (
92
+ <Receive address={accountAddress} />
93
+ )}
146
94
  </Block>
147
95
  )
148
96
  }
97
+
98
+ export default Content
@@ -20,12 +20,13 @@ const DisconnectedTrigger = forwardRef<
20
20
  }
21
21
  overrides={{
22
22
  Root: {
23
- props: { ref, ...restProps },
23
+ props: { ref },
24
24
  },
25
25
  }}
26
26
  size="small"
27
27
  shape="pill"
28
28
  onClick={onClick}
29
+ {...restProps}
29
30
  >
30
31
  {children}
31
32
  </Button>
@@ -1,28 +1,37 @@
1
1
  import {
2
+ ButtonProps,
2
3
  StatefulPopover,
3
4
  StatefulPopoverProps,
4
5
  useStyletron,
5
6
  } from "@mezo-org/mezo-clay"
6
7
  import { useConnectModal } from "@rainbow-me/rainbowkit"
7
- import React from "react"
8
+ import React, { useEffect, useMemo } from "react"
9
+ import { useDisconnect } from "wagmi"
8
10
  import DefaultAvatar from "../../assets/DefaultAvatar"
9
- import useDropdownData, {
10
- DropdownCryptoAsset,
11
- } from "../../hooks/useDropdownData"
12
11
  import useWalletAccount from "../../hooks/useWalletAccount"
13
12
  import ConnectedTrigger from "./ConnectedTrigger"
14
13
  import Content from "./Content"
15
14
  import DisconnectedTrigger from "./DisconnectedTrigger"
15
+ import { useSignInWithWallet } from "../../hooks"
16
+ import useDropdownData from "../../hooks/useDropdownData"
16
17
 
17
18
  export type DropdownProps = {
18
19
  /** The callback to be called when the user clicks the sign-out button */
19
20
  onSignOut?: () => void
20
21
  /** The callback to be called when the user clicks the button in sign-in state */
21
22
  onSignIn?: () => void
22
- /** The set of EVM native assets to be displayed in the dropdown */
23
- evmNativeAssets?: DropdownCryptoAsset<"tbtc" | "wbtc">[]
24
- /** The set of Matsnet assets to be displayed in the dropdown */
25
- matsnetAssets?: DropdownCryptoAsset<"mbtc" | "musd">[]
23
+ /** The props to be passed to the trigger button */
24
+ triggerProps?: {
25
+ signedIn?: Omit<ButtonProps, "onClick" | "size"> & {
26
+ size: "medium" | "large"
27
+ }
28
+ signedOut?: Omit<ButtonProps, "onClick">
29
+ }
30
+ onOtherAssetsClick?: () => void
31
+ /** Time in milliseconds after which account data (like mats or mezo id) in dropdown should be re-fetched. Default is 90000 (90 secs) */
32
+ accountDataRefetchInterval?: number
33
+ /** Time in milliseconds after which native balance in dropdown should be re-fetched. Default is 90000 (90 secs) */
34
+ nativeBalanceRefetchInterval?: number
26
35
  } & Omit<StatefulPopoverProps, "children" | "content">
27
36
 
28
37
  /**
@@ -36,26 +45,58 @@ export function Dropdown(props: DropdownProps) {
36
45
  animateOutTime = 120,
37
46
  onSignIn,
38
47
  onSignOut,
39
- evmNativeAssets,
40
- matsnetAssets,
41
48
  overrides,
49
+ triggerProps,
50
+ onOtherAssetsClick,
51
+ accountDataRefetchInterval,
52
+ nativeBalanceRefetchInterval,
42
53
  ...restProps
43
54
  } = props
44
55
 
45
56
  const [, theme] = useStyletron()
46
57
 
47
- const dropdownData = useDropdownData({ evmNativeAssets, matsnetAssets })
58
+ const data = useDropdownData({
59
+ accountDataRefetchInterval,
60
+ nativeBalanceRefetchInterval,
61
+ })
62
+
63
+ const isCriticalDropdownDataLoaded = useMemo(
64
+ () => Boolean(data.mezoId && data.accountAddress && data.walletAddress),
65
+ [data],
66
+ )
48
67
 
49
68
  const { openConnectModal } = useConnectModal()
50
69
 
51
70
  const { isConnected } = useWalletAccount()
52
71
 
53
- if (!dropdownData || !isConnected) {
72
+ const { signInWithWalletAsync, isPending } = useSignInWithWallet()
73
+
74
+ const { disconnectAsync } = useDisconnect()
75
+
76
+ useEffect(() => {
77
+ if (onSignIn) return
78
+
79
+ const handleSignIn = async () => {
80
+ if (!isConnected) return
81
+
82
+ try {
83
+ await signInWithWalletAsync()
84
+ } catch (error) {
85
+ await disconnectAsync()
86
+ }
87
+ }
88
+
89
+ handleSignIn()
90
+ }, [disconnectAsync, isConnected, onSignIn, signInWithWalletAsync])
91
+
92
+ if (!isConnected || !isCriticalDropdownDataLoaded) {
54
93
  return (
55
94
  <DisconnectedTrigger
56
95
  // If connect wallet flow is not provided it fallbacks to RainbowKit's
57
96
  // connect modal
58
97
  onClick={onSignIn || openConnectModal}
98
+ isLoading={isPending}
99
+ {...triggerProps?.signedOut}
59
100
  >
60
101
  Sign in
61
102
  </DisconnectedTrigger>
@@ -64,7 +105,23 @@ export function Dropdown(props: DropdownProps) {
64
105
 
65
106
  return (
66
107
  <StatefulPopover
67
- content={<Content data={dropdownData} onSignOut={onSignOut} />}
108
+ content={
109
+ <Content
110
+ mezoId={data.mezoId!}
111
+ matsBalance={data.matsBalance}
112
+ accountAddress={data.accountAddress!}
113
+ walletAddress={data.walletAddress!}
114
+ walletType={data.walletType}
115
+ usdTotalBalance={data.usdTotalBalance}
116
+ usdTroveDebt={data.usdTroveDebt}
117
+ usdCollateral={data.usdCollateral}
118
+ assets={data.assets}
119
+ otherAssetsCount={data.otherAssetsCount}
120
+ otherAssetsUsdTotal={data.otherAssetsUsdTotal}
121
+ onSignOut={onSignOut}
122
+ onOtherAssetsClick={onOtherAssetsClick}
123
+ />
124
+ }
68
125
  placement={placement}
69
126
  animateOutTime={animateOutTime}
70
127
  overrides={{
@@ -72,7 +129,7 @@ export function Dropdown(props: DropdownProps) {
72
129
  Body: {
73
130
  ...overrides?.Body,
74
131
  style: {
75
- minWidth: "378px",
132
+ width: "396px",
76
133
  borderRadius: theme.borders.radius500,
77
134
  boxShadow: theme.lighting.shadow500,
78
135
  overflow: "hidden",
@@ -82,7 +139,10 @@ export function Dropdown(props: DropdownProps) {
82
139
  }}
83
140
  {...restProps}
84
141
  >
85
- <ConnectedTrigger avatar={<DefaultAvatar />} />
142
+ <ConnectedTrigger
143
+ avatar={<DefaultAvatar />}
144
+ {...triggerProps?.signedIn}
145
+ />
86
146
  </StatefulPopover>
87
147
  )
88
148
  }