@mezo-org/passport 0.4.0-dev.9 → 0.5.1-dev.0

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 (305) 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 +4 -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 +9 -6
  26. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  27. package/dist/src/components/Dropdown/Dropdown.js +10 -10
  28. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  29. package/dist/src/components/Dropdown/ListingItem.d.ts +14 -0
  30. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
  31. package/dist/src/components/Dropdown/ListingItem.js +42 -0
  32. package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
  33. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +8 -0
  34. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
  35. package/dist/src/components/Dropdown/NestedViewLayout.js +32 -0
  36. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
  37. package/dist/src/components/Dropdown/Receive/Receive.d.ts +4 -0
  38. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
  39. package/dist/src/components/Dropdown/Receive/Receive.js +64 -0
  40. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +4 -0
  42. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +49 -0
  44. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
  45. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +6 -0
  46. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
  47. package/dist/src/components/Dropdown/Root/AccountBalance.js +35 -0
  48. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
  49. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
  50. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  51. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
  52. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  53. package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
  54. package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
  55. package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
  56. package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
  57. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
  58. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  59. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
  60. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  61. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +8 -0
  62. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
  63. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +43 -0
  64. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
  65. package/dist/src/components/Dropdown/Root/Root.d.ts +8 -0
  66. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
  67. package/dist/src/components/Dropdown/Root/Root.js +45 -0
  68. package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
  69. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +4 -0
  70. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
  71. package/dist/src/components/Dropdown/Root/WalletAddress.js +66 -0
  72. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
  73. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +6 -0
  74. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
  75. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +88 -0
  76. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
  77. package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
  78. package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
  79. package/dist/src/components/Dropdown/SlotNumber.js +67 -0
  80. package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
  81. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
  82. package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
  83. package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
  84. package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
  85. package/dist/src/config.d.ts +19 -5
  86. package/dist/src/config.d.ts.map +1 -1
  87. package/dist/src/config.js +58 -14
  88. package/dist/src/config.js.map +1 -1
  89. package/dist/src/constants.d.ts +11 -3
  90. package/dist/src/constants.d.ts.map +1 -1
  91. package/dist/src/constants.js +12 -4
  92. package/dist/src/constants.js.map +1 -1
  93. package/dist/src/hooks/index.d.ts +4 -0
  94. package/dist/src/hooks/index.d.ts.map +1 -1
  95. package/dist/src/hooks/index.js +4 -0
  96. package/dist/src/hooks/index.js.map +1 -1
  97. package/dist/src/hooks/useAssetsConversionRates.d.ts +18 -0
  98. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
  99. package/dist/src/hooks/useAssetsConversionRates.js +67 -0
  100. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
  101. package/dist/src/hooks/useAuthenticateWithWallet.d.ts +13 -13
  102. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  103. package/dist/src/hooks/useAuthenticateWithWallet.js +9 -8
  104. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  105. package/dist/src/hooks/useBorrowData.d.ts +108 -0
  106. package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
  107. package/dist/src/hooks/useBorrowData.js +201 -0
  108. package/dist/src/hooks/useBorrowData.js.map +1 -0
  109. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  110. package/dist/src/hooks/useCreateAccount.js +22 -1
  111. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  112. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  113. package/dist/src/hooks/useGetCurrentAccount.js +4 -6
  114. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  115. package/dist/src/hooks/useLinkAccount.d.ts +19 -13
  116. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  117. package/dist/src/hooks/useLinkAccount.js +20 -1
  118. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  119. package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
  120. package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
  121. package/dist/src/hooks/useRefreshPassport.js +44 -0
  122. package/dist/src/hooks/useRefreshPassport.js.map +1 -0
  123. package/dist/src/hooks/useSignInWithWallet.d.ts +13 -13
  124. package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
  125. package/dist/src/hooks/useSignUpWithWallet.d.ts +13 -13
  126. package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
  127. package/dist/src/hooks/useTokensBalances.d.ts +75 -0
  128. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
  129. package/dist/src/hooks/useTokensBalances.js +181 -0
  130. package/dist/src/hooks/useTokensBalances.js.map +1 -0
  131. package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
  132. package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
  133. package/dist/src/hooks/useValidateMezoId.js +24 -0
  134. package/dist/src/hooks/useValidateMezoId.js.map +1 -0
  135. package/dist/src/hooks/useWalletAccount.d.ts +2 -1
  136. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  137. package/dist/src/hooks/useWalletAccount.js +20 -15
  138. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  139. package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
  140. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
  141. package/dist/src/hooks/useWatchTransferEvents.js +63 -0
  142. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
  143. package/dist/src/index.d.ts +2 -1
  144. package/dist/src/index.d.ts.map +1 -1
  145. package/dist/src/index.js +2 -1
  146. package/dist/src/index.js.map +1 -1
  147. package/dist/src/lib/contracts/index.d.ts +13 -0
  148. package/dist/src/lib/contracts/index.d.ts.map +1 -0
  149. package/dist/src/lib/contracts/index.js +66 -0
  150. package/dist/src/lib/contracts/index.js.map +1 -0
  151. package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
  152. package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
  153. package/dist/src/lib/contracts/priceOracle.js +52 -0
  154. package/dist/src/lib/contracts/priceOracle.js.map +1 -0
  155. package/dist/src/provider.d.ts +7 -1
  156. package/dist/src/provider.d.ts.map +1 -1
  157. package/dist/src/provider.js +4 -1
  158. package/dist/src/provider.js.map +1 -1
  159. package/dist/src/stores/dropdownStore.d.ts +12 -0
  160. package/dist/src/stores/dropdownStore.d.ts.map +1 -0
  161. package/dist/src/stores/dropdownStore.js +13 -0
  162. package/dist/src/stores/dropdownStore.js.map +1 -0
  163. package/dist/src/utils/address.d.ts +1 -1
  164. package/dist/src/utils/address.d.ts.map +1 -1
  165. package/dist/src/utils/address.js +2 -0
  166. package/dist/src/utils/address.js.map +1 -1
  167. package/dist/src/utils/address.test.js +8 -5
  168. package/dist/src/utils/address.test.js.map +1 -1
  169. package/dist/src/utils/assets.d.ts +145 -0
  170. package/dist/src/utils/assets.d.ts.map +1 -0
  171. package/dist/src/utils/assets.js +100 -0
  172. package/dist/src/utils/assets.js.map +1 -0
  173. package/dist/src/utils/assets.test.d.ts +2 -0
  174. package/dist/src/utils/assets.test.d.ts.map +1 -0
  175. package/dist/src/utils/assets.test.js +46 -0
  176. package/dist/src/utils/assets.test.js.map +1 -0
  177. package/dist/src/utils/currency.d.ts +13 -2
  178. package/dist/src/utils/currency.d.ts.map +1 -1
  179. package/dist/src/utils/currency.js +22 -8
  180. package/dist/src/utils/currency.js.map +1 -1
  181. package/dist/src/utils/currency.test.js +44 -1
  182. package/dist/src/utils/currency.test.js.map +1 -1
  183. package/dist/src/utils/mezoId.d.ts +7 -0
  184. package/dist/src/utils/mezoId.d.ts.map +1 -0
  185. package/dist/src/utils/mezoId.js +41 -0
  186. package/dist/src/utils/mezoId.js.map +1 -0
  187. package/dist/src/utils/number2.d.ts +106 -0
  188. package/dist/src/utils/number2.d.ts.map +1 -0
  189. package/dist/src/utils/number2.js +289 -0
  190. package/dist/src/utils/number2.js.map +1 -0
  191. package/dist/src/utils/numbers.d.ts +15 -33
  192. package/dist/src/utils/numbers.d.ts.map +1 -1
  193. package/dist/src/utils/numbers.js +26 -70
  194. package/dist/src/utils/numbers.js.map +1 -1
  195. package/dist/src/utils/numbers.test.js +46 -42
  196. package/dist/src/utils/numbers.test.js.map +1 -1
  197. package/dist/src/utils/siww.d.ts +1 -0
  198. package/dist/src/utils/siww.d.ts.map +1 -1
  199. package/dist/src/utils/siww.js +50 -12
  200. package/dist/src/utils/siww.js.map +1 -1
  201. package/dist/src/utils/wagmi.d.ts +3 -0
  202. package/dist/src/utils/wagmi.d.ts.map +1 -0
  203. package/dist/src/utils/wagmi.js +7 -0
  204. package/dist/src/utils/wagmi.js.map +1 -0
  205. package/dist/src/wallet/index.d.ts +1 -1
  206. package/dist/src/wallet/index.d.ts.map +1 -1
  207. package/dist/src/wallet/index.js +1 -1
  208. package/dist/src/wallet/index.js.map +1 -1
  209. package/package.json +11 -8
  210. package/src/api/auth.ts +8 -4
  211. package/src/api/client.ts +11 -2
  212. package/src/api/portal.ts +11 -14
  213. package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
  214. package/src/components/Dropdown/Content.tsx +26 -121
  215. package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
  216. package/src/components/Dropdown/Dropdown.tsx +29 -17
  217. package/src/components/Dropdown/ListingItem.tsx +176 -0
  218. package/src/components/Dropdown/NestedViewLayout.tsx +87 -0
  219. package/src/components/Dropdown/README.md +10 -18
  220. package/src/components/Dropdown/Receive/Receive.tsx +144 -0
  221. package/src/components/Dropdown/Root/AccountAddressActions.tsx +99 -0
  222. package/src/components/Dropdown/Root/AccountBalance.tsx +75 -0
  223. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  224. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  225. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  226. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +85 -0
  227. package/src/components/Dropdown/Root/Root.tsx +77 -0
  228. package/src/components/Dropdown/Root/WalletAddress.tsx +123 -0
  229. package/src/components/Dropdown/Root/WelcomeBlock.tsx +173 -0
  230. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  231. package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
  232. package/src/config.ts +88 -20
  233. package/src/constants.ts +12 -4
  234. package/src/hooks/index.ts +7 -0
  235. package/src/hooks/useAssetsConversionRates.ts +79 -0
  236. package/src/hooks/useAuthenticateWithWallet.ts +30 -14
  237. package/src/hooks/useBorrowData.ts +246 -0
  238. package/src/hooks/useCreateAccount.ts +29 -2
  239. package/src/hooks/useGetCurrentAccount.ts +5 -7
  240. package/src/hooks/useLinkAccount.ts +37 -4
  241. package/src/hooks/useRefreshPassport.ts +56 -0
  242. package/src/hooks/useSignInWithWallet.ts +2 -2
  243. package/src/hooks/useSignUpWithWallet.ts +2 -2
  244. package/src/hooks/useTokensBalances.ts +265 -0
  245. package/src/hooks/useValidateMezoId.ts +31 -0
  246. package/src/hooks/useWalletAccount.ts +32 -20
  247. package/src/hooks/useWatchTransferEvents.ts +74 -0
  248. package/src/index.ts +12 -1
  249. package/src/lib/contracts/index.ts +99 -0
  250. package/src/lib/contracts/priceOracle.ts +53 -0
  251. package/src/provider.ts +11 -3
  252. package/src/stores/dropdownStore.ts +20 -0
  253. package/src/utils/address.test.ts +10 -6
  254. package/src/utils/address.ts +5 -3
  255. package/src/utils/assets.test.ts +57 -0
  256. package/src/utils/assets.ts +103 -0
  257. package/src/utils/currency.test.ts +77 -1
  258. package/src/utils/currency.ts +35 -9
  259. package/src/utils/mezoId.ts +51 -0
  260. package/src/utils/number2.ts +419 -0
  261. package/src/utils/numbers.test.ts +49 -42
  262. package/src/utils/numbers.ts +33 -95
  263. package/src/utils/siww.ts +71 -16
  264. package/src/utils/wagmi.ts +12 -0
  265. package/src/wallet/index.ts +3 -2
  266. package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
  267. package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
  268. package/dist/src/components/Dropdown/AccountAddress.js +0 -58
  269. package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
  270. package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
  271. package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
  272. package/dist/src/components/Dropdown/AccountAssets.js +0 -44
  273. package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
  274. package/dist/src/components/Dropdown/AccountBalance.d.ts +0 -7
  275. package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
  276. package/dist/src/components/Dropdown/AccountBalance.js +0 -18
  277. package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
  278. package/dist/src/components/Dropdown/WelcomeBlock.d.ts +0 -8
  279. package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
  280. package/dist/src/components/Dropdown/WelcomeBlock.js +0 -44
  281. package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
  282. package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
  283. package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
  284. package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
  285. package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
  286. package/dist/src/hooks/useDropdownData.d.ts +0 -44
  287. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  288. package/dist/src/hooks/useDropdownData.js +0 -73
  289. package/dist/src/hooks/useDropdownData.js.map +0 -1
  290. package/dist/src/utils/cryptoAssets.d.ts +0 -28
  291. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  292. package/dist/src/utils/cryptoAssets.js +0 -73
  293. package/dist/src/utils/cryptoAssets.js.map +0 -1
  294. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  295. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  296. package/dist/src/utils/cryptoAssets.test.js +0 -49
  297. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  298. package/src/components/Dropdown/AccountAddress.tsx +0 -111
  299. package/src/components/Dropdown/AccountAssets.tsx +0 -110
  300. package/src/components/Dropdown/AccountBalance.tsx +0 -38
  301. package/src/components/Dropdown/WelcomeBlock.tsx +0 -92
  302. package/src/hooks/useAssetsUSDConversion.ts +0 -31
  303. package/src/hooks/useDropdownData.ts +0 -130
  304. package/src/utils/cryptoAssets.test.ts +0 -59
  305. package/src/utils/cryptoAssets.ts +0 -93
@@ -1,12 +1,16 @@
1
1
  export { useBitcoinAccount, useSendBitcoin, useSendTransaction, useSubscribeToConnectedToUnsupportedBitcoinAddress, useSubscribeToConnectorEvent, useSubscribeToWalletNetworkDoesNotMatchProviderChain, } from "@mezo-org/orangekit";
2
+ export { useInvalidateBorrowData, useResetBorrowData } from "./useBorrowData";
2
3
  export * from "./useGetAccountByAddress";
3
4
  export * from "./useGetAccountByMezoId";
4
5
  export * from "./useGetCurrentAccount";
5
6
  export * from "./useGetSession";
6
7
  export * from "./useLinkAccount";
8
+ export * from "./useRefreshPassport";
7
9
  export * from "./useSignInWithDiscord";
8
10
  export * from "./useSignInWithWallet";
9
11
  export * from "./useSignOut";
10
12
  export * from "./useSignUpWithWallet";
13
+ export { useInvalidateTokensBalances, useResetTokensBalances, } from "./useTokensBalances";
11
14
  export * from "./useUpdateMezoId";
15
+ export * from "./useValidateMezoId";
12
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,18 @@
1
+ export declare const CONVERSION_RATE_DECIMALS = 18;
2
+ export declare const QUERY_KEY = "passport.assetsConversionRates";
3
+ /**
4
+ * Hook to fetch assets conversion rates.
5
+ * @see https://github.com/mezo-org/musd/blob/f0b2030315f0d8b0fc11a9fc778856fe4673051f/solidity/contracts/PriceFeed.sol
6
+ * @returns {}.data.{}.price - The latest asset price.
7
+ * @returns {}.data.{}.digits - The latest asset price digits.
8
+ * @returns {}.isPending - Whether the request is pending.
9
+ * @returns {}.isError - Whether there was an error fetching the price.
10
+ */
11
+ export declare function useAssetsConversionRates(): import("@tanstack/react-query").UseQueryResult<{
12
+ rates: {
13
+ mT: bigint;
14
+ BTC: bigint;
15
+ };
16
+ decimals: number;
17
+ }, Error>;
18
+ //# sourceMappingURL=useAssetsConversionRates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAssetsConversionRates.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAssetsConversionRates.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,wBAAwB,KAAK,CAAA;AAK1C,eAAO,MAAM,SAAS,mCAAmC,CAAA;AAEzD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB;;;;;;UAoDvC"}
@@ -0,0 +1,67 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ import { useConfig } from "wagmi";
3
+ import { readContract } from "wagmi/actions";
4
+ import { parseUnits } from "viem";
5
+ import { ONE_SECOND_MS } from "../utils/time";
6
+ import { usePortalApiClient } from "./usePortalApiClient";
7
+ import { priceOracleContract } from "../lib/contracts";
8
+ import { CHAIN_ID } from "../constants";
9
+ import { usePassportContext } from "./usePassportContext";
10
+ import { normalizePrecision } from "../utils/numbers";
11
+ export const CONVERSION_RATE_DECIMALS = 18;
12
+ // If the oracle has not been updated in at least 60 seconds, it is stale.
13
+ const MAX_PRICE_DELAY = 60 * ONE_SECOND_MS;
14
+ export const QUERY_KEY = "passport.assetsConversionRates";
15
+ /**
16
+ * Hook to fetch assets conversion rates.
17
+ * @see https://github.com/mezo-org/musd/blob/f0b2030315f0d8b0fc11a9fc778856fe4673051f/solidity/contracts/PriceFeed.sol
18
+ * @returns {}.data.{}.price - The latest asset price.
19
+ * @returns {}.data.{}.digits - The latest asset price digits.
20
+ * @returns {}.isPending - Whether the request is pending.
21
+ * @returns {}.isError - Whether there was an error fetching the price.
22
+ */
23
+ export function useAssetsConversionRates() {
24
+ const portalApiClient = usePortalApiClient();
25
+ const { environment = "mainnet" } = usePassportContext();
26
+ const config = useConfig();
27
+ return useQuery({
28
+ queryKey: [QUERY_KEY],
29
+ queryFn: async () => Promise.all([
30
+ portalApiClient.getPortalStatistics(),
31
+ readContract(config, {
32
+ ...priceOracleContract,
33
+ functionName: "latestRoundData",
34
+ chainId: CHAIN_ID[environment],
35
+ }),
36
+ ]),
37
+ select: ([portalStatistics, btcPriceData]) => {
38
+ const tTokenConversionRate = portalStatistics.currentUsdPerTToken;
39
+ const [, btcConversionRate] = btcPriceData;
40
+ const tPrice = parseUnits(tTokenConversionRate, CONVERSION_RATE_DECIMALS);
41
+ const btcPrice = normalizePrecision(btcConversionRate, CONVERSION_RATE_DECIMALS);
42
+ return {
43
+ rates: {
44
+ mT: tPrice,
45
+ BTC: btcPrice,
46
+ },
47
+ decimals: CONVERSION_RATE_DECIMALS,
48
+ };
49
+ },
50
+ refetchInterval: ({ state }) => {
51
+ if (!state.data)
52
+ return MAX_PRICE_DELAY;
53
+ const [, btcPriceData] = state.data;
54
+ const [, , , updatedAt] = btcPriceData;
55
+ if (!updatedAt)
56
+ return MAX_PRICE_DELAY;
57
+ const age = Date.now() - Number(updatedAt) * 1000;
58
+ return age > MAX_PRICE_DELAY
59
+ ? // If the data is stale, we want to refetch as soon as possible, but
60
+ // not faster than once per second, to avoid excessive requests.
61
+ // Math.max ensures the interval is at least 1 second.
62
+ Math.max(ONE_SECOND_MS, MAX_PRICE_DELAY - age)
63
+ : MAX_PRICE_DELAY - age;
64
+ },
65
+ });
66
+ }
67
+ //# sourceMappingURL=useAssetsConversionRates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAssetsConversionRates.js","sourceRoot":"","sources":["../../../src/hooks/useAssetsConversionRates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,E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C;QACD,eAAe,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;YAC7B,IAAI,CAAC,KAAK,CAAC,IAAI;gBAAE,OAAO,eAAe,CAAA;YAEvC,MAAM,CAAC,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,IAAI,CAAA;YACnC,MAAM,CAAC,EAAE,AAAD,EAAG,AAAD,EAAG,SAAS,CAAC,GAAG,YAAY,CAAA;YAEtC,IAAI,CAAC,SAAS;gBAAE,OAAO,eAAe,CAAA;YAEtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAA;YAEjD,OAAO,GAAG,GAAG,eAAe;gBAC1B,CAAC,CAAC,oEAAoE;oBACpE,gEAAgE;oBAChE,sDAAsD;oBACtD,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,eAAe,GAAG,GAAG,CAAC;gBAChD,CAAC,CAAC,eAAe,GAAG,GAAG,CAAA;QAC3B,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -1,6 +1,6 @@
1
- import { MutationOptions } from "@tanstack/react-query";
1
+ import { DefaultError, MutationOptions } from "@tanstack/react-query";
2
2
  import type { Session } from "../api";
3
- declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutationOptions?: Omit<MutationOptions<Session>, "mutationFn" | "mutationKey">): {
3
+ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutationOptions?: Omit<MutationOptions<Session, DefaultError, number | void>, "mutationFn" | "mutationKey">): {
4
4
  data: undefined;
5
5
  variables: undefined;
6
6
  error: null;
@@ -15,11 +15,11 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
15
15
  failureReason: Error | null;
16
16
  isPaused: boolean;
17
17
  submittedAt: number;
18
- authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
19
- authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
18
+ authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
19
+ authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
20
20
  } | {
21
21
  data: undefined;
22
- variables: void;
22
+ variables: number | void | undefined;
23
23
  error: null;
24
24
  isError: false;
25
25
  isIdle: false;
@@ -32,12 +32,12 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
32
32
  failureReason: Error | null;
33
33
  isPaused: boolean;
34
34
  submittedAt: number;
35
- authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
36
- authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
35
+ authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
36
+ authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
37
37
  } | {
38
38
  data: undefined;
39
39
  error: Error;
40
- variables: void;
40
+ variables: number | void | undefined;
41
41
  isError: true;
42
42
  isIdle: false;
43
43
  isPending: false;
@@ -49,12 +49,12 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
49
49
  failureReason: Error | null;
50
50
  isPaused: boolean;
51
51
  submittedAt: number;
52
- authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
53
- authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
52
+ authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
53
+ authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
54
54
  } | {
55
55
  data: Session;
56
56
  error: null;
57
- variables: void;
57
+ variables: number | void | undefined;
58
58
  isError: false;
59
59
  isIdle: false;
60
60
  isPending: false;
@@ -66,8 +66,8 @@ declare function useAuthenticateWithWallet(shouldCreateAccount?: boolean, mutati
66
66
  failureReason: Error | null;
67
67
  isPaused: boolean;
68
68
  submittedAt: number;
69
- authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, void, unknown>;
70
- authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, void, unknown>;
69
+ authenticateWithWallet: import("@tanstack/react-query").UseMutateFunction<Session, Error, number | void | undefined, unknown>;
70
+ authenticateWithWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Session, Error, number | void | undefined, unknown>;
71
71
  };
72
72
  export { useAuthenticateWithWallet };
73
73
  //# sourceMappingURL=useAuthenticateWithWallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticateWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAe,MAAM,uBAAuB,CAAA;AAMpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGrC,iBAAS,yBAAyB,CAChC,mBAAmB,UAAQ,EAC3B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,CAAC,EACxB,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgFP;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
1
+ {"version":3,"file":"useAuthenticateWithWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,eAAe,EAEhB,MAAM,uBAAuB,CAAA;AAS9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGrC,iBAAS,yBAAyB,CAChC,mBAAmB,UAAQ,EAC3B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,EACrD,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyFP;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
@@ -1,32 +1,33 @@
1
1
  import { useSignMessage } from "wagmi";
2
- import { useMutation } from "@tanstack/react-query";
2
+ import { useMutation, } from "@tanstack/react-query";
3
3
  import { useCreateAccount } from "./useCreateAccount";
4
4
  import { useCreateSession } from "./useCreateSession";
5
5
  import { useEnsureNoSessionAndFetchNonce } from "./useEnsureNoSessionAndFetchNonce";
6
- import { createSignInWithWalletMessage } from "../utils/siww";
6
+ import { createSignInWithWalletMessage, verifyDomainInSignInWithWalletMessage, } from "../utils/siww";
7
7
  import { useGetAccountByAddress } from "./useGetAccountByAddress";
8
8
  import useWalletAccount from "./useWalletAccount";
9
9
  function useAuthenticateWithWallet(shouldCreateAccount = false, mutationOptions = {}) {
10
- const { address, chainId, connector, networkFamily } = useWalletAccount();
10
+ const walletAccount = useWalletAccount();
11
11
  const { ensureNoSessionAndFetchNonce } = useEnsureNoSessionAndFetchNonce();
12
12
  const { createSessionAsync } = useCreateSession();
13
13
  const { createAccountAsync } = useCreateAccount();
14
14
  const { signMessageAsync } = useSignMessage();
15
- const { refetch: getAccountByAddress } = useGetAccountByAddress(address, {
15
+ const { refetch: getAccountByAddress } = useGetAccountByAddress(walletAccount.walletAddress, {
16
16
  enabled: false,
17
17
  retry: false,
18
18
  });
19
19
  const { mutate, mutateAsync, ...signInMutationRestParameters } = useMutation({
20
- mutationFn: async () => {
21
- if (!address) {
20
+ mutationFn: async (chainId) => {
21
+ if (!walletAccount.walletAddress) {
22
22
  throw new Error("Sign in error: Wallet not connected!");
23
23
  }
24
24
  const nonce = await ensureNoSessionAndFetchNonce();
25
- const messageResult = createSignInWithWalletMessage(address, nonce, networkFamily, chainId);
25
+ const messageResult = createSignInWithWalletMessage(walletAccount.walletAddress, nonce, walletAccount.networkFamily, chainId ?? walletAccount.chainId);
26
26
  const signatureResult = await signMessageAsync({
27
27
  message: messageResult,
28
- connector,
28
+ connector: walletAccount.connector,
29
29
  });
30
+ await verifyDomainInSignInWithWalletMessage(messageResult, signatureResult, nonce);
30
31
  if (shouldCreateAccount) {
31
32
  const getAccountByAddressResult = await getAccountByAddress();
32
33
  if (getAccountByAddressResult.data) {
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticateWithWallet.js","sourceRoot":"","sources":["../../../src/hooks/useAuthenticateWithWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAmB,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAA;AACnF,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AAEjD,SAAS,yBAAyB,CAChC,mBAAmB,GAAG,KAAK,EAC3B,kBAGI,EAAE;IAEN,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,CAAA;IACzE,MAAM,EAAE,4BAA4B,EAAE,GAAG,+BAA+B,EAAE,CAAA;IAC1E,MAAM,EAAE,kBAAkB,EAAE,GAAG,gBAAgB,EAAE,CAAA;IACjD,MAAM,EAAE,kBAAkB,EAAE,GAAG,gBAAgB,EAAE,CAAA;IACjD,MAAM,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,CAAA;IAE7C,MAAM,EAAE,OAAO,EAAE,mBAAm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BACnD,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,aAAa;wBACtB,SAAS,EAAE,eAAe;qBAC3B,CAAC,CAAA;oBAEF,IAAI,CAAC,mBAAmB,EAAE,CAAC;wBACzB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;oBACjD,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CACb,0DAA0D,KAAK,EAAE,CAClE,CAAA;gBACH,CAAC;YACH,CAAC;YAED,OAAO,CAAC,MAAM,kBAAkB,CAAC;gBAC/B,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,aAAa;gBACtB,SAAS,EAAE,eAAe;aAC3B,CAAC,CAAY,CAAA;YACd,0EAA0E;QAC5E,CAAC;QACD,GAAG,eAAe;KACnB,CAAC,CAAA;IAEF,OAAO;QACL,sBAAsB,EAAE,MAAM;QAC9B,2BAA2B,EAAE,WAAW;QACxC,GAAG,4BAA4B;KAChC,CAAA;AACH,CAAC;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Query hook for getting borrow data. Returns collateral and trove debt for the
3
+ * connected account, based on it's evm address.
4
+ * @param queryOptions Query options passed to the underlying `useQuery` hook.
5
+ */
6
+ export declare function useBorrowData(queryOptions?: {}): import("wagmi").UseReadContractsReturnType<readonly [{
7
+ readonly abi: readonly [{
8
+ readonly inputs: readonly [{
9
+ readonly internalType: "address";
10
+ readonly name: "_borrower";
11
+ readonly type: "address";
12
+ }];
13
+ readonly name: "getEntireDebtAndColl";
14
+ readonly outputs: readonly [{
15
+ readonly internalType: "uint256";
16
+ readonly name: "coll";
17
+ readonly type: "uint256";
18
+ }, {
19
+ readonly internalType: "uint256";
20
+ readonly name: "principal";
21
+ readonly type: "uint256";
22
+ }, {
23
+ readonly internalType: "uint256";
24
+ readonly name: "interest";
25
+ readonly type: "uint256";
26
+ }, {
27
+ readonly internalType: "uint256";
28
+ readonly name: "pendingCollateral";
29
+ readonly type: "uint256";
30
+ }, {
31
+ readonly internalType: "uint256";
32
+ readonly name: "pendingPrincipal";
33
+ readonly type: "uint256";
34
+ }, {
35
+ readonly internalType: "uint256";
36
+ readonly name: "pendingInterest";
37
+ readonly type: "uint256";
38
+ }];
39
+ readonly stateMutability: "view";
40
+ readonly type: "function";
41
+ }];
42
+ readonly address: `0x${string}`;
43
+ readonly functionName: "getEntireDebtAndColl";
44
+ readonly args: [`0x${string}`];
45
+ readonly chainId: number;
46
+ }, {
47
+ readonly abi: readonly [{
48
+ readonly inputs: readonly [];
49
+ readonly name: "MUSD_GAS_COMPENSATION";
50
+ readonly outputs: readonly [{
51
+ readonly internalType: "uint256";
52
+ readonly name: "";
53
+ readonly type: "uint256";
54
+ }];
55
+ readonly stateMutability: "view";
56
+ readonly type: "function";
57
+ }];
58
+ readonly address: `0x${string}`;
59
+ readonly functionName: "MUSD_GAS_COMPENSATION";
60
+ readonly chainId: number;
61
+ }, {
62
+ readonly abi: readonly [{
63
+ readonly inputs: readonly [];
64
+ readonly name: "fetchPrice";
65
+ readonly outputs: readonly [{
66
+ readonly internalType: "uint256";
67
+ readonly name: "";
68
+ readonly type: "uint256";
69
+ }];
70
+ readonly stateMutability: "view";
71
+ readonly type: "function";
72
+ }];
73
+ readonly address: `0x${string}`;
74
+ readonly functionName: "fetchPrice";
75
+ readonly chainId: number;
76
+ }], true, {
77
+ collateral: {
78
+ value: bigint;
79
+ decimals: number;
80
+ symbol: string;
81
+ formatted: string;
82
+ usd: {
83
+ value: bigint;
84
+ formatted: string;
85
+ };
86
+ };
87
+ debtInUsd: {
88
+ value: bigint;
89
+ formatted: string;
90
+ };
91
+ }>;
92
+ /**
93
+ * Hook for for invalidating current user's borrow data. Can be used to
94
+ * invalidate borrow data manually, which forces the data to be re-fetched.
95
+ * @returns Function `invalidateBorrowData` for invalidating the borrow data
96
+ */
97
+ export declare function useInvalidateBorrowData(): {
98
+ invalidateBorrowData: () => Promise<void>;
99
+ };
100
+ /**
101
+ * Hook for for resetting current user's borrow data. Can be used to reset
102
+ * borrow data manually, which forces the data to be re-fetched.
103
+ * @returns Function `resetBorrowData` for resetting the borrow data
104
+ */
105
+ export declare function useResetBorrowData(): {
106
+ resetBorrowData: () => Promise<void>;
107
+ };
108
+ //# sourceMappingURL=useBorrowData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBorrowData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useBorrowData.ts"],"names":[],"mappings":"AAuGA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,YAAY,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiG9C;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB;;EAatC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB;;EAajC"}
@@ -0,0 +1,201 @@
1
+ import { useReadContracts } from "wagmi";
2
+ import { useCallback, useMemo } from "react";
3
+ import { useQueryClient } from "@tanstack/react-query";
4
+ import { formatUnits } from "viem";
5
+ import { ONE_MINUTE_MS } from "../utils/time";
6
+ import { mainnetBorrowContracts, testnetBorrowContracts, } from "../lib/contracts";
7
+ import { usePassportContext } from "./usePassportContext";
8
+ import { CHAIN_ID } from "../constants";
9
+ import { bigIntMax, normalizePrecision } from "../utils/numbers";
10
+ import useWalletAccount from "./useWalletAccount";
11
+ import { getAsset } from "../utils/assets";
12
+ import { convertToUsd } from "../utils/currency";
13
+ const DEBT_AND_COLL_PRECISION = 18;
14
+ // Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
15
+ // support importing JSON as const yet so types cannot be inferred from the
16
+ // imported contract. As a workaround there is minimal ABI definition that can
17
+ // be asserted types from.
18
+ // Ref: https://wagmi.sh/core/typescript#const-assert-abis-typed-data
19
+ const TROVE_MANAGER_ABI = [
20
+ {
21
+ inputs: [
22
+ {
23
+ internalType: "address",
24
+ name: "_borrower",
25
+ type: "address",
26
+ },
27
+ ],
28
+ name: "getEntireDebtAndColl",
29
+ outputs: [
30
+ {
31
+ internalType: "uint256",
32
+ name: "coll",
33
+ type: "uint256",
34
+ },
35
+ {
36
+ internalType: "uint256",
37
+ name: "principal",
38
+ type: "uint256",
39
+ },
40
+ {
41
+ internalType: "uint256",
42
+ name: "interest",
43
+ type: "uint256",
44
+ },
45
+ {
46
+ internalType: "uint256",
47
+ name: "pendingCollateral",
48
+ type: "uint256",
49
+ },
50
+ {
51
+ internalType: "uint256",
52
+ name: "pendingPrincipal",
53
+ type: "uint256",
54
+ },
55
+ {
56
+ internalType: "uint256",
57
+ name: "pendingInterest",
58
+ type: "uint256",
59
+ },
60
+ ],
61
+ stateMutability: "view",
62
+ type: "function",
63
+ },
64
+ ];
65
+ const BORROWER_OPERATIONS_ABI = [
66
+ {
67
+ inputs: [],
68
+ name: "MUSD_GAS_COMPENSATION",
69
+ outputs: [
70
+ {
71
+ internalType: "uint256",
72
+ name: "",
73
+ type: "uint256",
74
+ },
75
+ ],
76
+ stateMutability: "view",
77
+ type: "function",
78
+ },
79
+ ];
80
+ const PRICE_FEED_ABI = [
81
+ {
82
+ inputs: [],
83
+ name: "fetchPrice",
84
+ outputs: [
85
+ {
86
+ internalType: "uint256",
87
+ name: "",
88
+ type: "uint256",
89
+ },
90
+ ],
91
+ stateMutability: "view",
92
+ type: "function",
93
+ },
94
+ ];
95
+ /**
96
+ * Query hook for getting borrow data. Returns collateral and trove debt for the
97
+ * connected account, based on it's evm address.
98
+ * @param queryOptions Query options passed to the underlying `useQuery` hook.
99
+ */
100
+ export function useBorrowData(queryOptions = {}) {
101
+ const { environment = "mainnet" } = usePassportContext();
102
+ const walletAccount = useWalletAccount();
103
+ const contractAddress = useMemo(() => {
104
+ if (environment === "mainnet") {
105
+ return {
106
+ troveManager: mainnetBorrowContracts.TroveManager.address,
107
+ borrowerOperations: mainnetBorrowContracts.BorrowerOperations.address,
108
+ priceFeed: mainnetBorrowContracts.PriceFeed.address,
109
+ };
110
+ }
111
+ return {
112
+ troveManager: testnetBorrowContracts.TroveManager.address,
113
+ borrowerOperations: testnetBorrowContracts.BorrowerOperations.address,
114
+ priceFeed: testnetBorrowContracts.PriceFeed.address,
115
+ };
116
+ }, [environment]);
117
+ const chainId = CHAIN_ID[environment];
118
+ return useReadContracts({
119
+ contracts: [
120
+ {
121
+ abi: TROVE_MANAGER_ABI,
122
+ address: contractAddress.troveManager,
123
+ functionName: "getEntireDebtAndColl",
124
+ args: walletAccount.accountAddress
125
+ ? [walletAccount.accountAddress]
126
+ : ["0x"],
127
+ chainId,
128
+ },
129
+ {
130
+ abi: BORROWER_OPERATIONS_ABI,
131
+ address: contractAddress.borrowerOperations,
132
+ functionName: "MUSD_GAS_COMPENSATION",
133
+ chainId,
134
+ },
135
+ {
136
+ abi: PRICE_FEED_ABI,
137
+ address: contractAddress.priceFeed,
138
+ functionName: "fetchPrice",
139
+ chainId,
140
+ },
141
+ ],
142
+ query: {
143
+ enabled: !!walletAccount.accountAddress,
144
+ staleTime: 5 * ONE_MINUTE_MS,
145
+ retry: 1,
146
+ select: (data) => {
147
+ if (!data || data.some((item) => !item.result))
148
+ throw new Error("No borrow data available");
149
+ const [rawCollateral, principal, interest] = data[0].result;
150
+ const gasCompensation = data[1].result;
151
+ const collateralPrice = data[2].result;
152
+ const btcDetails = getAsset("BTC");
153
+ const collateral = {
154
+ value: rawCollateral,
155
+ decimals: btcDetails.decimals,
156
+ symbol: btcDetails.symbol,
157
+ formatted: formatUnits(rawCollateral, DEBT_AND_COLL_PRECISION),
158
+ usd: convertToUsd(rawCollateral, DEBT_AND_COLL_PRECISION, collateralPrice, DEBT_AND_COLL_PRECISION),
159
+ };
160
+ const debtInUsdValue = bigIntMax(normalizePrecision(principal + interest - gasCompensation, DEBT_AND_COLL_PRECISION), 0n);
161
+ const formattedDebtInUsd = formatUnits(debtInUsdValue, DEBT_AND_COLL_PRECISION);
162
+ const debtInUsd = {
163
+ value: debtInUsdValue,
164
+ formatted: formattedDebtInUsd,
165
+ };
166
+ return {
167
+ collateral,
168
+ debtInUsd,
169
+ };
170
+ },
171
+ ...queryOptions,
172
+ },
173
+ });
174
+ }
175
+ /**
176
+ * Hook for for invalidating current user's borrow data. Can be used to
177
+ * invalidate borrow data manually, which forces the data to be re-fetched.
178
+ * @returns Function `invalidateBorrowData` for invalidating the borrow data
179
+ */
180
+ export function useInvalidateBorrowData() {
181
+ const queryClient = useQueryClient();
182
+ const { queryKey } = useBorrowData();
183
+ const invalidateBorrowDataHandler = useCallback(() => queryClient.invalidateQueries({ queryKey }), [queryClient, queryKey]);
184
+ return {
185
+ invalidateBorrowData: invalidateBorrowDataHandler,
186
+ };
187
+ }
188
+ /**
189
+ * Hook for for resetting current user's borrow data. Can be used to reset
190
+ * borrow data manually, which forces the data to be re-fetched.
191
+ * @returns Function `resetBorrowData` for resetting the borrow data
192
+ */
193
+ export function useResetBorrowData() {
194
+ const queryClient = useQueryClient();
195
+ const { queryKey } = useBorrowData();
196
+ const resetBorrowDataHandler = useCallback(() => queryClient.resetQueries({ queryKey }), [queryClient, queryKey]);
197
+ return {
198
+ resetBorrowData: resetBorrowDataHandler,
199
+ };
200
+ }
201
+ //# sourceMappingURL=useBorrowData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBorrowData.js","sourceRoot":"","sources":["../../../src/hooks/useBorrowData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,kBA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,EAAE,sBAAsB;KACxC,CAAA;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCreateAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAEzE,wBAAgB,gBAAgB,CAC9B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,qBAAqB,EAAE,YAAY,EAAE,oBAAoB,CAAC,EAC1E,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBP"}
1
+ {"version":3,"file":"useCreateAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useCreateAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,YAAY,EACb,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAIzE,wBAAgB,gBAAgB,CAC9B,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,qBAAqB,EAAE,YAAY,EAAE,oBAAoB,CAAC,EAC1E,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8CP"}
@@ -1,12 +1,33 @@
1
1
  import { useQueryClient, useMutation, } from "@tanstack/react-query";
2
2
  import { useAuthApiClient } from "./useAuthApiClient";
3
3
  import { QUERY_KEYS } from "./constants";
4
+ import useWalletAccount from "./useWalletAccount";
5
+ import { getBitcoinPublicKeyFromConnector } from "../utils/wagmi";
4
6
  export function useCreateAccount(mutationOptions = {}) {
5
7
  const queryClient = useQueryClient();
6
8
  const authApiClient = useAuthApiClient();
9
+ const walletAccount = useWalletAccount();
7
10
  const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions;
8
11
  const { mutate, mutateAsync, ...rest } = useMutation({
9
- mutationFn: (createAccountRequest) => authApiClient.createAccount(createAccountRequest),
12
+ mutationFn: async (createAccountMutationFnParameters) => {
13
+ if (createAccountMutationFnParameters.type === "wallet") {
14
+ if (!walletAccount?.connector) {
15
+ throw new Error("Connector not defined.");
16
+ }
17
+ const bitcoinPublicKey = await getBitcoinPublicKeyFromConnector(walletAccount.connector);
18
+ // Creating bitcoin mezo account
19
+ if (bitcoinPublicKey) {
20
+ return authApiClient.createAccount({
21
+ ...createAccountMutationFnParameters,
22
+ bitcoinPublicKey,
23
+ });
24
+ }
25
+ }
26
+ // Creating evm mezo account
27
+ return authApiClient.createAccount({
28
+ ...createAccountMutationFnParameters,
29
+ });
30
+ },
10
31
  onSuccess: (data, variables, context) => {
11
32
  queryClient.resetQueries({
12
33
  queryKey: [QUERY_KEYS.ACCOUNT],
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateAccount.js","sourceRoot":"","sources":["../../../src/hooks/useCreateAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,UAAU,gBAAgB,CAC9B,kBAGI,EAAE;IAEN,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,mBAAmB,EAAE,GAAG,eAAe,CAAA;IAE9E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IA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AE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAED,wBAAgB,oBAAoB,CAClC,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,iCAAiC,CAAC,EACtD,UAAU,GAAG,SAAS,CAClB;;;;;UATA;QACJ,SAAS,EAAE,MAAM,CAAA;KAClB;UAmDF"}
1
+ {"version":3,"file":"useGetCurrentAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetCurrentAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAKrE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAA;AAEvD,KAAK,iCAAiC,GAAG,yBAAyB,GAAG;IACnE,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF,CAAA;AAED,wBAAgB,oBAAoB,CAClC,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,iCAAiC,CAAC,EACtD,UAAU,GAAG,SAAS,CAClB;;;;;UATA;QACJ,SAAS,EAAE,MAAM,CAAA;KAClB;UAiDF"}