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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/src/api/auth.d.ts +1 -1
  2. package/dist/src/api/auth.d.ts.map +1 -1
  3. package/dist/src/components/Dropdown/Content.d.ts +0 -15
  4. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  5. package/dist/src/components/Dropdown/Content.js +3 -3
  6. package/dist/src/components/Dropdown/Content.js.map +1 -1
  7. package/dist/src/components/Dropdown/Dropdown.d.ts +0 -4
  8. package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
  9. package/dist/src/components/Dropdown/Dropdown.js +10 -33
  10. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  11. package/dist/src/components/Dropdown/ListingItem.d.ts +8 -7
  12. package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -1
  13. package/dist/src/components/Dropdown/ListingItem.js +36 -28
  14. package/dist/src/components/Dropdown/ListingItem.js.map +1 -1
  15. package/dist/src/components/Dropdown/NestedViewLayout.d.ts +2 -1
  16. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -1
  17. package/dist/src/components/Dropdown/NestedViewLayout.js +13 -15
  18. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -1
  19. package/dist/src/components/Dropdown/Receive/Receive.d.ts +1 -4
  20. package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -1
  21. package/dist/src/components/Dropdown/Receive/Receive.js +36 -19
  22. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -1
  23. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +2 -5
  24. package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -1
  25. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +28 -12
  26. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -1
  27. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +2 -4
  28. package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -1
  29. package/dist/src/components/Dropdown/Root/AccountBalance.js +24 -8
  30. package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -1
  31. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts +6 -0
  32. package/dist/src/components/Dropdown/Root/AccountBtcListing.d.ts.map +1 -0
  33. package/dist/src/components/Dropdown/Root/AccountBtcListing.js +27 -0
  34. package/dist/src/components/Dropdown/Root/AccountBtcListing.js.map +1 -0
  35. package/dist/src/components/Dropdown/Root/AccountError.d.ts +8 -0
  36. package/dist/src/components/Dropdown/Root/AccountError.d.ts.map +1 -0
  37. package/dist/src/components/Dropdown/Root/AccountError.js +17 -0
  38. package/dist/src/components/Dropdown/Root/AccountError.js.map +1 -0
  39. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts +4 -0
  40. package/dist/src/components/Dropdown/Root/AccountMusdListing.d.ts.map +1 -0
  41. package/dist/src/components/Dropdown/Root/AccountMusdListing.js +21 -0
  42. package/dist/src/components/Dropdown/Root/AccountMusdListing.js.map +1 -0
  43. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +2 -3
  44. package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -1
  45. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +34 -39
  46. package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -1
  47. package/dist/src/components/Dropdown/Root/Root.d.ts +0 -15
  48. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -1
  49. package/dist/src/components/Dropdown/Root/Root.js +22 -34
  50. package/dist/src/components/Dropdown/Root/Root.js.map +1 -1
  51. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +2 -6
  52. package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -1
  53. package/dist/src/components/Dropdown/Root/WalletAddress.js +43 -34
  54. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -1
  55. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +2 -4
  56. package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -1
  57. package/dist/src/components/Dropdown/Root/WelcomeBlock.js +60 -16
  58. package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -1
  59. package/dist/src/components/Dropdown/SlotNumber.d.ts +19 -0
  60. package/dist/src/components/Dropdown/SlotNumber.d.ts.map +1 -0
  61. package/dist/src/components/Dropdown/SlotNumber.js +67 -0
  62. package/dist/src/components/Dropdown/SlotNumber.js.map +1 -0
  63. package/dist/src/config.d.ts +1 -11
  64. package/dist/src/config.d.ts.map +1 -1
  65. package/dist/src/config.js +3 -40
  66. package/dist/src/config.js.map +1 -1
  67. package/dist/src/constants.d.ts +0 -2
  68. package/dist/src/constants.d.ts.map +1 -1
  69. package/dist/src/constants.js +0 -2
  70. package/dist/src/constants.js.map +1 -1
  71. package/dist/src/hooks/useAssetsConversionRates.d.ts +8 -13
  72. package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -1
  73. package/dist/src/hooks/useAssetsConversionRates.js +44 -67
  74. package/dist/src/hooks/useAssetsConversionRates.js.map +1 -1
  75. package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
  76. package/dist/src/hooks/useAuthenticateWithWallet.js +1 -1
  77. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  78. package/dist/src/hooks/useBorrowData.d.ts +31 -5
  79. package/dist/src/hooks/useBorrowData.d.ts.map +1 -1
  80. package/dist/src/hooks/useBorrowData.js +53 -11
  81. package/dist/src/hooks/useBorrowData.js.map +1 -1
  82. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  83. package/dist/src/hooks/useCreateAccount.js +3 -3
  84. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  85. package/dist/src/hooks/useGetCurrentAccount.d.ts +2 -2
  86. package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
  87. package/dist/src/hooks/useGetCurrentAccount.js +4 -6
  88. package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
  89. package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
  90. package/dist/src/hooks/useLinkAccount.js +3 -3
  91. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  92. package/dist/src/hooks/useTokensBalances.d.ts +36 -35
  93. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
  94. package/dist/src/hooks/useTokensBalances.js +93 -52
  95. package/dist/src/hooks/useTokensBalances.js.map +1 -1
  96. package/dist/src/hooks/useWalletAccount.d.ts +8 -10
  97. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  98. package/dist/src/hooks/useWalletAccount.js +22 -19
  99. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  100. package/dist/src/index.d.ts +1 -1
  101. package/dist/src/index.d.ts.map +1 -1
  102. package/dist/src/index.js +1 -1
  103. package/dist/src/index.js.map +1 -1
  104. package/dist/src/lib/contracts/index.d.ts +1 -1
  105. package/dist/src/lib/contracts/index.d.ts.map +1 -1
  106. package/dist/src/lib/contracts/index.js +4 -0
  107. package/dist/src/lib/contracts/index.js.map +1 -1
  108. package/dist/src/provider.d.ts +7 -1
  109. package/dist/src/provider.d.ts.map +1 -1
  110. package/dist/src/provider.js +4 -1
  111. package/dist/src/provider.js.map +1 -1
  112. package/dist/src/utils/assets.d.ts +145 -0
  113. package/dist/src/utils/assets.d.ts.map +1 -0
  114. package/dist/src/utils/assets.js +100 -0
  115. package/dist/src/utils/assets.js.map +1 -0
  116. package/dist/src/utils/assets.test.d.ts +2 -0
  117. package/dist/src/utils/assets.test.d.ts.map +1 -0
  118. package/dist/src/utils/assets.test.js +46 -0
  119. package/dist/src/utils/assets.test.js.map +1 -0
  120. package/dist/src/utils/currency.d.ts +6 -3
  121. package/dist/src/utils/currency.d.ts.map +1 -1
  122. package/dist/src/utils/currency.js +13 -10
  123. package/dist/src/utils/currency.js.map +1 -1
  124. package/dist/src/utils/currency.test.js +44 -2
  125. package/dist/src/utils/currency.test.js.map +1 -1
  126. package/dist/src/utils/numbers.d.ts +13 -53
  127. package/dist/src/utils/numbers.d.ts.map +1 -1
  128. package/dist/src/utils/numbers.js +16 -118
  129. package/dist/src/utils/numbers.js.map +1 -1
  130. package/dist/src/utils/numbers.test.js +24 -142
  131. package/dist/src/utils/numbers.test.js.map +1 -1
  132. package/package.json +2 -1
  133. package/src/api/auth.ts +1 -1
  134. package/src/components/Dropdown/Content.tsx +3 -48
  135. package/src/components/Dropdown/Dropdown.tsx +7 -55
  136. package/src/components/Dropdown/ListingItem.tsx +155 -59
  137. package/src/components/Dropdown/NestedViewLayout.tsx +32 -20
  138. package/src/components/Dropdown/Receive/Receive.tsx +69 -32
  139. package/src/components/Dropdown/Root/AccountAddressActions.tsx +64 -35
  140. package/src/components/Dropdown/Root/AccountBalance.tsx +54 -16
  141. package/src/components/Dropdown/Root/AccountBtcListing.tsx +52 -0
  142. package/src/components/Dropdown/Root/AccountError.tsx +34 -0
  143. package/src/components/Dropdown/Root/AccountMusdListing.tsx +45 -0
  144. package/src/components/Dropdown/Root/AccountOtherAssets.tsx +63 -46
  145. package/src/components/Dropdown/Root/Root.tsx +28 -98
  146. package/src/components/Dropdown/Root/WalletAddress.tsx +95 -89
  147. package/src/components/Dropdown/Root/WelcomeBlock.tsx +109 -29
  148. package/src/components/Dropdown/SlotNumber.tsx +131 -0
  149. package/src/config.ts +3 -59
  150. package/src/constants.ts +0 -6
  151. package/src/hooks/useAssetsConversionRates.ts +49 -67
  152. package/src/hooks/useAuthenticateWithWallet.ts +7 -5
  153. package/src/hooks/useBorrowData.ts +71 -12
  154. package/src/hooks/useCreateAccount.ts +5 -4
  155. package/src/hooks/useGetCurrentAccount.ts +5 -7
  156. package/src/hooks/useLinkAccount.ts +5 -4
  157. package/src/hooks/useTokensBalances.ts +152 -74
  158. package/src/hooks/useWalletAccount.ts +27 -36
  159. package/src/index.ts +0 -1
  160. package/src/lib/contracts/index.ts +8 -1
  161. package/src/provider.ts +11 -3
  162. package/src/utils/assets.test.ts +57 -0
  163. package/src/utils/assets.ts +103 -0
  164. package/src/utils/currency.test.ts +76 -2
  165. package/src/utils/currency.ts +20 -15
  166. package/src/utils/numbers.test.ts +29 -180
  167. package/src/utils/numbers.ts +22 -171
  168. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +0 -11
  169. package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +0 -1
  170. package/dist/src/components/Dropdown/Root/AccountAssetItem.js +0 -9
  171. package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +0 -1
  172. package/dist/src/hooks/useDropdownData.d.ts +0 -47
  173. package/dist/src/hooks/useDropdownData.d.ts.map +0 -1
  174. package/dist/src/hooks/useDropdownData.js +0 -97
  175. package/dist/src/hooks/useDropdownData.js.map +0 -1
  176. package/dist/src/utils/cryptoAssets.d.ts +0 -44
  177. package/dist/src/utils/cryptoAssets.d.ts.map +0 -1
  178. package/dist/src/utils/cryptoAssets.js +0 -129
  179. package/dist/src/utils/cryptoAssets.js.map +0 -1
  180. package/dist/src/utils/cryptoAssets.test.d.ts +0 -2
  181. package/dist/src/utils/cryptoAssets.test.d.ts.map +0 -1
  182. package/dist/src/utils/cryptoAssets.test.js +0 -67
  183. package/dist/src/utils/cryptoAssets.test.js.map +0 -1
  184. package/src/components/Dropdown/Root/AccountAssetItem.tsx +0 -26
  185. package/src/hooks/useDropdownData.ts +0 -152
  186. package/src/utils/cryptoAssets.test.ts +0 -79
  187. package/src/utils/cryptoAssets.ts +0 -171
@@ -1,6 +1,5 @@
1
- type DesiredDecimals = Intl.NumberFormatOptions &
1
+ type CompactStringDecimals = Intl.NumberFormatOptions["minimumFractionDigits"] &
2
2
  BigIntToLocaleStringOptions["minimumFractionDigits"]
3
-
4
3
  /**
5
4
  * Formats a number or bigint into compact string with K, M, B, or T suffix.
6
5
  * @param value The number or bigint to format.
@@ -9,189 +8,41 @@ type DesiredDecimals = Intl.NumberFormatOptions &
9
8
  */
10
9
  export function formatNumberToCompactString(
11
10
  value: number | bigint,
12
- decimals = 4,
11
+ decimals: CompactStringDecimals = 2,
13
12
  ): string {
14
13
  return value.toLocaleString("en-US", {
15
14
  notation: "compact",
16
15
  compactDisplay: "short",
17
- maximumFractionDigits: decimals as DesiredDecimals,
16
+ maximumFractionDigits: decimals,
18
17
  })
19
18
  }
20
19
 
21
20
  /**
22
- * Formats a number or string into a locale-sensitive string with the desired number of decimals.
23
- * @param value The number or string to format.
24
- * @param desiredDecimals The number of decimal places to include.
25
- * @returns The formatted number as a string.
26
- * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L5-L19
27
- */
28
- export function formatNumberToLocaleString(
29
- value: string | number,
30
- desiredDecimals = 0,
31
- ) {
32
- const number = typeof value === "number" ? value : parseFloat(value)
33
-
34
- if (number === 0 && desiredDecimals === 0) return "0"
35
-
36
- if (number === 0) return `0.${"0".repeat(desiredDecimals)}`
37
-
38
- return number.toLocaleString("en-US", {
39
- minimumFractionDigits: desiredDecimals,
40
- maximumFractionDigits: desiredDecimals,
41
- })
42
- }
43
-
44
- /**
45
- * Returns a number rounded up to the desired number of decimals.
46
- * @param amount The number to round up.
47
- * @param desiredDecimals The number of decimals to round up to.
48
- * @returns The rounded up number.
49
- * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L1-L3
50
- */
51
- export function roundUpNumber(amount: number, desiredDecimals = 2): number {
52
- return Math.ceil(amount * 10 ** desiredDecimals) / 10 ** desiredDecimals
53
- }
54
-
55
- /**
56
- * Convert a fixed point bigint with precision `fixedPointDecimals` to a
57
- * floating point number truncated to `desiredDecimals`.
58
- * @param fixedPoint The fixed point bigint to convert.
59
- * @param fixedPointDecimals The number of decimals in the fixed point bigint.
60
- * @param desiredDecimals The number of decimals in the output number.
61
- * @returns The floating point number truncated to `desiredDecimals`.
62
- * @see https://github.com/tahowallet/extension/blob/f6b26b7cb4a0a0278b1fccc6319626638f1a6dfa/background/lib/fixed-point.ts#L216-L239
21
+ * Normalizes a bigint value to a target precision.
22
+ * @param value The bigint value to normalize.
23
+ * @param currentPrecision The current precision of the value.
24
+ * @param targetPrecision The target precision to normalize to.
25
+ * @returns The normalized bigint value.
63
26
  */
64
- export function fromFixedPoint(
65
- fixedPoint: bigint,
66
- fixedPointDecimals: number,
67
- desiredDecimals = 4,
68
- ): number {
69
- const fixedPointDesiredDecimalsAmount =
70
- fixedPoint /
71
- 10n ** BigInt(Math.max(1, fixedPointDecimals - desiredDecimals))
72
-
73
- const formattedAmount =
74
- Number(fixedPointDesiredDecimalsAmount) /
75
- 10 ** Math.min(desiredDecimals, fixedPointDecimals)
76
-
77
- return formattedAmount
78
- }
79
-
80
- /**
81
- * Display a token amount correctly with desired decimals.
82
- * The function returns a string with a language-sensitive representation of this number.
83
- * @param amount The fixed point number to convert.
84
- * @param decimals The number of decimals in the fixed point number.
85
- * @param desiredDecimals The number of decimals to display.
86
- * @param withRoundUp Whether to round up the number.
87
- * @returns The formatted number as a string.
88
- * @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L57-L87
89
- */
90
- export const fromFixedPointToString = (
91
- amount: number | string | bigint,
92
- decimals = 18,
93
- desiredDecimals = 4,
94
- withRoundUp = false,
95
- ) => {
96
- const fixedPoint = BigInt(amount)
97
-
98
- if (fixedPoint === 0n) {
99
- return `0.${"0".repeat(desiredDecimals)}`
100
- }
101
-
102
- const formattedAmount = fromFixedPoint(
103
- fixedPoint,
104
- decimals,
105
- // To round the amount up, let's increase the precision by one.
106
- // The desired decimal numbers will be set later anyway.
107
- withRoundUp ? desiredDecimals + 1 : desiredDecimals,
108
- )
109
-
110
- const minAmountToDisplay = 1 / 10 ** Math.min(desiredDecimals, decimals)
111
-
112
- if (minAmountToDisplay > formattedAmount) {
113
- return `<0.${"0".repeat(desiredDecimals - 1)}1`
114
- }
115
-
116
- const finalFormattedAmount = withRoundUp
117
- ? Math.ceil(formattedAmount * 10 ** desiredDecimals) / 10 ** desiredDecimals
118
- : formattedAmount
119
- return formatNumberToLocaleString(finalFormattedAmount, desiredDecimals)
120
- }
121
-
122
- /**
123
- * Converts a floating-point number or string to a bigint representation
124
- * scaled by the specified number of decimal places (default: 18).
125
- *
126
- * This function avoids floating-point precision issues by manually
127
- * parsing and scaling the number.
128
- *
129
- * @param amount - A number or string containing a floating point number.
130
- * @param decimals - Number of decimals to scale to (default: 18).
131
- * @returns A bigint representation scaled to the given decimal places.
132
- * @see https://github.com/thesis/mezo-portal/blob/3bd4f39cb77c39948af2886a6ce7415a0c60307a/dapp/src/shared/utils/numbers.ts#L55
133
- */
134
- export const fromFloatToBigInt = (
135
- amount: string | number,
136
- decimals = 18,
27
+ export const normalizePrecision = (
28
+ value: bigint,
29
+ currentPrecision: number,
30
+ targetPrecision = currentPrecision,
137
31
  ): bigint => {
138
- const FLOATING_POINT_REGEX = /^-?\d{1,3}(,\d{3})*(\.\d+)?$|^-?\d+(\.\d+)?$/
139
-
140
- const parseToFixedPointNumber = (
141
- floatingPointString: string,
142
- ): { amount: bigint; decimals: number } | undefined => {
143
- if (!floatingPointString.match(FLOATING_POINT_REGEX)) {
144
- return undefined
145
- }
146
-
147
- const [whole, decimalsPart, ...extra] = floatingPointString.split(".")
148
-
149
- if (extra.length > 0) return undefined
150
-
151
- const noThousandsSeparatorWhole = whole.replace(/,/g, "")
152
- const setDecimals = decimalsPart ?? ""
153
-
154
- try {
155
- return {
156
- amount: BigInt([noThousandsSeparatorWhole, setDecimals].join("")),
157
- decimals: setDecimals.length,
158
- }
159
- } catch {
160
- return undefined
161
- }
162
- }
163
-
164
- const convertFixedPoint = (
165
- fixedPoint: bigint,
166
- fixedPointDecimals: number,
167
- targetDecimals: number,
168
- ): bigint => {
169
- if (fixedPointDecimals >= targetDecimals) {
170
- return fixedPoint / 10n ** BigInt(fixedPointDecimals - targetDecimals)
171
- }
172
-
173
- return fixedPoint * 10n ** BigInt(targetDecimals - fixedPointDecimals)
32
+ if (currentPrecision > targetPrecision) {
33
+ return value / 10n ** BigInt(currentPrecision - targetPrecision)
174
34
  }
175
-
176
- const parsedAmount = amount.toString()
177
- const fixedPointAmount = parseToFixedPointNumber(parsedAmount)
178
-
179
- if (typeof fixedPointAmount === "undefined") {
180
- return 0n
35
+ if (currentPrecision < targetPrecision) {
36
+ return value * 10n ** BigInt(targetPrecision - currentPrecision)
181
37
  }
182
-
183
- return convertFixedPoint(
184
- fixedPointAmount.amount,
185
- fixedPointAmount.decimals,
186
- decimals,
187
- )
38
+ return value
188
39
  }
189
40
 
190
41
  /**
191
- * Utility function to find the maximum value from an array of bigint values.
192
- * @param values Array of bigint values to find the maximum from.
193
- * @returns The maximum value from the provided bigint values.
194
- * @dev Works exactly like `Math.max` but for bigint values.
42
+ * Utility function to find the maximum value from given `BigInt` values.
43
+ * @param values Array of BigInt values to find the maximum from.
44
+ * @returns The maximum value from the provided `BigInt` values.
45
+ * @dev Works exactly like `Math.max` but for `BigInt` values.
195
46
  */
196
- export const bigIntMax = (...values: bigint[]) =>
47
+ export const bigIntMax = (...values: bigint[]): bigint =>
197
48
  values.reduce((max, value) => (value > max ? value : max))
@@ -1,11 +0,0 @@
1
- import React from "react";
2
- import { CryptoAssetKey } from "../../../utils/cryptoAssets";
3
- type AccountAssetItemProps = {
4
- type: CryptoAssetKey;
5
- amount: string;
6
- subLabel: string;
7
- subValue: string;
8
- };
9
- export default function AccountAssetItem(props: AccountAssetItemProps): React.JSX.Element;
10
- export {};
11
- //# sourceMappingURL=AccountAssetItem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountAssetItem.d.ts","sourceRoot":"","sources":["../../../../../src/components/Dropdown/Root/AccountAssetItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,EAAkB,MAAM,6BAA6B,CAAA;AAG5E,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,cAAc,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,qBAcpE"}
@@ -1,9 +0,0 @@
1
- import React from "react";
2
- import { getCryptoAsset } from "../../../utils/cryptoAssets";
3
- import ListingItem from "../ListingItem";
4
- export default function AccountAssetItem(props) {
5
- const { type, amount, subLabel, subValue } = props;
6
- const { icon: Icon, name: label } = getCryptoAsset(type);
7
- return (React.createElement(ListingItem, { icon: Icon, label: label, subLabel: subLabel, value: amount, subValue: subValue }));
8
- }
9
- //# sourceMappingURL=AccountAssetItem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountAssetItem.js","sourceRoot":"","sources":["../../../../../src/components/Dropdown/Root/AccountAssetItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAkB,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5E,OAAO,WAAW,MAAM,gBAAgB,CAAA;AASxC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAA4B;IACnE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAElD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IAExD,OAAO,CACL,oBAAC,WAAW,IACV,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,QAAQ,GAClB,CACH,CAAA;AACH,CAAC"}
@@ -1,47 +0,0 @@
1
- import { CryptoAssetKey } from "../utils/cryptoAssets";
2
- export type DropdownCryptoAsset<T = CryptoAssetKey> = {
3
- type: T;
4
- balance: bigint;
5
- };
6
- /**
7
- * Aggregates dropdown data for Dropdown component.
8
- * @param {accountDataRefetchInterval: number, nativeBalanceRefetchInterval: number }
9
- * Object containing refetch intervals time (in milliseconds) for account data
10
- * (like mats or mezo id) and for native balance. After that time the specific
11
- * value should be marked as stale and re-fetched. Default value for both is
12
- * 90000 (90 secs).
13
- * @returns Dropdown data.
14
- * @dev This hook is for internal use only.
15
- */
16
- export default function useDropdownData({ accountDataRefetchInterval, nativeBalanceRefetchInterval, }: {
17
- accountDataRefetchInterval?: number | undefined;
18
- nativeBalanceRefetchInterval?: number | undefined;
19
- }): {
20
- mezoId: string | undefined;
21
- matsBalance: number;
22
- accountAddress: `0x${string}` | undefined;
23
- walletAddress: string | undefined;
24
- walletType: "bitcoin" | "evm";
25
- usdTotalBalance: number;
26
- usdTroveDebt: number;
27
- usdCollateral: number;
28
- assets: {
29
- btc: {
30
- type: CryptoAssetKey;
31
- rawBalance: bigint;
32
- formattedBalance: string;
33
- usdBalance: number;
34
- formattedUsdBalance: string;
35
- };
36
- musd: {
37
- type: CryptoAssetKey;
38
- rawBalance: bigint;
39
- formattedBalance: string;
40
- usdBalance: number;
41
- formattedUsdBalance: string;
42
- };
43
- };
44
- otherAssetsCount: number;
45
- otherAssetsUsdTotal: number;
46
- };
47
- //# sourceMappingURL=useDropdownData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDropdownData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useDropdownData.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EAIf,MAAM,uBAAuB,CAAA;AAW9B,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,cAAc,IAAI;IACpD,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AASD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,0BAAkC,EAClC,4BAAoC,GACrC;;;CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4GA"}
@@ -1,97 +0,0 @@
1
- import { useBalance } from "wagmi";
2
- import { useGetCurrentAccount } from ".";
3
- import { getCryptoAsset, isBitcoinLikeCryptoAsset, mapCryptoAssetToDetails, } from "../utils/cryptoAssets";
4
- import { fromFixedPoint } from "../utils/numbers";
5
- import { useAssetsConversionRates } from "./useAssetsConversionRates";
6
- import useWalletAccount from "./useWalletAccount";
7
- import { useTokensBalances } from "./useTokensBalances";
8
- import { useBorrowData } from "./useBorrowData";
9
- import { CHAIN_ID } from "../constants";
10
- import { usePassportContext } from "./usePassportContext";
11
- import { useWatchTransferEventsForAllTokens } from "./useWatchTransferEvents";
12
- import { convertToUsd } from "../utils/currency";
13
- const DEFAULT_ASSET_DATA = {
14
- rawBalance: 0n,
15
- formattedBalance: "0.0000",
16
- usdBalance: 0,
17
- formattedUsdBalance: "$0.00",
18
- };
19
- /**
20
- * Aggregates dropdown data for Dropdown component.
21
- * @param {accountDataRefetchInterval: number, nativeBalanceRefetchInterval: number }
22
- * Object containing refetch intervals time (in milliseconds) for account data
23
- * (like mats or mezo id) and for native balance. After that time the specific
24
- * value should be marked as stale and re-fetched. Default value for both is
25
- * 90000 (90 secs).
26
- * @returns Dropdown data.
27
- * @dev This hook is for internal use only.
28
- */
29
- export default function useDropdownData({ accountDataRefetchInterval = 90000, nativeBalanceRefetchInterval = 90000, }) {
30
- const { walletAddress, accountAddress, networkFamily: walletType, } = useWalletAccount();
31
- const { environment = "mainnet" } = usePassportContext();
32
- const { data: btcBalance } = useBalance({
33
- address: accountAddress,
34
- chainId: CHAIN_ID[environment],
35
- query: {
36
- staleTime: nativeBalanceRefetchInterval,
37
- refetchInterval: nativeBalanceRefetchInterval,
38
- },
39
- });
40
- const { data: passportAccount } = useGetCurrentAccount({
41
- staleTime: accountDataRefetchInterval,
42
- refetchInterval: accountDataRefetchInterval,
43
- enabled: !!accountAddress,
44
- });
45
- const { data: assetsConversionRates } = useAssetsConversionRates();
46
- const { data: tokensBalances } = useTokensBalances();
47
- const { data: debt } = useBorrowData();
48
- useWatchTransferEventsForAllTokens();
49
- const mezoId = passportAccount?.mezoId;
50
- const detailedAssets = [
51
- ["BTC", btcBalance?.value ?? 0n],
52
- ...Object.entries(tokensBalances ?? {}),
53
- ].map((asset) => {
54
- const [type, balance] = asset;
55
- if (isBitcoinLikeCryptoAsset(type)) {
56
- return mapCryptoAssetToDetails(type, balance, assetsConversionRates.btc.price, assetsConversionRates.btc.decimals);
57
- }
58
- if (type === "mT") {
59
- return mapCryptoAssetToDetails(type, balance, assetsConversionRates.t.price, assetsConversionRates.t.decimals);
60
- }
61
- return mapCryptoAssetToDetails(type, balance, 1n, 0);
62
- });
63
- const btcData = detailedAssets.find(({ type }) => type === "BTC");
64
- const musdData = detailedAssets.find(({ type }) => type === "MUSD");
65
- const otherAssetsData = detailedAssets.filter(({ type }) => !["BTC", "MUSD"].includes(type));
66
- const otherAssetsCount = otherAssetsData.filter((asset) => asset.rawBalance !== 0n).length;
67
- const assets = {
68
- btc: btcData || {
69
- type: "BTC",
70
- ...DEFAULT_ASSET_DATA,
71
- },
72
- musd: musdData || {
73
- type: "mUSD",
74
- ...DEFAULT_ASSET_DATA,
75
- },
76
- };
77
- const otherAssetsUsdTotal = otherAssetsData.reduce((sum, { usdBalance }) => sum + usdBalance, 0);
78
- const matsBalance = passportAccount?.mats.totalMats || 0;
79
- const usdCollateral = convertToUsd(debt?.collateral ?? 0n, getCryptoAsset("MUSD").decimals, assetsConversionRates.btc.price, assetsConversionRates.btc.decimals);
80
- const usdTroveDebt = fromFixedPoint(debt?.troveDebt ?? 0n, 18);
81
- const usdTotalBalance = detailedAssets.reduce((sum, { usdBalance }) => sum + usdBalance, 0) +
82
- usdCollateral;
83
- return {
84
- mezoId,
85
- matsBalance,
86
- accountAddress,
87
- walletAddress,
88
- walletType,
89
- usdTotalBalance,
90
- usdTroveDebt,
91
- usdCollateral,
92
- assets,
93
- otherAssetsCount,
94
- otherAssetsUsdTotal,
95
- };
96
- }
97
- //# sourceMappingURL=useDropdownData.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDropdownData.js","sourceRoot":"","sources":["../../../src/hooks/useDropdownData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,GAAG,CAAA;AACxC,OAAO,EAEL,cAAc,EACd,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,kCAAkC,EAAE,MAAM,0BAA0B,CAAA;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAOhD,MAAM,kBAAkB,GAAG;IACzB,UAAU,EAAE,EAAE;IACd,gBAAgB,EAAE,QAAQ;IAC1B,UAAU,EAAE,CAAC;IACb,mBAAmB,EAAE,OAAO;CAC7B,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,0BAA0B,GAAG,KAAK,EAClC,4BAA4B,GAAG,KAAK,GACrC;IACC,MAAM,EACJ,aAAa,EACb,cAAc,EACd,aAAa,EAAE,UAAU,GAC1B,GAAG,gBAAgB,EAAE,CAAA;IACtB,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,GAAG,kBAAkB,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CAAC,MAAM,CAAC,CAAC,QAAQ,EAC/B,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAC/B,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CACnC,CAAA;IAED,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,EAAE,SAAS,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;IAE9D,MAAM,eAAe,GACnB,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,EAAE,CAAC,CAAC;QACnE,aAAa,CAAA;IAEf,OAAO;QACL,MAAM;QACN,WAAW;QACX,cAAc;QACd,aAAa;QACb,UAAU;QACV,eAAe;QACf,YAAY;QACZ,aAAa;QACb,MAAM;QACN,gBAAgB;QAChB,mBAAmB;KACpB,CAAA;AACH,CAAC"}
@@ -1,44 +0,0 @@
1
- import { IconProps } from "@mezo-org/mezo-clay";
2
- import { FC } from "react";
3
- import { MezoChainToken } from "../lib/contracts";
4
- export type CryptoAssetKey = MezoChainToken | "BTC" | "ETH";
5
- export type CryptoAsset = {
6
- name: string;
7
- symbol: string;
8
- icon: FC<IconProps>;
9
- decimals: number;
10
- };
11
- /**
12
- * Gets details of given crypto asset
13
- * @param key The key of crypto asset
14
- * @returns The crypto asset details
15
- */
16
- export declare function getCryptoAsset(key: CryptoAssetKey): CryptoAsset;
17
- /**
18
- * Checks if given crypto asset is Bitcoin-like
19
- * @param key The key of crypto asset
20
- * @returns True if crypto asset is Bitcoin-like
21
- */
22
- export declare function isBitcoinLikeCryptoAsset(key: CryptoAssetKey): boolean;
23
- /**
24
- * Checks if given crypto asset is USD-like
25
- * @param key The key of crypto asset
26
- * @returns True if crypto asset is USD-like
27
- */
28
- export declare function isUsdLikeCryptoAsset(key: CryptoAssetKey): boolean;
29
- /**
30
- * Formats crypto asset to balance details (balance in USD and decimals)
31
- * @param type The type of crypto asset
32
- * @param balance The balance of crypto asset
33
- * @param usdConversionRate The USD conversion rate
34
- * @returns The balance details
35
- */
36
- export declare function mapCryptoAssetToDetails(type: CryptoAssetKey, balance: bigint, usdConversionRate: bigint, usdConversionRateDecimals: number): {
37
- type: CryptoAssetKey;
38
- rawBalance: bigint;
39
- formattedBalance: string;
40
- usdBalance: number;
41
- formattedUsdBalance: string;
42
- };
43
- export type DetailedCryptoAsset = ReturnType<typeof mapCryptoAssetToDetails>;
44
- //# sourceMappingURL=cryptoAssets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cryptoAssets.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EAGV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAIjD,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,KAAK,GAAG,KAAK,CAAA;AAE3D,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAqFD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,eAEjD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,cAAc,WAE3D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,cAAc,WAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,MAAM,EACzB,yBAAyB,EAAE,MAAM;;;;;;EA0BlC;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAA"}
@@ -1,129 +0,0 @@
1
- import { BitcoinCircle, EthCircle, MUsdCircle02, Cryptocurrency04, } from "@mezo-org/mezo-clay";
2
- import { convertToUsd, formatUsd } from "./currency";
3
- import { fromFixedPointToString } from "./numbers";
4
- // TODO: Add actual icons for the assets
5
- const CRYPTO_ASSETS = {
6
- BTC: {
7
- name: "Bitcoin",
8
- symbol: "BTC",
9
- icon: BitcoinCircle,
10
- decimals: 18,
11
- },
12
- ETH: {
13
- name: "Ethereum",
14
- symbol: "ETH",
15
- icon: EthCircle,
16
- decimals: 18,
17
- },
18
- MUSD: {
19
- name: "MUSD",
20
- symbol: "MUSD",
21
- icon: MUsdCircle02,
22
- decimals: 18,
23
- },
24
- mDAI: {
25
- name: "mDAI",
26
- symbol: "mDAI",
27
- icon: Cryptocurrency04,
28
- decimals: 18,
29
- },
30
- mFBTC: {
31
- name: "mFBTC",
32
- symbol: "mFBTC",
33
- icon: BitcoinCircle,
34
- decimals: 8,
35
- },
36
- mcbBTC: {
37
- name: "mcbBTC",
38
- symbol: "mcbBTC",
39
- icon: BitcoinCircle,
40
- decimals: 8,
41
- },
42
- mSolvBTC: {
43
- name: "mSolvBTC",
44
- symbol: "mSolvBTC",
45
- icon: BitcoinCircle,
46
- decimals: 18,
47
- },
48
- mswBTC: {
49
- name: "mswBTC",
50
- symbol: "mswBTC",
51
- icon: BitcoinCircle,
52
- decimals: 8,
53
- },
54
- mT: {
55
- name: "mT",
56
- symbol: "mT",
57
- icon: Cryptocurrency04,
58
- decimals: 18,
59
- },
60
- mUSDC: {
61
- name: "mUSDC",
62
- symbol: "mUSDC",
63
- icon: Cryptocurrency04,
64
- decimals: 6,
65
- },
66
- mUSDe: {
67
- name: "mUSDe",
68
- symbol: "mUSDe",
69
- icon: Cryptocurrency04,
70
- decimals: 18,
71
- },
72
- mUSDT: {
73
- name: "mUSDT",
74
- symbol: "mUSDT",
75
- icon: Cryptocurrency04,
76
- decimals: 6,
77
- },
78
- mxSolvBTC: {
79
- name: "mxSolvBTC",
80
- symbol: "mxSolvBTC",
81
- icon: BitcoinCircle,
82
- decimals: 18,
83
- },
84
- };
85
- /**
86
- * Gets details of given crypto asset
87
- * @param key The key of crypto asset
88
- * @returns The crypto asset details
89
- */
90
- export function getCryptoAsset(key) {
91
- return CRYPTO_ASSETS[key];
92
- }
93
- /**
94
- * Checks if given crypto asset is Bitcoin-like
95
- * @param key The key of crypto asset
96
- * @returns True if crypto asset is Bitcoin-like
97
- */
98
- export function isBitcoinLikeCryptoAsset(key) {
99
- return /(btc)/i.test(key);
100
- }
101
- /**
102
- * Checks if given crypto asset is USD-like
103
- * @param key The key of crypto asset
104
- * @returns True if crypto asset is USD-like
105
- */
106
- export function isUsdLikeCryptoAsset(key) {
107
- return /(usd|dai)/i.test(key);
108
- }
109
- /**
110
- * Formats crypto asset to balance details (balance in USD and decimals)
111
- * @param type The type of crypto asset
112
- * @param balance The balance of crypto asset
113
- * @param usdConversionRate The USD conversion rate
114
- * @returns The balance details
115
- */
116
- export function mapCryptoAssetToDetails(type, balance, usdConversionRate, usdConversionRateDecimals) {
117
- const { decimals } = getCryptoAsset(type);
118
- const formattedBalance = fromFixedPointToString(balance, decimals, isUsdLikeCryptoAsset(type) ? 2 : 4);
119
- const usdBalance = convertToUsd(balance, decimals, usdConversionRate, usdConversionRateDecimals);
120
- const formattedUsdBalance = formatUsd(usdBalance);
121
- return {
122
- type,
123
- rawBalance: balance,
124
- formattedBalance,
125
- usdBalance,
126
- formattedUsdBalance,
127
- };
128
- }
129
- //# sourceMappingURL=cryptoAssets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cryptoAssets.js","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,SAAS,EAET,YAAY,EACZ,gBAAgB,GACjB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW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ACnB,gBAAgB;QAChB,UAAU;QACV,mBAAmB;KACpB,CAAA;AACH,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=cryptoAssets.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cryptoAssets.test.d.ts","sourceRoot":"","sources":["../../../src/utils/cryptoAssets.test.ts"],"names":[],"mappings":""}
@@ -1,67 +0,0 @@
1
- import { BitcoinCircle, EthCircle, MUsdCircle02 } from "@mezo-org/mezo-clay";
2
- import { getCryptoAsset, isBitcoinLikeCryptoAsset, isUsdLikeCryptoAsset, } from "./cryptoAssets";
3
- // FIXME: Test fails if run in full suite (pnpm test) but works when run in isolation (pnpm test cryptoAssets)
4
- describe("getCryptoAsset", () => {
5
- it("returns the correct asset for 'BTC (mBTC)'", () => {
6
- const asset = getCryptoAsset("BTC");
7
- expect(asset.name).toBe("Bitcoin");
8
- expect(asset.symbol).toBe("BTC");
9
- expect(asset.decimals).toBe(18);
10
- expect(asset.icon).toBe(BitcoinCircle);
11
- });
12
- it("returns the correct asset for 'ETH'", () => {
13
- const asset = getCryptoAsset("ETH");
14
- expect(asset.name).toBe("Ethereum");
15
- expect(asset.symbol).toBe("ETH");
16
- expect(asset.decimals).toBe(18);
17
- expect(asset.icon).toBe(EthCircle);
18
- });
19
- it("returns the correct asset for 'MUSD'", () => {
20
- const asset = getCryptoAsset("MUSD");
21
- expect(asset.name).toBe("MUSD");
22
- expect(asset.symbol).toBe("MUSD");
23
- expect(asset.decimals).toBe(18);
24
- expect(asset.icon).toBe(MUsdCircle02);
25
- });
26
- });
27
- describe("isBitcoinLikeCryptoAsset", () => {
28
- const cases = [
29
- { input: "mcbBTC", expected: true },
30
- { input: "mDAI", expected: false },
31
- { input: "mFBTC", expected: true },
32
- { input: "mSolvBTC", expected: true },
33
- { input: "mswBTC", expected: true },
34
- { input: "mT", expected: false },
35
- { input: "mUSDC", expected: false },
36
- { input: "mUSDe", expected: false },
37
- { input: "mUSDT", expected: false },
38
- { input: "mxSolvBTC", expected: true },
39
- { input: "MUSD", expected: false },
40
- ];
41
- cases.forEach(({ input, expected }) => {
42
- it(`returns ${expected} for ${input}`, () => {
43
- expect(isBitcoinLikeCryptoAsset(input)).toBe(expected);
44
- });
45
- });
46
- });
47
- describe("isUsdLikeCryptoAsset", () => {
48
- const cases = [
49
- { input: "mcbBTC", expected: false },
50
- { input: "mDAI", expected: true },
51
- { input: "mFBTC", expected: false },
52
- { input: "mSolvBTC", expected: false },
53
- { input: "mswBTC", expected: false },
54
- { input: "mT", expected: false },
55
- { input: "mUSDC", expected: true },
56
- { input: "mUSDe", expected: true },
57
- { input: "mUSDT", expected: true },
58
- { input: "mxSolvBTC", expected: false },
59
- { input: "MUSD", expected: true },
60
- ];
61
- cases.forEach(({ input, expected }) => {
62
- it(`returns ${expected} for ${input}`, () => {
63
- expect(isUsdLikeCryptoAsset(input)).toBe(expected);
64
- });
65
- });
66
- });
67
- //# sourceMappingURL=cryptoAssets.test.js.map