@mezo-org/passport 0.4.0-dev.7 → 0.4.0-dev.70
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.
- package/README.md +18 -22
- package/dist/src/api/auth.d.ts +7 -3
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +3 -1
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +4 -1
- package/dist/src/api/client.d.ts.map +1 -1
- package/dist/src/api/client.js +9 -2
- package/dist/src/api/client.js.map +1 -1
- package/dist/src/api/portal.d.ts +3 -9
- package/dist/src/api/portal.d.ts.map +1 -1
- package/dist/src/api/portal.js +8 -5
- package/dist/src/api/portal.js.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +2 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/ConnectedTrigger.js +29 -20
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Content.d.ts +19 -5
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Content.js +19 -61
- package/dist/src/components/Dropdown/Content.js.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -1
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +2 -2
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.d.ts +13 -6
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/src/components/Dropdown/Dropdown.js +32 -9
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +34 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
- package/dist/src/components/Dropdown/{AccountBalance.d.ts → Root/AccountBalance.d.ts} +2 -1
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +57 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/{AccountAddress.js → Root/WalletAddress.js} +21 -15
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.d.ts → Root/WelcomeBlock.d.ts} +1 -1
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/{WelcomeBlock.js → Root/WelcomeBlock.js} +5 -5
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
- package/dist/src/config.d.ts +18 -5
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +45 -14
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +11 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +12 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +90 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +9 -9
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBorrowData.d.ts +82 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +159 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +22 -1
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +37 -34
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -1
- package/dist/src/hooks/useDropdownData.js +85 -61
- package/dist/src/hooks/useDropdownData.js.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +19 -13
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +20 -1
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
- package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
- package/dist/src/hooks/useRefreshPassport.js +44 -0
- package/dist/src/hooks/useRefreshPassport.js.map +1 -0
- package/dist/src/hooks/useTokensBalances.d.ts +74 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +140 -0
- package/dist/src/hooks/useTokensBalances.js.map +1 -0
- package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
- package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useValidateMezoId.js +24 -0
- package/dist/src/hooks/useValidateMezoId.js.map +1 -0
- package/dist/src/hooks/useWalletAccount.d.ts +2 -1
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
- package/dist/src/hooks/useWalletAccount.js +19 -15
- package/dist/src/hooks/useWalletAccount.js.map +1 -1
- package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.js +63 -0
- package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +13 -0
- package/dist/src/lib/contracts/index.d.ts.map +1 -0
- package/dist/src/lib/contracts/index.js +62 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
- package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
- package/dist/src/lib/contracts/priceOracle.js +52 -0
- package/dist/src/lib/contracts/priceOracle.js.map +1 -0
- package/dist/src/provider.js +1 -1
- package/dist/src/provider.js.map +1 -1
- package/dist/src/stores/dropdownStore.d.ts +12 -0
- package/dist/src/stores/dropdownStore.d.ts.map +1 -0
- package/dist/src/stores/dropdownStore.js +13 -0
- package/dist/src/stores/dropdownStore.js.map +1 -0
- package/dist/src/utils/address.d.ts +1 -1
- package/dist/src/utils/address.d.ts.map +1 -1
- package/dist/src/utils/address.js +2 -0
- package/dist/src/utils/address.js.map +1 -1
- package/dist/src/utils/address.test.js +8 -5
- package/dist/src/utils/address.test.js.map +1 -1
- package/dist/src/utils/cryptoAssets.d.ts +17 -1
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -1
- package/dist/src/utils/cryptoAssets.js +87 -31
- package/dist/src/utils/cryptoAssets.js.map +1 -1
- package/dist/src/utils/cryptoAssets.test.js +51 -33
- package/dist/src/utils/cryptoAssets.test.js.map +1 -1
- package/dist/src/utils/currency.d.ts +8 -0
- package/dist/src/utils/currency.d.ts.map +1 -1
- package/dist/src/utils/currency.js +11 -0
- package/dist/src/utils/currency.js.map +1 -1
- package/dist/src/utils/currency.test.js +1 -0
- package/dist/src/utils/currency.test.js.map +1 -1
- package/dist/src/utils/mezoId.d.ts +3 -0
- package/dist/src/utils/mezoId.d.ts.map +1 -0
- package/dist/src/utils/mezoId.js +41 -0
- package/dist/src/utils/mezoId.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +39 -17
- package/dist/src/utils/numbers.d.ts.map +1 -1
- package/dist/src/utils/numbers.js +91 -33
- package/dist/src/utils/numbers.js.map +1 -1
- package/dist/src/utils/numbers.test.js +144 -22
- package/dist/src/utils/numbers.test.js.map +1 -1
- package/dist/src/utils/siww.d.ts +1 -0
- package/dist/src/utils/siww.d.ts.map +1 -1
- package/dist/src/utils/siww.js +50 -12
- package/dist/src/utils/siww.js.map +1 -1
- package/dist/src/utils/wagmi.d.ts +3 -0
- package/dist/src/utils/wagmi.d.ts.map +1 -0
- package/dist/src/utils/wagmi.js +7 -0
- package/dist/src/utils/wagmi.js.map +1 -0
- package/dist/src/wallet/index.d.ts +1 -1
- package/dist/src/wallet/index.d.ts.map +1 -1
- package/dist/src/wallet/index.js +1 -1
- package/dist/src/wallet/index.js.map +1 -1
- package/package.json +10 -8
- package/src/api/auth.ts +8 -4
- package/src/api/client.ts +11 -2
- package/src/api/portal.ts +11 -14
- package/src/components/Dropdown/ConnectedTrigger.tsx +52 -32
- package/src/components/Dropdown/Content.tsx +67 -117
- package/src/components/Dropdown/DisconnectedTrigger.tsx +2 -1
- package/src/components/Dropdown/Dropdown.tsx +75 -15
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +10 -18
- package/src/components/Dropdown/Receive/Receive.tsx +119 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
- package/src/components/Dropdown/Root/Root.tsx +147 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
- package/src/components/Dropdown/{WelcomeBlock.tsx → Root/WelcomeBlock.tsx} +5 -6
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/config.ts +73 -20
- package/src/constants.ts +12 -4
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useAssetsConversionRates.ts +97 -0
- package/src/hooks/useAuthenticateWithWallet.ts +18 -12
- package/src/hooks/useBorrowData.ts +187 -0
- package/src/hooks/useCreateAccount.ts +28 -2
- package/src/hooks/useDropdownData.ts +119 -97
- package/src/hooks/useLinkAccount.ts +36 -4
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useValidateMezoId.ts +31 -0
- package/src/hooks/useWalletAccount.ts +29 -19
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +11 -1
- package/src/lib/contracts/index.ts +92 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +1 -1
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +10 -6
- package/src/utils/address.ts +5 -3
- package/src/utils/cryptoAssets.test.ts +57 -37
- package/src/utils/cryptoAssets.ts +113 -35
- package/src/utils/currency.test.ts +2 -0
- package/src/utils/currency.ts +21 -0
- package/src/utils/mezoId.ts +50 -0
- package/src/utils/numbers.test.ts +181 -23
- package/src/utils/numbers.ts +121 -34
- package/src/utils/siww.ts +71 -16
- package/src/utils/wagmi.ts +12 -0
- package/src/wallet/index.ts +3 -2
- package/dist/src/components/Dropdown/AccountAddress.d.ts +0 -8
- package/dist/src/components/Dropdown/AccountAddress.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAddress.js.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.d.ts +0 -14
- package/dist/src/components/Dropdown/AccountAssets.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountAssets.js +0 -44
- package/dist/src/components/Dropdown/AccountAssets.js.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.d.ts.map +0 -1
- package/dist/src/components/Dropdown/AccountBalance.js +0 -18
- package/dist/src/components/Dropdown/AccountBalance.js.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.d.ts.map +0 -1
- package/dist/src/components/Dropdown/WelcomeBlock.js.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.d.ts +0 -8
- package/dist/src/hooks/useAssetsUSDConversion.d.ts.map +0 -1
- package/dist/src/hooks/useAssetsUSDConversion.js +0 -21
- package/dist/src/hooks/useAssetsUSDConversion.js.map +0 -1
- package/src/components/Dropdown/AccountAddress.tsx +0 -111
- package/src/components/Dropdown/AccountAssets.tsx +0 -110
- package/src/components/Dropdown/AccountBalance.tsx +0 -38
- package/src/hooks/useAssetsUSDConversion.ts +0 -31
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type MezoId = `${string}.mezo`
|
|
2
|
+
|
|
3
|
+
// NOTE: This was copied from mezo-portal and is based on the validation from
|
|
4
|
+
// workers/passport-auth/src/utils/mezo-id.ts.
|
|
5
|
+
|
|
6
|
+
// Most of these are restrictions for an DNS hostname label (i.e., the part
|
|
7
|
+
// before/after `.` in a full hostname) as outlined in RFC1034
|
|
8
|
+
// (https://www.rfc-editor.org/rfc/rfc1034).
|
|
9
|
+
//
|
|
10
|
+
// A few addenda are made to ensure that nothing can sneak through that could
|
|
11
|
+
// look like an Ethereum or Bitcoin address.
|
|
12
|
+
const DISALLOWED_MEZO_ID_PATTERNS: { pattern: RegExp; error: string }[] = [
|
|
13
|
+
// RFC1034.
|
|
14
|
+
{ pattern: /^$/, error: "Must not be empty." },
|
|
15
|
+
{ pattern: /^.{16,}$/, error: "Must have 15 characters or fewer." },
|
|
16
|
+
{
|
|
17
|
+
pattern: /^[^A-Za-z]/,
|
|
18
|
+
error: "Must start with a one of the letters A-Z or a-z.",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
pattern: /[^A-Za-z0-9-]/,
|
|
22
|
+
error:
|
|
23
|
+
"Must only use letters or numbers (A-Z, a-z, or 0-9), or hyphen (-).",
|
|
24
|
+
},
|
|
25
|
+
{ pattern: /-$/, error: "Must not end in a hyphen (-)." },
|
|
26
|
+
// On-chain shenanigan avoidance.
|
|
27
|
+
{ pattern: /0x/i, error: "Must not contain 0x." },
|
|
28
|
+
{
|
|
29
|
+
pattern: /^(?:bc1|tb1|[a-z]pub|[a-z]priv)/i,
|
|
30
|
+
error: "Must not start with a Bitcoin magic string.",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
pattern: /^m[0-9]+$/i,
|
|
34
|
+
error: 'No "m" + "numeric string" prefixes.',
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
export function validateMezoId(mezoId: string): string[] {
|
|
39
|
+
if (!/\.mezo$/.test(mezoId)) {
|
|
40
|
+
return ["Must end with '.mezo'."]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const mezoIdWithoutSuffix = mezoId.replace(/\.mezo$/, "")
|
|
44
|
+
|
|
45
|
+
const errors = DISALLOWED_MEZO_ID_PATTERNS.flatMap(({ pattern, error }) =>
|
|
46
|
+
pattern.test(mezoIdWithoutSuffix) ? [error] : [],
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return errors
|
|
50
|
+
}
|
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
formatTokenAmount,
|
|
2
|
+
formatNumberToCompactString,
|
|
4
3
|
fromFixedPoint,
|
|
5
4
|
roundUpNumber,
|
|
5
|
+
formatNumberToLocaleString,
|
|
6
|
+
fromFixedPointToString,
|
|
7
|
+
bigIntMax,
|
|
6
8
|
} from "./numbers"
|
|
7
9
|
|
|
8
|
-
describe("
|
|
10
|
+
describe("formatNumberToCompactString", () => {
|
|
9
11
|
it("formats number less than 1000 with decimals", () => {
|
|
10
|
-
expect(
|
|
12
|
+
expect(formatNumberToCompactString(123.456789, 2)).toBe("123.46")
|
|
11
13
|
})
|
|
12
14
|
|
|
13
15
|
it("formats thousands with K", () => {
|
|
14
|
-
expect(
|
|
16
|
+
expect(formatNumberToCompactString(12_345, 2)).toBe("12.35K")
|
|
15
17
|
})
|
|
16
18
|
|
|
17
19
|
it("formats millions with M", () => {
|
|
18
|
-
expect(
|
|
20
|
+
expect(formatNumberToCompactString(12_345_678, 2)).toBe("12.35M")
|
|
19
21
|
})
|
|
20
22
|
|
|
21
23
|
it("formats billions with B", () => {
|
|
22
|
-
expect(
|
|
24
|
+
expect(formatNumberToCompactString(12_345_678_901, 2)).toBe("12.35B")
|
|
23
25
|
})
|
|
24
26
|
|
|
25
27
|
it("formats trillions with T", () => {
|
|
26
|
-
expect(
|
|
28
|
+
expect(formatNumberToCompactString(12_345_678_901_234, 2)).toBe("12.35T")
|
|
27
29
|
})
|
|
28
30
|
|
|
29
31
|
it("formats bigint as readable number", () => {
|
|
30
|
-
expect(
|
|
32
|
+
expect(formatNumberToCompactString(1234567890123456789n, 2)).toBe(
|
|
33
|
+
"1,234,567.89T",
|
|
34
|
+
)
|
|
31
35
|
})
|
|
32
36
|
|
|
33
37
|
it("caps at > 1000T for huge numbers", () => {
|
|
34
38
|
const hugeNumber = 10 ** 18 // 1e18
|
|
35
|
-
expect(
|
|
39
|
+
expect(formatNumberToCompactString(hugeNumber, 2)).toBe("1,000,000T")
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it("formats numbers with trailing zeros correctly", () => {
|
|
43
|
+
expect(formatNumberToCompactString(1_000, 2)).toBe("1K")
|
|
36
44
|
})
|
|
37
45
|
})
|
|
38
46
|
|
|
@@ -53,7 +61,7 @@ describe("roundUpNumber", () => {
|
|
|
53
61
|
describe("fromFixedPoint", () => {
|
|
54
62
|
it("converts fixed point with 18 decimals to float", () => {
|
|
55
63
|
const raw = 1234567890000000000n // 1.23456789 ETH in 18 decimals
|
|
56
|
-
expect(fromFixedPoint(raw, 18
|
|
64
|
+
expect(fromFixedPoint(raw, 18)).toBe(1.2345)
|
|
57
65
|
})
|
|
58
66
|
|
|
59
67
|
it("converts with truncation to 2 decimals", () => {
|
|
@@ -67,23 +75,173 @@ describe("fromFixedPoint", () => {
|
|
|
67
75
|
})
|
|
68
76
|
})
|
|
69
77
|
|
|
70
|
-
describe("
|
|
71
|
-
it("formats zero
|
|
72
|
-
expect(
|
|
73
|
-
|
|
78
|
+
describe("formatNumberToLocaleString", () => {
|
|
79
|
+
it("formats zero with 0 decimals", () => {
|
|
80
|
+
expect(formatNumberToLocaleString(0, 0)).toBe("0")
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("formats zero with >0 decimals", () => {
|
|
84
|
+
expect(formatNumberToLocaleString(0, 2)).toBe("0.00")
|
|
85
|
+
expect(formatNumberToLocaleString(0, 4)).toBe("0.0000")
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it("formats small decimal number", () => {
|
|
89
|
+
expect(formatNumberToLocaleString(0.123456, 2)).toBe("0.12")
|
|
90
|
+
expect(formatNumberToLocaleString(0.123456, 4)).toBe("0.1235")
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it("formats number just above 1", () => {
|
|
94
|
+
expect(formatNumberToLocaleString(1.000001, 3)).toBe("1.000")
|
|
95
|
+
expect(formatNumberToLocaleString(1.234567, 2)).toBe("1.23")
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it("formats whole number", () => {
|
|
99
|
+
expect(formatNumberToLocaleString(1234, 0)).toBe("1,234")
|
|
100
|
+
expect(formatNumberToLocaleString(1000, 2)).toBe("1,000.00")
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it("formats number with trailing decimal zeroes", () => {
|
|
104
|
+
expect(formatNumberToLocaleString(10.1, 3)).toBe("10.100")
|
|
105
|
+
expect(formatNumberToLocaleString(5.0, 2)).toBe("5.00")
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it("formats string input", () => {
|
|
109
|
+
expect(formatNumberToLocaleString("123.456", 2)).toBe("123.46")
|
|
110
|
+
expect(formatNumberToLocaleString("0.00123", 4)).toBe("0.0012")
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it("formats negative number", () => {
|
|
114
|
+
expect(formatNumberToLocaleString(-123.456, 2)).toBe("-123.46")
|
|
115
|
+
expect(formatNumberToLocaleString("-0.00999", 3)).toBe("-0.010")
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it("formats large number with commas", () => {
|
|
119
|
+
expect(formatNumberToLocaleString(12345678.9, 2)).toBe("12,345,678.90")
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it("handles max decimals safely", () => {
|
|
123
|
+
expect(formatNumberToLocaleString(1.123456789, 8)).toBe("1.12345679")
|
|
124
|
+
expect(formatNumberToLocaleString("0.000000000000000001", 18)).toBe(
|
|
125
|
+
"0.000000000000000001",
|
|
126
|
+
)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it("defaults to 0 decimals if not passed", () => {
|
|
130
|
+
expect(formatNumberToLocaleString(1234.567)).toBe("1,235") // rounds up by default
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe("fromFixedPointToString", () => {
|
|
135
|
+
const toFixedPoint = (num: number) => BigInt(Math.round(num * 1e18))
|
|
136
|
+
|
|
137
|
+
const cases = [
|
|
138
|
+
{ input: 2.0, expected: "2.000" },
|
|
139
|
+
{ input: 2.009, expected: "2.009" },
|
|
140
|
+
{ input: 2.01, expected: "2.010" },
|
|
141
|
+
{ input: 2.015, expected: "2.016" },
|
|
142
|
+
{ input: 2.05, expected: "2.050" },
|
|
143
|
+
{ input: 2.09, expected: "2.090" },
|
|
144
|
+
]
|
|
145
|
+
|
|
146
|
+
describe("withRoundUp: true", () => {
|
|
147
|
+
cases.forEach(({ input, expected }) => {
|
|
148
|
+
it(`formats ${input} → ${expected}`, () => {
|
|
149
|
+
const fixed = toFixedPoint(input)
|
|
150
|
+
expect(fromFixedPointToString(fixed, 18, 3, true)).toBe(expected)
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
describe("withRoundUp: false", () => {
|
|
156
|
+
const noRoundCases = [
|
|
157
|
+
{ input: 2.0099, expected: "2.009" },
|
|
158
|
+
{ input: 2.0159, expected: "2.015" },
|
|
159
|
+
{ input: 2.0101, expected: "2.010" },
|
|
160
|
+
{ input: 2.0199, expected: "2.019" },
|
|
161
|
+
]
|
|
162
|
+
|
|
163
|
+
noRoundCases.forEach(({ input, expected }) => {
|
|
164
|
+
it(`formats ${input} → ${expected} (no rounding)`, () => {
|
|
165
|
+
const fixed = toFixedPoint(input)
|
|
166
|
+
expect(fromFixedPointToString(fixed, 18, 3, false)).toBe(expected)
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
describe("zero handling", () => {
|
|
172
|
+
it("formats 0 → 0.000 (3 decimals)", () => {
|
|
173
|
+
expect(fromFixedPointToString(0n, 18, 3)).toBe("0.000")
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it("formats 0 → 0.0000 (4 decimals)", () => {
|
|
177
|
+
expect(fromFixedPointToString(0n, 18, 4)).toBe("0.0000")
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
describe("very small numbers below display threshold", () => {
|
|
182
|
+
it("returns <0.0001 for small number (3 decimals)", () => {
|
|
183
|
+
const small = BigInt(123) // ~1.23e-16
|
|
184
|
+
expect(fromFixedPointToString(small, 18, 4)).toBe("<0.0001")
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it("returns <0.01 for small number with only 2 decimals", () => {
|
|
188
|
+
const tiny = BigInt(9999999999999) // <0.01
|
|
189
|
+
expect(fromFixedPointToString(tiny, 18, 2)).toBe("<0.01")
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
describe("input types", () => {
|
|
194
|
+
it("accepts bigint", () => {
|
|
195
|
+
const amount = 2100000000000000000n
|
|
196
|
+
expect(fromFixedPointToString(amount, 18, 3)).toBe("2.100")
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it("accepts string", () => {
|
|
200
|
+
expect(fromFixedPointToString("2000000000000000000", 18, 3)).toBe("2.000")
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it("accepts number", () => {
|
|
204
|
+
expect(fromFixedPointToString(Number("1000000000000000000"), 18, 3)).toBe(
|
|
205
|
+
"1.000",
|
|
206
|
+
)
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
describe("high values", () => {
|
|
211
|
+
it("formats 1_000_000.123456789 correctly", () => {
|
|
212
|
+
const big = toFixedPoint(1_000_000.123456789)
|
|
213
|
+
expect(fromFixedPointToString(big, 18, 6)).toBe("1,000,000.123456")
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it("formats 1e12 ETH", () => {
|
|
217
|
+
const big = BigInt("1000000000000000000000000000000")
|
|
218
|
+
expect(fromFixedPointToString(big, 18, 2)).toBe("1,000,000,000,000.00")
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
describe("bigIntMax", () => {
|
|
224
|
+
it("returns the maximum of positive bigint values", () => {
|
|
225
|
+
expect(bigIntMax(1n, 2n, 3n)).toBe(3n)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it("returns the maximum of negative bigint values", () => {
|
|
229
|
+
expect(bigIntMax(-10n, -5n, -20n)).toBe(-5n)
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it("returns the only element if array has one bigint", () => {
|
|
233
|
+
expect(bigIntMax(42n)).toBe(42n)
|
|
74
234
|
})
|
|
75
235
|
|
|
76
|
-
it("
|
|
77
|
-
expect(
|
|
236
|
+
it("works with a mix of positive and negative bigints", () => {
|
|
237
|
+
expect(bigIntMax(-100n, 0n, 50n, -10n)).toBe(50n)
|
|
78
238
|
})
|
|
79
239
|
|
|
80
|
-
it("
|
|
81
|
-
|
|
82
|
-
expect(result).toBe("1.23")
|
|
240
|
+
it("throws an error if called with no arguments", () => {
|
|
241
|
+
expect(() => bigIntMax()).toThrow()
|
|
83
242
|
})
|
|
84
243
|
|
|
85
|
-
it("
|
|
86
|
-
|
|
87
|
-
expect(result).toBe("1.24")
|
|
244
|
+
it("returns the correct value when all values are equal", () => {
|
|
245
|
+
expect(bigIntMax(5n, 5n, 5n)).toBe(5n)
|
|
88
246
|
})
|
|
89
247
|
})
|
package/src/utils/numbers.ts
CHANGED
|
@@ -1,28 +1,44 @@
|
|
|
1
|
+
type DesiredDecimals = Intl.NumberFormatOptions &
|
|
2
|
+
BigIntToLocaleStringOptions["minimumFractionDigits"]
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* Formats a number or bigint into
|
|
5
|
+
* Formats a number or bigint into compact string with K, M, B, or T suffix.
|
|
3
6
|
* @param value The number or bigint to format.
|
|
4
7
|
* @param decimals Number of decimal places to include (ignored for bigint to avoid floating point issues).
|
|
5
8
|
* @returns The formatted number as a string.
|
|
6
9
|
*/
|
|
7
|
-
export function
|
|
10
|
+
export function formatNumberToCompactString(
|
|
8
11
|
value: number | bigint,
|
|
9
|
-
decimals
|
|
12
|
+
decimals = 4,
|
|
10
13
|
): string {
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
return value.toLocaleString("en-US", {
|
|
15
|
+
notation: "compact",
|
|
16
|
+
compactDisplay: "short",
|
|
17
|
+
maximumFractionDigits: decimals as DesiredDecimals,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
/**
|
|
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)
|
|
15
33
|
|
|
16
|
-
|
|
34
|
+
if (number === 0 && desiredDecimals === 0) return "0"
|
|
17
35
|
|
|
18
|
-
if (
|
|
19
|
-
const max = 10 ** ((suffixes.length - 1) * 3) * 1000 - 1
|
|
20
|
-
const capped = max / 10 ** ((suffixes.length - 1) * 3)
|
|
21
|
-
return `> ${capped.toFixed(0)}${suffixes[suffixes.length - 1]}`
|
|
22
|
-
}
|
|
36
|
+
if (number === 0) return `0.${"0".repeat(desiredDecimals)}`
|
|
23
37
|
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
return number.toLocaleString("en-US", {
|
|
39
|
+
minimumFractionDigits: desiredDecimals,
|
|
40
|
+
maximumFractionDigits: desiredDecimals,
|
|
41
|
+
})
|
|
26
42
|
}
|
|
27
43
|
|
|
28
44
|
/**
|
|
@@ -30,7 +46,7 @@ export function formatHumanReadableNumber(
|
|
|
30
46
|
* @param amount The number to round up.
|
|
31
47
|
* @param desiredDecimals The number of decimals to round up to.
|
|
32
48
|
* @returns The rounded up number.
|
|
33
|
-
* @see https://github.com/thesis/acre/blob/
|
|
49
|
+
* @see https://github.com/thesis/acre/blob/2078d339f4ddce79e69c78529c9d72910dd2640a/dapp/src/utils/numbersUtils.ts#L1-L3
|
|
34
50
|
*/
|
|
35
51
|
export function roundUpNumber(amount: number, desiredDecimals = 2): number {
|
|
36
52
|
return Math.ceil(amount * 10 ** desiredDecimals) / 10 ** desiredDecimals
|
|
@@ -43,12 +59,12 @@ export function roundUpNumber(amount: number, desiredDecimals = 2): number {
|
|
|
43
59
|
* @param fixedPointDecimals The number of decimals in the fixed point bigint.
|
|
44
60
|
* @param desiredDecimals The number of decimals in the output number.
|
|
45
61
|
* @returns The floating point number truncated to `desiredDecimals`.
|
|
46
|
-
* @see https://github.com/tahowallet/extension/blob/
|
|
62
|
+
* @see https://github.com/tahowallet/extension/blob/f6b26b7cb4a0a0278b1fccc6319626638f1a6dfa/background/lib/fixed-point.ts#L216-L239
|
|
47
63
|
*/
|
|
48
64
|
export function fromFixedPoint(
|
|
49
65
|
fixedPoint: bigint,
|
|
50
66
|
fixedPointDecimals: number,
|
|
51
|
-
desiredDecimals =
|
|
67
|
+
desiredDecimals = 4,
|
|
52
68
|
): number {
|
|
53
69
|
const fixedPointDesiredDecimalsAmount =
|
|
54
70
|
fixedPoint /
|
|
@@ -62,27 +78,21 @@ export function fromFixedPoint(
|
|
|
62
78
|
}
|
|
63
79
|
|
|
64
80
|
/**
|
|
65
|
-
* Display a
|
|
81
|
+
* Display a token amount correctly with desired decimals.
|
|
66
82
|
* The function returns a string with a language-sensitive representation of this number.
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* - If `formattedAmount` is less than the minimum amount to display
|
|
70
|
-
* for the specified precision return information about this.
|
|
71
|
-
* For example, <0.01 for a precision of 2.
|
|
72
|
-
* - Other amounts are formatted according to the use of the `bigIntToUserAmount` function.
|
|
73
|
-
* @param amount The amount of tokens to format.
|
|
74
|
-
* @param decimals The number of decimals the cryptoAsset has.
|
|
83
|
+
* @param amount The fixed point number to convert.
|
|
84
|
+
* @param decimals The number of decimals in the fixed point number.
|
|
75
85
|
* @param desiredDecimals The number of decimals to display.
|
|
76
|
-
* @param withRoundUp
|
|
77
|
-
* @returns The formatted
|
|
78
|
-
* @see https://github.com/thesis/acre/blob/
|
|
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
|
|
79
89
|
*/
|
|
80
|
-
export
|
|
90
|
+
export const fromFixedPointToString = (
|
|
81
91
|
amount: number | string | bigint,
|
|
82
92
|
decimals = 18,
|
|
83
|
-
desiredDecimals =
|
|
93
|
+
desiredDecimals = 4,
|
|
84
94
|
withRoundUp = false,
|
|
85
|
-
) {
|
|
95
|
+
) => {
|
|
86
96
|
const fixedPoint = BigInt(amount)
|
|
87
97
|
|
|
88
98
|
if (fixedPoint === 0n) {
|
|
@@ -104,7 +114,84 @@ export function formatTokenAmount(
|
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
const finalFormattedAmount = withRoundUp
|
|
107
|
-
?
|
|
117
|
+
? Math.ceil(formattedAmount * 10 ** desiredDecimals) / 10 ** desiredDecimals
|
|
108
118
|
: formattedAmount
|
|
109
|
-
return
|
|
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,
|
|
137
|
+
): 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)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const parsedAmount = amount.toString()
|
|
177
|
+
const fixedPointAmount = parseToFixedPointNumber(parsedAmount)
|
|
178
|
+
|
|
179
|
+
if (typeof fixedPointAmount === "undefined") {
|
|
180
|
+
return 0n
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return convertFixedPoint(
|
|
184
|
+
fixedPointAmount.amount,
|
|
185
|
+
fixedPointAmount.decimals,
|
|
186
|
+
decimals,
|
|
187
|
+
)
|
|
110
188
|
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
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.
|
|
195
|
+
*/
|
|
196
|
+
export const bigIntMax = (...values: bigint[]) =>
|
|
197
|
+
values.reduce((max, value) => (value > max ? value : max))
|
package/src/utils/siww.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SignInWithWalletErrorType,
|
|
3
|
+
SignInWithWalletMessage,
|
|
4
|
+
} from "@mezo-org/sign-in-with-wallet"
|
|
2
5
|
import { ONE_DAY_MS } from "./time"
|
|
3
6
|
|
|
4
7
|
const SESSION_EXPIRATION_DURATION_MS = 14 * ONE_DAY_MS
|
|
@@ -13,19 +16,71 @@ export function createSignInWithWalletMessage(
|
|
|
13
16
|
) {
|
|
14
17
|
const { host: domain, origin: uri } = window.location
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Date.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
let siwwMessage
|
|
20
|
+
try {
|
|
21
|
+
siwwMessage = new SignInWithWalletMessage({
|
|
22
|
+
domain,
|
|
23
|
+
address, // if "bitcoin" this should be btc address, not underlaying eth address
|
|
24
|
+
uri,
|
|
25
|
+
nonce,
|
|
26
|
+
issuedAt: new Date().toISOString(),
|
|
27
|
+
expirationTime: new Date(
|
|
28
|
+
Date.now() + SESSION_EXPIRATION_DURATION_MS,
|
|
29
|
+
).toISOString(),
|
|
30
|
+
version: "1",
|
|
31
|
+
chainId: networkFamily === "evm" ? chainId : undefined,
|
|
32
|
+
networkFamily,
|
|
33
|
+
})
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error(`Failed to create sign in with wallet message: ${error}`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return siwwMessage.prepareMessage()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class SIWWDomainError extends Error {
|
|
42
|
+
constructor(message: string) {
|
|
43
|
+
super(`Error when verifying domain in SIWW message: ${message}`)
|
|
44
|
+
this.name = "SIWWDomainError"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function verifyDomainInSignInWithWalletMessage(
|
|
49
|
+
message: string,
|
|
50
|
+
signature: string,
|
|
51
|
+
nonce: string,
|
|
52
|
+
) {
|
|
53
|
+
const { host: domain } = window.location
|
|
54
|
+
let siwwMessage: SignInWithWalletMessage
|
|
55
|
+
try {
|
|
56
|
+
siwwMessage = new SignInWithWalletMessage(message)
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw new SIWWDomainError("Failed to parse SIWW message")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!siwwMessage.expirationTime) {
|
|
62
|
+
throw new SIWWDomainError("SIWW messages must have an expiration time set")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const result = await siwwMessage.verify(
|
|
66
|
+
{
|
|
67
|
+
signature,
|
|
68
|
+
// Nonce has to match the session ID carried in the request.
|
|
69
|
+
nonce,
|
|
70
|
+
domain,
|
|
71
|
+
// Time is used as a reference to verify the expiration time set in the
|
|
72
|
+
// message.
|
|
73
|
+
time: new Date().toISOString(),
|
|
74
|
+
},
|
|
75
|
+
{ suppressExceptions: true },
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
if (
|
|
79
|
+
result.error &&
|
|
80
|
+
result.error.type === SignInWithWalletErrorType.DOMAIN_MISMATCH
|
|
81
|
+
) {
|
|
82
|
+
throw new SIWWDomainError(
|
|
83
|
+
"Domain does not match provided domain for verification.",
|
|
84
|
+
)
|
|
85
|
+
}
|
|
31
86
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OrangeKitConnector } from "@mezo-org/orangekit"
|
|
2
|
+
import { Connector } from "wagmi"
|
|
3
|
+
|
|
4
|
+
export async function getBitcoinPublicKeyFromConnector(connector: Connector) {
|
|
5
|
+
if (connector.type !== "orangekit") return undefined
|
|
6
|
+
|
|
7
|
+
const provider = (
|
|
8
|
+
connector as unknown as OrangeKitConnector
|
|
9
|
+
).getBitcoinProvider()
|
|
10
|
+
|
|
11
|
+
return provider.getPublicKey()
|
|
12
|
+
}
|
package/src/wallet/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export {
|
|
2
|
+
BitcoinWalletConnectionError,
|
|
2
3
|
getOKXWallet,
|
|
3
4
|
getUnisatWallet,
|
|
4
5
|
getXverseWallet,
|
|
5
|
-
BitcoinWalletConnectionError,
|
|
6
|
-
WalletNetworkDoesNotMatchProviderChainError,
|
|
7
6
|
isUnsupportedBitcoinAddressError,
|
|
8
7
|
isWalletNetworkDoesNotMatchProviderChainError,
|
|
8
|
+
OrangeKitConnector,
|
|
9
|
+
WalletNetworkDoesNotMatchProviderChainError,
|
|
9
10
|
} from "@mezo-org/orangekit"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AccountAddress.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountAddress.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,SAAS,GAAG,KAAK,CAAA;CACxB,CAAA;AAID,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAK,EAAE,mBAAmB,qBA0FhE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AccountAddress.js","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountAddress.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,IAAI,QAAQ,EAClB,cAAc,IAAI,QAAQ,EAC1B,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAOzD,oCAAoC;AAEpC,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAA0B;IAC/D,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAE/B,MAAM,EAAE,WAAW,EAAE,GAAG,kBAAkB,EAAE,CAAA;IAC5C,MAAM,gBAAgB,GAAG,qBAAqB,CAC5C,OAAO,EACP,IAAI,EACJ,WAAW,KAAK,SAAS,CAC1B,CAAA;IACD,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,cAAc,CAC1C,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CACnC,CAAA;IAED,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,YAAY,EAAE,CAAA;IAEhC,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,kBAAkB,EAAE,CAAA;IAErC,OAAO,CACL,oBAAC,KAAK,IACJ,EAAE,EAAC,QAAQ,EACX,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAC5B,OAAO,EAAC,MAAM,EACd,UAAU,EAAC,QAAQ,EACnB,eAAe,EAAC,aAAa,EAC7B,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,EAC5D,SAAS,EAAE;YACT,KAAK,EAAE;gBACL,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC;oBACd,MAAM,EAAE,SAAS;oBACjB,QAAQ,EAAE;wBACR,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,kBAAkB;qBACjD;iBACF;aACF;SACF;QAED,oBAAC,KAAK,IAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,GAAI;QACvD,oBAAC,KAAK,IACJ,EAAE,EAAC,GAAG,EACN,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EACjC,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAC,QAAQ,EACf,SAAS,EAAE;gBACT,KAAK,EAAE;oBACL,KAAK,EAAE;wBACL,KAAK,EAAE,SAAS;wBAChB,cAAc,EAAE,MAAM;wBACtB,QAAQ,EAAE;4BACR,cAAc,EAAE,WAAW;yBAC5B;qBACF;iBACF;aACF;YAED,oBAAC,cAAc,IACb,OAAO,EAAC,MAAM,EACd,UAAU,EAAC,QAAQ,EACnB,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO;gBAE1B,cAAc;gBACf,oBAAC,QAAQ,IACP,OAAO,EAAC,QAAQ,EAChB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC3B,SAAS,EAAE;wBACT,GAAG,EAAE;4BACH,KAAK,EAAE;gCACL,MAAM,EAAE,cAAc;gCACtB,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;6BAClC;yBACF;qBACF,GACD,CACa,CACX;QACR,oBAAC,QAAQ,IACP,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EAC3B,SAAS,EAAE;gBACT,GAAG,EAAE;oBACH,KAAK,EAAE;wBACL,UAAU,EAAE,MAAM;wBAClB,MAAM,EAAE,cAAc;qBACvB;iBACF;aACF,GACD,CACI,CACT,CAAA;AACH,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { CryptoAssetKey } from "../../utils/cryptoAssets";
|
|
3
|
-
type AccountAssetsProps = {
|
|
4
|
-
label: string | React.ReactNode;
|
|
5
|
-
assets: {
|
|
6
|
-
type: CryptoAssetKey;
|
|
7
|
-
decimals: number;
|
|
8
|
-
balance: number;
|
|
9
|
-
balanceInUsd: number;
|
|
10
|
-
}[];
|
|
11
|
-
};
|
|
12
|
-
export default function AccountAssets(props: AccountAssetsProps): React.JSX.Element | null;
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=AccountAssets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AccountAssets.d.ts","sourceRoot":"","sources":["../../../../src/components/Dropdown/AccountAssets.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAkB,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,cAAc,EAAkB,MAAM,0BAA0B,CAAA;AAGzE,KAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAA;IAC/B,MAAM,EAAE;QACN,IAAI,EAAE,cAAc,CAAA;QACpB,QAAQ,EAAE,MAAM,CAAA;QAChB,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;KACrB,EAAE,CAAA;CACJ,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,4BAyF9D"}
|