thirdweb 5.102.0 → 5.102.2

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 (96) hide show
  1. package/dist/cjs/bridge/Webhook.js +5 -2
  2. package/dist/cjs/bridge/Webhook.js.map +1 -1
  3. package/dist/cjs/insight/get-nfts.js +1 -1
  4. package/dist/cjs/insight/get-nfts.js.map +1 -1
  5. package/dist/cjs/pay/convert/cryptoToFiat.js +21 -13
  6. package/dist/cjs/pay/convert/cryptoToFiat.js.map +1 -1
  7. package/dist/cjs/pay/convert/fiatToCrypto.js +22 -14
  8. package/dist/cjs/pay/convert/fiatToCrypto.js.map +1 -1
  9. package/dist/cjs/pay/utils/definitions.js +1 -5
  10. package/dist/cjs/pay/utils/definitions.js.map +1 -1
  11. package/dist/cjs/react/native/hooks/wallets/useUnlinkProfile.js +19 -1
  12. package/dist/cjs/react/native/hooks/wallets/useUnlinkProfile.js.map +1 -1
  13. package/dist/cjs/react/web/hooks/wallets/useUnlinkProfile.js +19 -1
  14. package/dist/cjs/react/web/hooks/wallets/useUnlinkProfile.js.map +1 -1
  15. package/dist/cjs/version.js +1 -1
  16. package/dist/cjs/wallets/in-app/core/authentication/linkAccount.js +6 -2
  17. package/dist/cjs/wallets/in-app/core/authentication/linkAccount.js.map +1 -1
  18. package/dist/cjs/wallets/in-app/native/auth/index.js +1 -1
  19. package/dist/cjs/wallets/in-app/native/auth/index.js.map +1 -1
  20. package/dist/cjs/wallets/in-app/native/native-connector.js +2 -1
  21. package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
  22. package/dist/cjs/wallets/in-app/web/lib/auth/index.js +30 -1
  23. package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
  24. package/dist/cjs/wallets/in-app/web/lib/web-connector.js +2 -1
  25. package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
  26. package/dist/esm/bridge/Webhook.js +5 -2
  27. package/dist/esm/bridge/Webhook.js.map +1 -1
  28. package/dist/esm/insight/get-nfts.js +1 -1
  29. package/dist/esm/insight/get-nfts.js.map +1 -1
  30. package/dist/esm/pay/convert/cryptoToFiat.js +21 -13
  31. package/dist/esm/pay/convert/cryptoToFiat.js.map +1 -1
  32. package/dist/esm/pay/convert/fiatToCrypto.js +22 -14
  33. package/dist/esm/pay/convert/fiatToCrypto.js.map +1 -1
  34. package/dist/esm/pay/utils/definitions.js +0 -2
  35. package/dist/esm/pay/utils/definitions.js.map +1 -1
  36. package/dist/esm/react/native/hooks/wallets/useUnlinkProfile.js +19 -1
  37. package/dist/esm/react/native/hooks/wallets/useUnlinkProfile.js.map +1 -1
  38. package/dist/esm/react/web/hooks/wallets/useUnlinkProfile.js +19 -1
  39. package/dist/esm/react/web/hooks/wallets/useUnlinkProfile.js.map +1 -1
  40. package/dist/esm/version.js +1 -1
  41. package/dist/esm/wallets/in-app/core/authentication/linkAccount.js +6 -2
  42. package/dist/esm/wallets/in-app/core/authentication/linkAccount.js.map +1 -1
  43. package/dist/esm/wallets/in-app/native/auth/index.js +1 -1
  44. package/dist/esm/wallets/in-app/native/auth/index.js.map +1 -1
  45. package/dist/esm/wallets/in-app/native/native-connector.js +2 -1
  46. package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
  47. package/dist/esm/wallets/in-app/web/lib/auth/index.js +30 -1
  48. package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
  49. package/dist/esm/wallets/in-app/web/lib/web-connector.js +2 -1
  50. package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
  51. package/dist/types/bridge/Webhook.d.ts +10 -4
  52. package/dist/types/bridge/Webhook.d.ts.map +1 -1
  53. package/dist/types/pay/convert/cryptoToFiat.d.ts.map +1 -1
  54. package/dist/types/pay/convert/fiatToCrypto.d.ts.map +1 -1
  55. package/dist/types/pay/utils/definitions.d.ts +0 -2
  56. package/dist/types/pay/utils/definitions.d.ts.map +1 -1
  57. package/dist/types/react/native/hooks/wallets/useUnlinkProfile.d.ts +18 -0
  58. package/dist/types/react/native/hooks/wallets/useUnlinkProfile.d.ts.map +1 -1
  59. package/dist/types/react/web/hooks/wallets/useUnlinkProfile.d.ts +18 -0
  60. package/dist/types/react/web/hooks/wallets/useUnlinkProfile.d.ts.map +1 -1
  61. package/dist/types/version.d.ts +1 -1
  62. package/dist/types/wallets/in-app/core/authentication/linkAccount.d.ts +2 -1
  63. package/dist/types/wallets/in-app/core/authentication/linkAccount.d.ts.map +1 -1
  64. package/dist/types/wallets/in-app/core/authentication/types.d.ts +1 -0
  65. package/dist/types/wallets/in-app/core/authentication/types.d.ts.map +1 -1
  66. package/dist/types/wallets/in-app/core/interfaces/connector.d.ts +1 -1
  67. package/dist/types/wallets/in-app/core/interfaces/connector.d.ts.map +1 -1
  68. package/dist/types/wallets/in-app/native/auth/index.d.ts.map +1 -1
  69. package/dist/types/wallets/in-app/native/native-connector.d.ts +1 -1
  70. package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
  71. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts +29 -0
  72. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
  73. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +1 -1
  74. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
  75. package/package.json +3 -3
  76. package/src/bridge/Webhook.test.ts +8 -2
  77. package/src/bridge/Webhook.ts +7 -2
  78. package/src/insight/get-nfts.ts +1 -1
  79. package/src/pay/convert/cryptoToFiat.test.ts +1 -21
  80. package/src/pay/convert/cryptoToFiat.ts +31 -14
  81. package/src/pay/convert/fiatToCrypto.test.ts +1 -21
  82. package/src/pay/convert/fiatToCrypto.ts +30 -14
  83. package/src/pay/utils/definitions.ts +0 -6
  84. package/src/react/native/hooks/wallets/useUnlinkProfile.test.tsx +27 -0
  85. package/src/react/native/hooks/wallets/useUnlinkProfile.ts +24 -1
  86. package/src/react/web/hooks/wallets/useUnlinkProfile.test.tsx +2 -0
  87. package/src/react/web/hooks/wallets/useUnlinkProfile.ts +24 -1
  88. package/src/version.ts +1 -1
  89. package/src/wallets/in-app/core/authentication/linkAccount.test.ts +31 -1
  90. package/src/wallets/in-app/core/authentication/linkAccount.ts +7 -1
  91. package/src/wallets/in-app/core/authentication/types.ts +1 -0
  92. package/src/wallets/in-app/core/interfaces/connector.ts +4 -1
  93. package/src/wallets/in-app/native/auth/index.ts +4 -1
  94. package/src/wallets/in-app/native/native-connector.ts +2 -1
  95. package/src/wallets/in-app/web/lib/auth/index.ts +33 -1
  96. package/src/wallets/in-app/web/lib/web-connector.ts +2 -1
@@ -1,3 +1,4 @@
1
+ import { getV1TokensPrice } from "@thirdweb-dev/insight";
1
2
  import type { Address } from "abitype";
2
3
  import type { Chain } from "../../chains/types.js";
3
4
  import type { ThirdwebClient } from "../../client/client.js";
@@ -5,8 +6,10 @@ import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
5
6
  import { getBytecode } from "../../contract/actions/get-bytecode.js";
6
7
  import { getContract } from "../../contract/contract.js";
7
8
  import { isAddress } from "../../utils/address.js";
9
+ import { getThirdwebDomains } from "../../utils/domains.js";
8
10
  import { getClientFetch } from "../../utils/fetch.js";
9
- import { getPayConvertFiatToCryptoEndpoint } from "../utils/definitions.js";
11
+ import { stringify } from "../../utils/json.js";
12
+ import { withCache } from "../../utils/promise/withCache.js";
10
13
  import type { SupportedFiatCurrency } from "./type.js";
11
14
 
12
15
  /**
@@ -91,21 +94,34 @@ export async function convertFiatToCrypto(
91
94
  );
92
95
  }
93
96
  }
94
- const params = {
95
- from,
96
- to,
97
- chainId: String(chain.id),
98
- fromAmount: String(fromAmount),
99
- };
100
- const queryString = new URLSearchParams(params).toString();
101
- const url = `${getPayConvertFiatToCryptoEndpoint()}?${queryString}`;
102
- const response = await getClientFetch(client)(url);
103
- if (!response.ok) {
97
+ const result = await withCache(
98
+ () =>
99
+ getV1TokensPrice({
100
+ baseUrl: `https://${getThirdwebDomains().insight}`,
101
+ fetch: getClientFetch(client),
102
+ query: {
103
+ address: to,
104
+ chain_id: [chain.id],
105
+ },
106
+ }),
107
+ {
108
+ cacheKey: `convert-fiat-to-crypto-${to}-${chain.id}`,
109
+ cacheTime: 1000 * 60, // 1 minute cache
110
+ },
111
+ );
112
+
113
+ if (result.error) {
104
114
  throw new Error(
105
- `Failed to convert ${from} value to token (${to}) on chainId: ${chain.id}`,
115
+ `Failed to fetch ${from} value for token (${to}) on chainId: ${chain.id} - ${result.response.status} ${result.response.statusText} - ${result.error ? stringify(result.error) : "Unknown error"}`,
106
116
  );
107
117
  }
108
118
 
109
- const data: { result: number } = await response.json();
110
- return data;
119
+ const firstResult = result.data?.data[0];
120
+
121
+ if (!firstResult || firstResult.price_usd === 0) {
122
+ throw new Error(
123
+ `Failed to fetch ${from} value for token (${to}) on chainId: ${chain.id}`,
124
+ );
125
+ }
126
+ return { result: fromAmount / firstResult.price_usd };
111
127
  }
@@ -28,9 +28,3 @@ export const getPayBuyWithCryptoHistoryEndpoint = () =>
28
28
  */
29
29
  export const getPayBuyHistoryEndpoint = () =>
30
30
  `${getPayBaseUrl()}/wallet/history/v1`;
31
-
32
- export const getPayConvertFiatToCryptoEndpoint = () =>
33
- `${getPayBaseUrl()}/convert/fiat-to-crypto/v1`;
34
-
35
- export const getPayConvertCryptoToFiatEndpoint = () =>
36
- `${getPayBaseUrl()}/convert/crypto-to-fiat/v1`;
@@ -40,6 +40,32 @@ describe("useUnlinkProfile", () => {
40
40
  client: TEST_CLIENT,
41
41
  ecosystem: undefined,
42
42
  profileToUnlink: mockProfile,
43
+ allowAccountDeletion: false,
44
+ });
45
+ expect(queryClient.invalidateQueries).toHaveBeenCalledWith({
46
+ queryKey: ["profiles"],
47
+ });
48
+ });
49
+
50
+ it("should call unlinkProfile with allowAccountDeletion if true", async () => {
51
+ const { result } = renderHook(() => useUnlinkProfile(), {
52
+ wrapper,
53
+ });
54
+ const mutationFn = result.current.mutateAsync;
55
+
56
+ await act(async () => {
57
+ await mutationFn({
58
+ client: TEST_CLIENT,
59
+ profileToUnlink: mockProfile,
60
+ allowAccountDeletion: true,
61
+ });
62
+ });
63
+
64
+ expect(unlinkProfile).toHaveBeenCalledWith({
65
+ client: TEST_CLIENT,
66
+ ecosystem: undefined,
67
+ profileToUnlink: mockProfile,
68
+ allowAccountDeletion: true,
43
69
  });
44
70
  expect(queryClient.invalidateQueries).toHaveBeenCalledWith({
45
71
  queryKey: ["profiles"],
@@ -70,6 +96,7 @@ describe("useUnlinkProfile", () => {
70
96
  ?.partnerId,
71
97
  },
72
98
  profileToUnlink: mockProfile,
99
+ allowAccountDeletion: false,
73
100
  });
74
101
  });
75
102
  });
@@ -31,6 +31,23 @@ import { useConnectedWallets } from "../../../core/hooks/wallets/useConnectedWal
31
31
  * };
32
32
  * ```
33
33
  *
34
+ * ### Unlinking an email account with account deletion
35
+ *
36
+ * ```jsx
37
+ * import { useUnlinkProfile } from "thirdweb/react";
38
+ *
39
+ * const { mutate: unlinkProfile } = useUnlinkProfile();
40
+ *
41
+ * const onClick = () => {
42
+ * unlinkProfile({
43
+ * client,
44
+ * // Select the profile you want to unlink
45
+ * profileToUnlink: connectedProfiles[0],
46
+ * allowAccountDeletion: true, // This will delete the account if it's the last profile linked to the account
47
+ * });
48
+ * };
49
+ * ```
50
+ *
34
51
  * @wallet
35
52
  */
36
53
  export function useUnlinkProfile() {
@@ -40,7 +57,12 @@ export function useUnlinkProfile() {
40
57
  mutationFn: async ({
41
58
  client,
42
59
  profileToUnlink,
43
- }: { client: ThirdwebClient; profileToUnlink: Profile }) => {
60
+ allowAccountDeletion = false,
61
+ }: {
62
+ client: ThirdwebClient;
63
+ profileToUnlink: Profile;
64
+ allowAccountDeletion?: boolean;
65
+ }) => {
44
66
  const ecosystemWallet = wallets.find((w) => isEcosystemWallet(w));
45
67
  const ecosystem: Ecosystem | undefined = ecosystemWallet
46
68
  ? {
@@ -53,6 +75,7 @@ export function useUnlinkProfile() {
53
75
  client,
54
76
  ecosystem,
55
77
  profileToUnlink,
78
+ allowAccountDeletion,
56
79
  });
57
80
  },
58
81
  onSuccess: () => {
@@ -40,6 +40,7 @@ describe("useUnlinkProfile", () => {
40
40
  client: TEST_CLIENT,
41
41
  ecosystem: undefined,
42
42
  profileToUnlink: mockProfile,
43
+ allowAccountDeletion: false,
43
44
  });
44
45
  expect(queryClient.invalidateQueries).toHaveBeenCalledWith({
45
46
  queryKey: ["profiles"],
@@ -70,6 +71,7 @@ describe("useUnlinkProfile", () => {
70
71
  ?.partnerId,
71
72
  },
72
73
  profileToUnlink: mockProfile,
74
+ allowAccountDeletion: false,
73
75
  });
74
76
  });
75
77
  });
@@ -31,6 +31,23 @@ import { useConnectedWallets } from "../../../core/hooks/wallets/useConnectedWal
31
31
  * };
32
32
  * ```
33
33
  *
34
+ * ### Unlinking an email account with account deletion
35
+ *
36
+ * ```jsx
37
+ * import { useUnlinkProfile } from "thirdweb/react";
38
+ *
39
+ * const { mutate: unlinkProfile } = useUnlinkProfile();
40
+ *
41
+ * const onClick = () => {
42
+ * unlinkProfile({
43
+ * client,
44
+ * // Select the profile you want to unlink
45
+ * profileToUnlink: connectedProfiles[0],
46
+ * allowAccountDeletion: true, // This will delete the account if it's the last profile linked to the account
47
+ * });
48
+ * };
49
+ * ```
50
+ *
34
51
  * @wallet
35
52
  */
36
53
  export function useUnlinkProfile() {
@@ -40,7 +57,12 @@ export function useUnlinkProfile() {
40
57
  mutationFn: async ({
41
58
  client,
42
59
  profileToUnlink,
43
- }: { client: ThirdwebClient; profileToUnlink: Profile }) => {
60
+ allowAccountDeletion = false,
61
+ }: {
62
+ client: ThirdwebClient;
63
+ profileToUnlink: Profile;
64
+ allowAccountDeletion?: boolean;
65
+ }) => {
44
66
  const ecosystemWallet = wallets.find((w) => isEcosystemWallet(w));
45
67
  const ecosystem: Ecosystem | undefined = ecosystemWallet
46
68
  ? {
@@ -53,6 +75,7 @@ export function useUnlinkProfile() {
53
75
  client,
54
76
  ecosystem,
55
77
  profileToUnlink,
78
+ allowAccountDeletion,
56
79
  });
57
80
  },
58
81
  onSuccess: () => {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.102.0";
1
+ export const version = "5.102.2";
@@ -90,7 +90,37 @@ describe("Account linking functions", () => {
90
90
  Authorization: "Bearer iaw-auth-token:mock-token",
91
91
  "Content-Type": "application/json",
92
92
  },
93
- body: JSON.stringify(profileToUnlink),
93
+ body: JSON.stringify({
94
+ type: profileToUnlink.type,
95
+ details: profileToUnlink.details,
96
+ allowAccountDeletion: false,
97
+ }),
98
+ },
99
+ );
100
+ expect(result).toEqual(mockLinkedAccounts);
101
+ });
102
+
103
+ it("should successfully unlink an account with allowAccountDeletion", async () => {
104
+ const result = await unlinkAccount({
105
+ client: mockClient,
106
+ profileToUnlink,
107
+ storage: mockStorage,
108
+ allowAccountDeletion: true,
109
+ });
110
+
111
+ expect(mockFetch).toHaveBeenCalledWith(
112
+ "https://embedded-wallet.thirdweb.com/api/2024-05-05/account/disconnect",
113
+ {
114
+ method: "POST",
115
+ headers: {
116
+ Authorization: "Bearer iaw-auth-token:mock-token",
117
+ "Content-Type": "application/json",
118
+ },
119
+ body: JSON.stringify({
120
+ type: profileToUnlink.type,
121
+ details: profileToUnlink.details,
122
+ allowAccountDeletion: true,
123
+ }),
94
124
  },
95
125
  );
96
126
  expect(result).toEqual(mockLinkedAccounts);
@@ -66,11 +66,13 @@ export async function unlinkAccount({
66
66
  client,
67
67
  ecosystem,
68
68
  profileToUnlink,
69
+ allowAccountDeletion = false,
69
70
  storage,
70
71
  }: {
71
72
  client: ThirdwebClient;
72
73
  ecosystem?: Ecosystem;
73
74
  profileToUnlink: Profile;
75
+ allowAccountDeletion?: boolean;
74
76
  storage: ClientScopedStorage;
75
77
  }): Promise<Profile[]> {
76
78
  const clientFetch = getClientFetch(client, ecosystem);
@@ -90,7 +92,11 @@ export async function unlinkAccount({
90
92
  {
91
93
  method: "POST",
92
94
  headers,
93
- body: stringify(profileToUnlink),
95
+ body: stringify({
96
+ type: profileToUnlink.type,
97
+ details: profileToUnlink.details,
98
+ allowAccountDeletion,
99
+ }),
94
100
  },
95
101
  );
96
102
 
@@ -259,4 +259,5 @@ export type UnlinkParams = {
259
259
  client: ThirdwebClient;
260
260
  ecosystem?: Ecosystem;
261
261
  profileToUnlink: Profile;
262
+ allowAccountDeletion?: boolean;
262
263
  };
@@ -37,7 +37,10 @@ export interface InAppConnector {
37
37
  ): Promise<AuthLoginReturnType>;
38
38
  logout(): Promise<LogoutReturnType>;
39
39
  linkProfile(args: AuthArgsType): Promise<Profile[]>;
40
- unlinkProfile(args: Profile): Promise<Profile[]>;
40
+ unlinkProfile(
41
+ args: Profile,
42
+ allowAccountDeletion?: boolean,
43
+ ): Promise<Profile[]>;
41
44
  getProfiles(): Promise<Profile[]>;
42
45
  storage: ClientScopedStorage;
43
46
  }
@@ -203,7 +203,10 @@ export async function linkProfile(args: AuthArgsType) {
203
203
  */
204
204
  export async function unlinkProfile(args: UnlinkParams) {
205
205
  const connector = await getInAppWalletConnector(args.client, args.ecosystem);
206
- return await connector.unlinkProfile(args.profileToUnlink);
206
+ return await connector.unlinkProfile(
207
+ args.profileToUnlink,
208
+ args.allowAccountDeletion,
209
+ );
207
210
  }
208
211
 
209
212
  /**
@@ -367,7 +367,7 @@ export class InAppNativeConnector implements InAppConnector {
367
367
  });
368
368
  }
369
369
 
370
- async unlinkProfile(profile: Profile) {
370
+ async unlinkProfile(profile: Profile, allowAccountDeletion?: boolean) {
371
371
  const { unlinkAccount } = await import(
372
372
  "../core/authentication/linkAccount.js"
373
373
  );
@@ -376,6 +376,7 @@ export class InAppNativeConnector implements InAppConnector {
376
376
  ecosystem: this.ecosystem,
377
377
  storage: this.storage,
378
378
  profileToUnlink: profile,
379
+ allowAccountDeletion,
379
380
  });
380
381
  }
381
382
 
@@ -224,6 +224,8 @@ export async function linkProfile(args: AuthArgsType) {
224
224
  * @throws If the unlinking fails. This can happen if the account has no other associated profiles or if the profile that is being unlinked doesn't exists for the current logged in user.
225
225
  *
226
226
  * @example
227
+ * ### Unlinking an authentication method
228
+ *
227
229
  * ```ts
228
230
  * import { inAppWallet } from "thirdweb/wallets";
229
231
  *
@@ -239,11 +241,41 @@ export async function linkProfile(args: AuthArgsType) {
239
241
  * profileToUnlink: profiles[0],
240
242
  * });
241
243
  * ```
244
+ *
245
+ * ### Unlinking an authentication for ecosystems
246
+ *
247
+ * ```ts
248
+ * import { unlinkProfile } from "thirdweb/wallets/in-app";
249
+ *
250
+ * const updatedProfiles = await unlinkProfile({
251
+ * client,
252
+ * ecosystem: {
253
+ * id: "ecosystem.your-ecosystem-id",
254
+ * },
255
+ * profileToUnlink: profiles[0],
256
+ * });
257
+ * ```
258
+ *
259
+ * ### Unlinking an authentication method with account deletion
260
+ *
261
+ * ```ts
262
+ * import { unlinkProfile } from "thirdweb/wallets/in-app";
263
+ *
264
+ * const updatedProfiles = await unlinkProfile({
265
+ * client,
266
+ * profileToUnlink: profiles[0],
267
+ * allowAccountDeletion: true, // This will delete the account if it's the last profile linked to the account
268
+ * });
269
+ * ```
270
+ *
242
271
  * @wallet
243
272
  */
244
273
  export async function unlinkProfile(args: UnlinkParams) {
245
274
  const connector = await getInAppWalletConnector(args.client, args.ecosystem);
246
- return await connector.unlinkProfile(args.profileToUnlink);
275
+ return await connector.unlinkProfile(
276
+ args.profileToUnlink,
277
+ args.allowAccountDeletion,
278
+ );
247
279
  }
248
280
 
249
281
  /**
@@ -470,12 +470,13 @@ export class InAppWebConnector implements InAppConnector {
470
470
  });
471
471
  }
472
472
 
473
- async unlinkProfile(profile: Profile) {
473
+ async unlinkProfile(profile: Profile, allowAccountDeletion?: boolean) {
474
474
  return await unlinkAccount({
475
475
  client: this.client,
476
476
  storage: this.storage,
477
477
  ecosystem: this.ecosystem,
478
478
  profileToUnlink: profile,
479
+ allowAccountDeletion,
479
480
  });
480
481
  }
481
482