thirdweb 5.80.1-nightly-a7b6cb3211e8b5232e77965cb8dd8ff96b369424-20241228000338 → 5.80.1-nightly-03bf859809de255d20f4ed8285a3bb75cef17252-20241229000354

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 (81) hide show
  1. package/dist/cjs/chains/utils.js +4 -0
  2. package/dist/cjs/chains/utils.js.map +1 -1
  3. package/dist/cjs/exports/utils.js +2 -2
  4. package/dist/cjs/exports/utils.js.map +1 -1
  5. package/dist/cjs/utils/bytecode/{extractMnimalProxyImplementationAddress.js → extractMinimalProxyImplementationAddress.js} +1 -1
  6. package/dist/cjs/utils/bytecode/extractMinimalProxyImplementationAddress.js.map +1 -0
  7. package/dist/cjs/utils/bytecode/resolveImplementation.js +2 -2
  8. package/dist/cjs/utils/bytecode/resolveImplementation.js.map +1 -1
  9. package/dist/cjs/utils/promise/p-limit.js +5 -0
  10. package/dist/cjs/utils/promise/p-limit.js.map +1 -1
  11. package/dist/cjs/utils/semver.js +1 -0
  12. package/dist/cjs/utils/semver.js.map +1 -1
  13. package/dist/cjs/utils/url.js +3 -0
  14. package/dist/cjs/utils/url.js.map +1 -1
  15. package/dist/cjs/version.js +1 -1
  16. package/dist/esm/chains/utils.js +4 -1
  17. package/dist/esm/chains/utils.js.map +1 -1
  18. package/dist/esm/exports/utils.js +1 -1
  19. package/dist/esm/exports/utils.js.map +1 -1
  20. package/dist/esm/utils/bytecode/{extractMnimalProxyImplementationAddress.js → extractMinimalProxyImplementationAddress.js} +1 -1
  21. package/dist/esm/utils/bytecode/extractMinimalProxyImplementationAddress.js.map +1 -0
  22. package/dist/esm/utils/bytecode/resolveImplementation.js +1 -1
  23. package/dist/esm/utils/bytecode/resolveImplementation.js.map +1 -1
  24. package/dist/esm/utils/promise/p-limit.js +4 -1
  25. package/dist/esm/utils/promise/p-limit.js.map +1 -1
  26. package/dist/esm/utils/semver.js +1 -1
  27. package/dist/esm/utils/semver.js.map +1 -1
  28. package/dist/esm/utils/url.js +3 -3
  29. package/dist/esm/utils/url.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/dist/types/chains/utils.d.ts +4 -0
  32. package/dist/types/chains/utils.d.ts.map +1 -1
  33. package/dist/types/exports/utils.d.ts +1 -1
  34. package/dist/types/exports/utils.d.ts.map +1 -1
  35. package/dist/types/utils/bytecode/{extractMnimalProxyImplementationAddress.d.ts → extractMinimalProxyImplementationAddress.d.ts} +1 -1
  36. package/dist/types/utils/bytecode/extractMinimalProxyImplementationAddress.d.ts.map +1 -0
  37. package/dist/types/utils/promise/p-limit.d.ts +13 -0
  38. package/dist/types/utils/promise/p-limit.d.ts.map +1 -1
  39. package/dist/types/utils/semver.d.ts +15 -0
  40. package/dist/types/utils/semver.d.ts.map +1 -1
  41. package/dist/types/utils/url.d.ts +12 -0
  42. package/dist/types/utils/url.d.ts.map +1 -1
  43. package/dist/types/version.d.ts +1 -1
  44. package/package.json +1 -1
  45. package/src/auth/verify-hash.test.ts +3 -3
  46. package/src/chains/utils.test.ts +70 -1
  47. package/src/chains/utils.ts +4 -1
  48. package/src/contract/contract.test.ts +42 -0
  49. package/src/exports/utils.ts +1 -1
  50. package/src/extensions/thirdweb/write/publish.test.ts +1 -1
  51. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.test.tsx +52 -0
  52. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.test.ts +174 -0
  53. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/formatSeconds.test.ts +30 -0
  54. package/src/react/web/ui/ConnectWallet/screens/Buy/utils.test.ts +20 -0
  55. package/src/react/web/wallets/injected/locale/getInjectedWalletLocale.test.ts +39 -0
  56. package/src/react/web/wallets/smartWallet/locale/getSmartWalletLocale.test.ts +39 -0
  57. package/src/utils/abi/normalizeFunctionParams.test.ts +108 -0
  58. package/src/utils/bigint.test.ts +91 -1
  59. package/src/utils/bytecode/extractMinimalProxyImplementationAddress.test.ts +60 -0
  60. package/src/utils/bytecode/resolveImplementation.ts +1 -1
  61. package/src/utils/domain.test.ts +78 -0
  62. package/src/utils/encoding/hex.test.ts +163 -1
  63. package/src/utils/ens/encodeLabelToLabelhash.test.ts +28 -0
  64. package/src/utils/ens/encodeLabelhash.test.ts +18 -0
  65. package/src/utils/ens/namehash.test.ts +17 -0
  66. package/src/utils/nft/{parse-nft.test.ts → parseNft.test.ts} +39 -0
  67. package/src/utils/promise/p-limit.test.ts +105 -0
  68. package/src/utils/promise/p-limit.ts +4 -1
  69. package/src/utils/promise/withCache.test.ts +73 -0
  70. package/src/utils/semver.test.ts +72 -0
  71. package/src/utils/semver.ts +1 -1
  72. package/src/utils/url.test.ts +90 -1
  73. package/src/utils/url.ts +6 -3
  74. package/src/version.ts +1 -1
  75. package/src/wallets/eip5792/get-calls-status.test.ts +4 -4
  76. package/src/wallets/eip5792/send-calls.test.ts +7 -7
  77. package/src/wallets/eip5792/show-calls-status.test.ts +2 -2
  78. package/dist/cjs/utils/bytecode/extractMnimalProxyImplementationAddress.js.map +0 -1
  79. package/dist/esm/utils/bytecode/extractMnimalProxyImplementationAddress.js.map +0 -1
  80. package/dist/types/utils/bytecode/extractMnimalProxyImplementationAddress.d.ts.map +0 -1
  81. /package/src/utils/bytecode/{extractMnimalProxyImplementationAddress.ts → extractMinimalProxyImplementationAddress.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/utils/url.ts"],"names":[],"mappings":"AAOA,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AA4CF;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,aAAa,CAIf;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAEtE;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAE5E"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,WAEpC;AAED,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,aAAa,CAcf;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAkB5E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,aAAa,CAIf;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAEtE;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAE5E"}
@@ -1,2 +1,2 @@
1
- export declare const version = "5.80.1-nightly-a7b6cb3211e8b5232e77965cb8dd8ff96b369424-20241228000338";
1
+ export declare const version = "5.80.1-nightly-03bf859809de255d20f4ed8285a3bb75cef17252-20241229000354";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thirdweb",
3
- "version": "5.80.1-nightly-a7b6cb3211e8b5232e77965cb8dd8ff96b369424-20241228000338",
3
+ "version": "5.80.1-nightly-03bf859809de255d20f4ed8285a3bb75cef17252-20241229000354",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/thirdweb-dev/js.git#main"
@@ -16,7 +16,7 @@ describe("verifyHash", async () => {
16
16
  privateKey: ANVIL_PKEY_A,
17
17
  });
18
18
 
19
- expect(
19
+ await expect(
20
20
  verifyHash({
21
21
  address: TEST_ACCOUNT_A.address,
22
22
  hash: hashMessage("hello world"),
@@ -33,7 +33,7 @@ describe("verifyHash", async () => {
33
33
  privateKey: ANVIL_PKEY_A,
34
34
  });
35
35
 
36
- expect(
36
+ await expect(
37
37
  verifyHash({
38
38
  address: TEST_ACCOUNT_A.address,
39
39
  hash: hashMessage("hello world"),
@@ -50,7 +50,7 @@ describe("verifyHash", async () => {
50
50
  privateKey: ANVIL_PKEY_A,
51
51
  });
52
52
 
53
- expect(
53
+ await expect(
54
54
  verifyHash({
55
55
  address: TEST_ACCOUNT_A.address,
56
56
  hash: hashMessage("hello world"),
@@ -9,12 +9,15 @@ import { toSerializableTransaction } from "../transaction/actions/to-serializabl
9
9
  import { privateKeyToAccount } from "../wallets/private-key.js";
10
10
  import { avalanche } from "./chain-definitions/avalanche.js";
11
11
  import { ethereum } from "./chain-definitions/ethereum.js";
12
- import type { LegacyChain } from "./types.js";
12
+ import type { ChainMetadata, LegacyChain } from "./types.js";
13
13
 
14
+ import { base } from "viem/chains";
14
15
  import {
15
16
  CUSTOM_CHAIN_MAP,
16
17
  cacheChains,
18
+ convertApiChainToChain,
17
19
  convertLegacyChain,
20
+ convertViemChain,
18
21
  defineChain,
19
22
  getCachedChain,
20
23
  getChainDecimals,
@@ -237,4 +240,70 @@ describe("defineChain", () => {
237
240
  cacheChains([scroll]);
238
241
  expect(CUSTOM_CHAIN_MAP.get(scroll.id)).toStrictEqual(scroll);
239
242
  });
243
+
244
+ it("Chain converted from viem should have the blockExplorers being an array", () => {
245
+ expect(Array.isArray(convertViemChain(base).blockExplorers)).toBe(true);
246
+ });
247
+
248
+ it("convertApiChainToChain should work", () => {
249
+ const ethChain: ChainMetadata = {
250
+ chainId: 1,
251
+ name: "Ethereum Mainnet",
252
+ chain: "ETH",
253
+ shortName: "eth",
254
+ icon: {
255
+ url: "ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/ethereum/512.png",
256
+ width: 512,
257
+ height: 512,
258
+ format: "png",
259
+ },
260
+ nativeCurrency: {
261
+ name: "Ether",
262
+ symbol: "ETH",
263
+ decimals: 18,
264
+ },
265
+ ens: {
266
+ registry: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
267
+ },
268
+ explorers: [
269
+ {
270
+ name: "etherscan",
271
+ url: "https://etherscan.io",
272
+ standard: "EIP3091",
273
+ },
274
+ ],
275
+ rpc: ["https://1.rpc.thirdweb.com/${THIRDWEB_API_KEY}"],
276
+ testnet: false,
277
+ infoURL: "https://ethereum.org",
278
+ slug: "ethereum",
279
+ networkId: 1,
280
+ stackType: "l1",
281
+ };
282
+
283
+ expect(convertApiChainToChain(ethChain)).toStrictEqual({
284
+ blockExplorers: [
285
+ {
286
+ apiUrl: "https://etherscan.io",
287
+ name: "etherscan",
288
+ url: "https://etherscan.io",
289
+ },
290
+ ],
291
+ faucets: undefined,
292
+ icon: {
293
+ format: "png",
294
+ height: 512,
295
+ url: "ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/ethereum/512.png",
296
+ width: 512,
297
+ },
298
+ id: 1,
299
+ name: "Ethereum Mainnet",
300
+ nativeCurrency: {
301
+ decimals: 18,
302
+ name: "Ether",
303
+ symbol: "ETH",
304
+ },
305
+ rpc: "https://1.rpc.thirdweb.com/${THIRDWEB_API_KEY}",
306
+ testnet: undefined,
307
+ });
308
+ });
240
309
  });
@@ -132,7 +132,10 @@ function isViemChain(
132
132
  return "rpcUrls" in chain && !("rpc" in chain);
133
133
  }
134
134
 
135
- function convertViemChain(viemChain: ViemChain): Chain {
135
+ /**
136
+ * @internal
137
+ */
138
+ export function convertViemChain(viemChain: ViemChain): Chain {
136
139
  const RPC_URL = getThirdwebDomains().rpc;
137
140
  return {
138
141
  id: viemChain.id,
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TEST_CLIENT } from "~test/test-clients.js";
3
+ import { USDT_CONTRACT_ADDRESS } from "~test/test-contracts.js";
4
+ import { ethereum } from "../chains/chain-definitions/ethereum.js";
5
+ import { getContract } from "./contract.js";
6
+
7
+ describe("Contract - getContract", () => {
8
+ it("should throw error if client is not passed", () => {
9
+ expect(() =>
10
+ // @ts-ignore Test purpose
11
+ getContract({ address: "0x", chain: ethereum }),
12
+ ).toThrowError(
13
+ `getContract validation error - invalid client: ${undefined}`,
14
+ );
15
+ });
16
+
17
+ it("should throw error if address is not valid", () => {
18
+ expect(() =>
19
+ getContract({ address: "0x", chain: ethereum, client: TEST_CLIENT }),
20
+ ).toThrowError("getContract validation error - invalid address: 0x");
21
+ });
22
+
23
+ it("should throw error if chain is not passed", () => {
24
+ expect(() =>
25
+ // @ts-ignore Test purpose
26
+ getContract({ address: USDT_CONTRACT_ADDRESS, client: TEST_CLIENT }),
27
+ ).toThrowError(
28
+ `getContract validation error - invalid chain: ${undefined}`,
29
+ );
30
+ });
31
+
32
+ it("should throw error if chain doesn't have id", () => {
33
+ expect(() =>
34
+ getContract({
35
+ address: USDT_CONTRACT_ADDRESS,
36
+ client: TEST_CLIENT,
37
+ // @ts-ignore Test
38
+ chain: {},
39
+ }),
40
+ ).toThrowError(`getContract validation error - invalid chain: ${{}}`);
41
+ });
42
+ });
@@ -1,7 +1,7 @@
1
1
  // bytecode
2
2
  export { detectMethod } from "../utils/bytecode/detectExtension.js";
3
3
  export { extractIPFSUri } from "../utils/bytecode/extractIPFS.js";
4
- export { extractMinimalProxyImplementationAddress } from "../utils/bytecode/extractMnimalProxyImplementationAddress.js";
4
+ export { extractMinimalProxyImplementationAddress } from "../utils/bytecode/extractMinimalProxyImplementationAddress.js";
5
5
  export { isContractDeployed } from "../utils/bytecode/is-contract-deployed.js";
6
6
  export { ensureBytecodePrefix } from "../utils/bytecode/prefix.js";
7
7
  export { resolveImplementation } from "../utils/bytecode/resolveImplementation.js";
@@ -105,7 +105,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential("publishContract", () => {
105
105
 
106
106
  expect(publishedContracts.length).toBe(1);
107
107
 
108
- expect(
108
+ await expect(
109
109
  sendAndConfirmTransaction({
110
110
  account: TEST_ACCOUNT_D,
111
111
  transaction: publishContract({
@@ -0,0 +1,52 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { CADIcon } from "../../../icons/currencies/CADIcon.js";
3
+ import { EURIcon } from "../../../icons/currencies/EURIcon.js";
4
+ import { GBPIcon } from "../../../icons/currencies/GBPIcon.js";
5
+ import { JPYIcon } from "../../../icons/currencies/JPYIcon.js";
6
+ import { USDIcon } from "../../../icons/currencies/USDIcon.js";
7
+ import { currencies, getCurrencyMeta, usdCurrency } from "./currencies.js";
8
+
9
+ describe("Currency Utilities", () => {
10
+ it("should have correct number of currencies", () => {
11
+ expect(currencies.length).toBe(5);
12
+ });
13
+
14
+ it("should have USD as the first currency", () => {
15
+ expect(currencies[0]).toEqual(usdCurrency);
16
+ });
17
+
18
+ it("should have correct properties for each currency", () => {
19
+ for (const currency of currencies) {
20
+ expect(currency).toHaveProperty("shorthand");
21
+ expect(currency).toHaveProperty("name");
22
+ expect(currency).toHaveProperty("icon");
23
+ }
24
+ });
25
+
26
+ describe("getCurrencyMeta function", () => {
27
+ it("should return correct currency meta for valid shorthand", () => {
28
+ const cadMeta = getCurrencyMeta("CAD");
29
+ expect(cadMeta.shorthand).toBe("CAD");
30
+ expect(cadMeta.name).toBe("Canadian Dollar");
31
+ expect(cadMeta.icon).toBe(CADIcon);
32
+ });
33
+
34
+ it("should be case-insensitive", () => {
35
+ const eurMeta = getCurrencyMeta("eur");
36
+ expect(eurMeta.shorthand).toBe("EUR");
37
+ expect(eurMeta.name).toBe("Euro");
38
+ expect(eurMeta.icon).toBe(EURIcon);
39
+ });
40
+
41
+ it("should return unknown currency for invalid shorthand", () => {
42
+ const unknownMeta = getCurrencyMeta("XYZ");
43
+ expect(unknownMeta.shorthand).toBe("XYZ");
44
+ expect(unknownMeta.name).toBe("XYZ");
45
+ expect(unknownMeta.icon).not.toBe(USDIcon);
46
+ expect(unknownMeta.icon).not.toBe(CADIcon);
47
+ expect(unknownMeta.icon).not.toBe(GBPIcon);
48
+ expect(unknownMeta.icon).not.toBe(EURIcon);
49
+ expect(unknownMeta.icon).not.toBe(JPYIcon);
50
+ });
51
+ });
52
+ });
@@ -0,0 +1,174 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { BuyWithCryptoStatus } from "../../../../../../../pay/buyWithCrypto/getStatus.js";
3
+ import type { BuyWithFiatStatus } from "../../../../../../../pay/buyWithFiat/getStatus.js";
4
+ import {
5
+ getBuyWithCryptoStatusMeta,
6
+ getBuyWithFiatStatusMeta,
7
+ } from "./statusMeta.js";
8
+
9
+ describe("getBuyWithCryptoStatusMeta", () => {
10
+ it('returns "Unknown" for NOT_FOUND status', () => {
11
+ const result = getBuyWithCryptoStatusMeta({
12
+ status: "NOT_FOUND",
13
+ } as BuyWithCryptoStatus);
14
+ expect(result).toEqual({
15
+ status: "Unknown",
16
+ color: "secondaryText",
17
+ });
18
+ });
19
+
20
+ it('returns "Bridging" for WAITING_BRIDGE subStatus', () => {
21
+ const result = getBuyWithCryptoStatusMeta({
22
+ status: "PENDING",
23
+ subStatus: "WAITING_BRIDGE",
24
+ } as BuyWithCryptoStatus);
25
+ expect(result).toEqual({
26
+ status: "Bridging",
27
+ color: "accentText",
28
+ loading: true,
29
+ });
30
+ });
31
+
32
+ it('returns "Incomplete" for PARTIAL_SUCCESS subStatus', () => {
33
+ const result = getBuyWithCryptoStatusMeta({
34
+ status: "COMPLETED",
35
+ subStatus: "PARTIAL_SUCCESS",
36
+ } as BuyWithCryptoStatus);
37
+ expect(result).toEqual({
38
+ status: "Incomplete",
39
+ color: "secondaryText",
40
+ });
41
+ });
42
+
43
+ it('returns "Pending" for PENDING status', () => {
44
+ const result = getBuyWithCryptoStatusMeta({
45
+ status: "PENDING",
46
+ } as BuyWithCryptoStatus);
47
+ expect(result).toEqual({
48
+ status: "Pending",
49
+ color: "accentText",
50
+ loading: true,
51
+ });
52
+ });
53
+
54
+ it('returns "Failed" for FAILED status', () => {
55
+ const result = getBuyWithCryptoStatusMeta({
56
+ status: "FAILED",
57
+ } as BuyWithCryptoStatus);
58
+ expect(result).toEqual({
59
+ status: "Failed",
60
+ color: "danger",
61
+ });
62
+ });
63
+
64
+ it('returns "Completed" for COMPLETED status', () => {
65
+ const result = getBuyWithCryptoStatusMeta({
66
+ status: "COMPLETED",
67
+ } as BuyWithCryptoStatus);
68
+ expect(result).toEqual({
69
+ status: "Completed",
70
+ color: "success",
71
+ });
72
+ });
73
+
74
+ it('returns "Unknown" for unhandled status', () => {
75
+ const result = getBuyWithCryptoStatusMeta({
76
+ // @ts-ignore Test purpose
77
+ status: "Unknown",
78
+ });
79
+ expect(result).toEqual({
80
+ status: "Unknown",
81
+ color: "secondaryText",
82
+ });
83
+ });
84
+ });
85
+
86
+ describe("getBuyWithFiatStatusMeta", () => {
87
+ it('returns "Incomplete" for CRYPTO_SWAP_FALLBACK status', () => {
88
+ const result = getBuyWithFiatStatusMeta({
89
+ status: "CRYPTO_SWAP_FALLBACK",
90
+ } as BuyWithFiatStatus);
91
+ expect(result).toEqual({
92
+ status: "Incomplete",
93
+ color: "danger",
94
+ step: 2,
95
+ progressStatus: "partialSuccess",
96
+ });
97
+ });
98
+
99
+ it('returns "Pending" for CRYPTO_SWAP_IN_PROGRESS status', () => {
100
+ const result = getBuyWithFiatStatusMeta({
101
+ status: "CRYPTO_SWAP_IN_PROGRESS",
102
+ } as BuyWithFiatStatus);
103
+ expect(result).toEqual({
104
+ status: "Pending",
105
+ color: "accentText",
106
+ loading: true,
107
+ step: 2,
108
+ progressStatus: "pending",
109
+ });
110
+ });
111
+
112
+ it('returns "Pending" for PENDING_ON_RAMP_TRANSFER status', () => {
113
+ const result = getBuyWithFiatStatusMeta({
114
+ status: "PENDING_ON_RAMP_TRANSFER",
115
+ } as BuyWithFiatStatus);
116
+ expect(result).toEqual({
117
+ status: "Pending",
118
+ color: "accentText",
119
+ loading: true,
120
+ step: 1,
121
+ progressStatus: "pending",
122
+ });
123
+ });
124
+
125
+ it('returns "Completed" for ON_RAMP_TRANSFER_COMPLETED status', () => {
126
+ const result = getBuyWithFiatStatusMeta({
127
+ status: "ON_RAMP_TRANSFER_COMPLETED",
128
+ } as BuyWithFiatStatus);
129
+ expect(result).toEqual({
130
+ status: "Completed",
131
+ color: "success",
132
+ loading: true,
133
+ step: 1,
134
+ progressStatus: "completed",
135
+ });
136
+ });
137
+
138
+ it('returns "Action Required" for CRYPTO_SWAP_REQUIRED status', () => {
139
+ const result = getBuyWithFiatStatusMeta({
140
+ status: "CRYPTO_SWAP_REQUIRED",
141
+ } as BuyWithFiatStatus);
142
+ expect(result).toEqual({
143
+ status: "Action Required",
144
+ color: "accentText",
145
+ step: 2,
146
+ progressStatus: "actionRequired",
147
+ });
148
+ });
149
+
150
+ it('returns "Failed" for PAYMENT_FAILED status', () => {
151
+ const result = getBuyWithFiatStatusMeta({
152
+ status: "PAYMENT_FAILED",
153
+ } as BuyWithFiatStatus);
154
+ expect(result).toEqual({
155
+ status: "Failed",
156
+ color: "danger",
157
+ step: 1,
158
+ progressStatus: "failed",
159
+ });
160
+ });
161
+
162
+ it('returns "Unknown" for unhandled status', () => {
163
+ const result = getBuyWithFiatStatusMeta({
164
+ // @ts-ignore
165
+ status: "UNKNOWN_STATUS",
166
+ });
167
+ expect(result).toEqual({
168
+ status: "Unknown",
169
+ color: "secondaryText",
170
+ step: 1,
171
+ progressStatus: "unknown",
172
+ });
173
+ });
174
+ });
@@ -0,0 +1,30 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { formatSeconds } from "./formatSeconds.js";
3
+
4
+ describe("formatSeconds", () => {
5
+ it("formats seconds to hours and minutes when over 3600 seconds", () => {
6
+ expect(formatSeconds(3601)).toBe("1 Hours 0 Minutes");
7
+ expect(formatSeconds(7200)).toBe("2 Hours 0 Minutes");
8
+ expect(formatSeconds(5400)).toBe("1 Hours 30 Minutes");
9
+ expect(formatSeconds(12345)).toBe("3 Hours 25 Minutes");
10
+ });
11
+
12
+ it("formats seconds to minutes when between 61 and 3600 seconds", () => {
13
+ expect(formatSeconds(61)).toBe("2 Minutes");
14
+ expect(formatSeconds(120)).toBe("2 Minutes");
15
+ expect(formatSeconds(3599)).toBe("60 Minutes");
16
+ expect(formatSeconds(1800)).toBe("30 Minutes");
17
+ });
18
+
19
+ it('formats seconds to "Xs" when 60 seconds or less', () => {
20
+ expect(formatSeconds(60)).toBe("60s");
21
+ expect(formatSeconds(59)).toBe("59s");
22
+ expect(formatSeconds(1)).toBe("1s");
23
+ expect(formatSeconds(0)).toBe("0s");
24
+ });
25
+
26
+ it("handles decimal inputs by rounding down for hours/minutes and up for minutes only", () => {
27
+ expect(formatSeconds(3661.5)).toBe("1 Hours 1 Minutes");
28
+ expect(formatSeconds(119.9)).toBe("2 Minutes");
29
+ });
30
+ });
@@ -0,0 +1,20 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { getBuyTokenAmountFontSize } from "./utils.js";
3
+
4
+ describe("getBuyTokenAmountFontSize", () => {
5
+ it("returns 26px for strings longer than 10 characters", () => {
6
+ expect(getBuyTokenAmountFontSize("12345678901")).toBe("26px");
7
+ expect(getBuyTokenAmountFontSize("1234567890123")).toBe("26px");
8
+ });
9
+
10
+ it("returns 34px for strings longer than 6 characters but not more than 10", () => {
11
+ expect(getBuyTokenAmountFontSize("1234567")).toBe("34px");
12
+ expect(getBuyTokenAmountFontSize("1234567890")).toBe("34px");
13
+ });
14
+
15
+ it("returns 50px for strings 6 characters or shorter", () => {
16
+ expect(getBuyTokenAmountFontSize("123456")).toBe("50px");
17
+ expect(getBuyTokenAmountFontSize("12345")).toBe("50px");
18
+ expect(getBuyTokenAmountFontSize("")).toBe("50px");
19
+ });
20
+ });
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { LocaleId } from "../../../../../react/web/ui/types.js";
3
+ import br from "./br.js";
4
+ import de from "./de.js";
5
+ import en from "./en.js";
6
+ import es from "./es.js";
7
+ import fr from "./fr.js";
8
+ import { getInjectedWalletLocale } from "./getInjectedWalletLocale.js";
9
+ import ja from "./ja.js";
10
+ import kr from "./kr.js";
11
+ import tl from "./tl.js";
12
+ import vi from "./vi.js";
13
+
14
+ const locales: { locale: LocaleId; content: object }[] = [
15
+ { locale: "es_ES", content: es },
16
+ { locale: "ja_JP", content: ja },
17
+ { locale: "tl_PH", content: tl },
18
+ { locale: "vi_VN", content: vi },
19
+ { locale: "de_DE", content: de },
20
+ { locale: "ko_KR", content: kr },
21
+ { locale: "fr_FR", content: fr },
22
+ { locale: "pt_BR", content: br },
23
+ ];
24
+
25
+ describe("getInjectedWalletLocale", () => {
26
+ for (const item of locales) {
27
+ it(`should return the correct locale structure for ${item.locale}`, async () => {
28
+ expect(await getInjectedWalletLocale(item.locale)).toStrictEqual(
29
+ item.content,
30
+ );
31
+ });
32
+ }
33
+
34
+ it("should return the default locale being ENGLISH for an unsupported locale", async () => {
35
+ expect(
36
+ await getInjectedWalletLocale("unsupported_locale" as LocaleId),
37
+ ).toBe(en);
38
+ });
39
+ });
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { LocaleId } from "../../../../../react/web/ui/types.js";
3
+ import br from "./br.js";
4
+ import de from "./de.js";
5
+ import en from "./en.js";
6
+ import es from "./es.js";
7
+ import fr from "./fr.js";
8
+ import { getSmartWalletLocale } from "./getSmartWalletLocale.js";
9
+ import ja from "./ja.js";
10
+ import kr from "./kr.js";
11
+ import tl from "./tl.js";
12
+ import vi from "./vi.js";
13
+
14
+ const locales: { locale: LocaleId; content: object }[] = [
15
+ { locale: "es_ES", content: es },
16
+ { locale: "ja_JP", content: ja },
17
+ { locale: "tl_PH", content: tl },
18
+ { locale: "vi_VN", content: vi },
19
+ { locale: "de_DE", content: de },
20
+ { locale: "ko_KR", content: kr },
21
+ { locale: "fr_FR", content: fr },
22
+ { locale: "pt_BR", content: br },
23
+ ];
24
+
25
+ describe("getInjectedWalletLocale", () => {
26
+ for (const item of locales) {
27
+ it(`should return the correct locale structure for ${item.locale}`, async () => {
28
+ expect(await getSmartWalletLocale(item.locale)).toStrictEqual(
29
+ item.content,
30
+ );
31
+ });
32
+ }
33
+
34
+ it("should return the default locale being ENGLISH for an unsupported locale", async () => {
35
+ expect(await getSmartWalletLocale("unsupported_locale" as LocaleId)).toBe(
36
+ en,
37
+ );
38
+ });
39
+ });
@@ -0,0 +1,108 @@
1
+ import type { AbiFunction } from "abitype";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { parseAbiParams } from "../contract/parse-abi-params.js";
4
+ import { normalizeFunctionParams } from "./normalizeFunctionParams.js";
5
+
6
+ vi.mock("../contract/parse-abi-params.js", () => {
7
+ return {
8
+ parseAbiParams: vi.fn((_types, values) => values),
9
+ };
10
+ });
11
+
12
+ describe("normalizeFunctionParams", () => {
13
+ it("should return an empty array when abiFunction is undefined", () => {
14
+ const result = normalizeFunctionParams(undefined, {});
15
+ expect(result).toEqual([]);
16
+ });
17
+
18
+ it("should normalize and return function parameters correctly", () => {
19
+ const abiFunction: AbiFunction = {
20
+ inputs: [
21
+ { name: "_param1", type: "uint256" },
22
+ { name: "_param2", type: "string" },
23
+ ],
24
+ type: "function",
25
+ stateMutability: "pure",
26
+ name: "test",
27
+ outputs: [],
28
+ };
29
+ const params = {
30
+ param1: 123,
31
+ param2: "hello",
32
+ };
33
+
34
+ const result = normalizeFunctionParams(abiFunction, params);
35
+ expect(result).toEqual([123, "hello"]);
36
+ });
37
+
38
+ it("should handle parameter names with underscores", () => {
39
+ const abiFunction: AbiFunction = {
40
+ inputs: [
41
+ { name: "_param1", type: "uint256" },
42
+ { name: "_param2", type: "string" },
43
+ ],
44
+ type: "function",
45
+ stateMutability: "pure",
46
+ name: "test",
47
+ outputs: [],
48
+ };
49
+ const params = {
50
+ _param1: 123,
51
+ param2: "hello",
52
+ };
53
+
54
+ const result = normalizeFunctionParams(abiFunction, params);
55
+ expect(result).toEqual([123, "hello"]);
56
+ });
57
+
58
+ it("should throw an error if a parameter name is missing", () => {
59
+ const abiFunction: AbiFunction = {
60
+ inputs: [{ name: undefined, type: "uint256" }],
61
+ type: "function",
62
+ stateMutability: "pure",
63
+ name: "test",
64
+ outputs: [],
65
+ };
66
+
67
+ expect(() => normalizeFunctionParams(abiFunction, {})).toThrow(
68
+ "Missing named parameter for test at index 0",
69
+ );
70
+ });
71
+
72
+ it("should throw an error if a parameter value is missing", () => {
73
+ const abiFunction: AbiFunction = {
74
+ inputs: [{ name: "_param1", type: "uint256" }],
75
+ name: "testFunction",
76
+ type: "function",
77
+ stateMutability: "pure",
78
+ outputs: [],
79
+ };
80
+
81
+ expect(() => normalizeFunctionParams(abiFunction, {})).toThrow(
82
+ "Missing value for parameter _param1 at index 0",
83
+ );
84
+ });
85
+
86
+ it("should call parseAbiParams with the correct arguments", () => {
87
+ const abiFunction: AbiFunction = {
88
+ inputs: [
89
+ { name: "_param1", type: "uint256" },
90
+ { name: "_param2", type: "string" },
91
+ ],
92
+ type: "function",
93
+ stateMutability: "pure",
94
+ name: "test",
95
+ outputs: [],
96
+ };
97
+ const params = {
98
+ param1: 123,
99
+ param2: "hello",
100
+ };
101
+
102
+ normalizeFunctionParams(abiFunction, params);
103
+ expect(parseAbiParams).toHaveBeenCalledWith(
104
+ ["uint256", "string"],
105
+ [123, "hello"],
106
+ );
107
+ });
108
+ });