thirdweb 5.47.0-nightly-f0d6e343eea28cd49863ba4794b89d6b070c52b2-20240818000714 → 5.47.1-nightly-574ff0295dcbb39f2ddd753c9e8a264498aae99e-20240819000344

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 (92) hide show
  1. package/dist/cjs/exports/extensions/lens.js +4 -1
  2. package/dist/cjs/exports/extensions/lens.js.map +1 -1
  3. package/dist/cjs/exports/utils.js +7 -5
  4. package/dist/cjs/exports/utils.js.map +1 -1
  5. package/dist/cjs/extensions/lens/read/getFullProfile.js.map +1 -1
  6. package/dist/cjs/extensions/lens/read/getHandleFromProfileId.js.map +1 -1
  7. package/dist/cjs/extensions/lens/read/getProfileMetadata.js.map +1 -1
  8. package/dist/cjs/extensions/lens/read/resolveAddress.js +74 -0
  9. package/dist/cjs/extensions/lens/read/resolveAddress.js.map +1 -0
  10. package/dist/cjs/extensions/vote/read/getProposalVoteCounts.js +4 -3
  11. package/dist/cjs/extensions/vote/read/getProposalVoteCounts.js.map +1 -1
  12. package/dist/cjs/react/core/hooks/transaction/useSendAndConfirmTransaction.js +16 -1
  13. package/dist/cjs/react/core/hooks/transaction/useSendAndConfirmTransaction.js.map +1 -1
  14. package/dist/cjs/react/native/hooks/transaction/useSendTransaction.js +11 -0
  15. package/dist/cjs/react/native/hooks/transaction/useSendTransaction.js.map +1 -1
  16. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +1 -0
  17. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  18. package/dist/cjs/react/web/ui/TransactionButton/index.js +22 -6
  19. package/dist/cjs/react/web/ui/TransactionButton/index.js.map +1 -1
  20. package/dist/cjs/transaction/actions/send-and-confirm-transaction.js +15 -0
  21. package/dist/cjs/transaction/actions/send-and-confirm-transaction.js.map +1 -1
  22. package/dist/cjs/transaction/actions/send-transaction.js +13 -0
  23. package/dist/cjs/transaction/actions/send-transaction.js.map +1 -1
  24. package/dist/cjs/version.js +1 -1
  25. package/dist/esm/exports/extensions/lens.js +2 -0
  26. package/dist/esm/exports/extensions/lens.js.map +1 -1
  27. package/dist/esm/exports/utils.js +1 -0
  28. package/dist/esm/exports/utils.js.map +1 -1
  29. package/dist/esm/extensions/lens/read/getFullProfile.js.map +1 -1
  30. package/dist/esm/extensions/lens/read/getHandleFromProfileId.js.map +1 -1
  31. package/dist/esm/extensions/lens/read/getProfileMetadata.js.map +1 -1
  32. package/dist/esm/extensions/lens/read/resolveAddress.js +71 -0
  33. package/dist/esm/extensions/lens/read/resolveAddress.js.map +1 -0
  34. package/dist/esm/extensions/vote/read/getProposalVoteCounts.js +4 -3
  35. package/dist/esm/extensions/vote/read/getProposalVoteCounts.js.map +1 -1
  36. package/dist/esm/react/core/hooks/transaction/useSendAndConfirmTransaction.js +16 -1
  37. package/dist/esm/react/core/hooks/transaction/useSendAndConfirmTransaction.js.map +1 -1
  38. package/dist/esm/react/native/hooks/transaction/useSendTransaction.js +11 -0
  39. package/dist/esm/react/native/hooks/transaction/useSendTransaction.js.map +1 -1
  40. package/dist/esm/react/web/ui/ConnectWallet/Details.js +1 -0
  41. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  42. package/dist/esm/react/web/ui/TransactionButton/index.js +22 -6
  43. package/dist/esm/react/web/ui/TransactionButton/index.js.map +1 -1
  44. package/dist/esm/transaction/actions/send-and-confirm-transaction.js +15 -0
  45. package/dist/esm/transaction/actions/send-and-confirm-transaction.js.map +1 -1
  46. package/dist/esm/transaction/actions/send-transaction.js +13 -0
  47. package/dist/esm/transaction/actions/send-transaction.js.map +1 -1
  48. package/dist/esm/version.js +1 -1
  49. package/dist/types/exports/extensions/lens.d.ts +1 -0
  50. package/dist/types/exports/extensions/lens.d.ts.map +1 -1
  51. package/dist/types/exports/utils.d.ts +1 -0
  52. package/dist/types/exports/utils.d.ts.map +1 -1
  53. package/dist/types/extensions/lens/read/getFullProfile.d.ts +16 -4
  54. package/dist/types/extensions/lens/read/getFullProfile.d.ts.map +1 -1
  55. package/dist/types/extensions/lens/read/getHandleFromProfileId.d.ts +12 -3
  56. package/dist/types/extensions/lens/read/getHandleFromProfileId.d.ts.map +1 -1
  57. package/dist/types/extensions/lens/read/getProfileMetadata.d.ts +4 -2
  58. package/dist/types/extensions/lens/read/getProfileMetadata.d.ts.map +1 -1
  59. package/dist/types/extensions/lens/read/resolveAddress.d.ts +47 -0
  60. package/dist/types/extensions/lens/read/resolveAddress.d.ts.map +1 -0
  61. package/dist/types/extensions/vote/read/getAll.d.ts +1 -1
  62. package/dist/types/extensions/vote/read/getProposalVoteCounts.d.ts +4 -3
  63. package/dist/types/extensions/vote/read/getProposalVoteCounts.d.ts.map +1 -1
  64. package/dist/types/react/core/hooks/transaction/useSendAndConfirmTransaction.d.ts +25 -1
  65. package/dist/types/react/core/hooks/transaction/useSendAndConfirmTransaction.d.ts.map +1 -1
  66. package/dist/types/react/native/hooks/transaction/useSendTransaction.d.ts +11 -0
  67. package/dist/types/react/native/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  68. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  69. package/dist/types/react/web/ui/TransactionButton/index.d.ts +22 -6
  70. package/dist/types/react/web/ui/TransactionButton/index.d.ts.map +1 -1
  71. package/dist/types/transaction/actions/send-and-confirm-transaction.d.ts +15 -0
  72. package/dist/types/transaction/actions/send-and-confirm-transaction.d.ts.map +1 -1
  73. package/dist/types/transaction/actions/send-transaction.d.ts +13 -0
  74. package/dist/types/transaction/actions/send-transaction.d.ts.map +1 -1
  75. package/dist/types/version.d.ts +1 -1
  76. package/package.json +1 -1
  77. package/src/exports/extensions/lens.ts +6 -0
  78. package/src/exports/utils.ts +2 -0
  79. package/src/extensions/lens/read/getFullProfile.ts +16 -4
  80. package/src/extensions/lens/read/getHandleFromProfileId.ts +12 -3
  81. package/src/extensions/lens/read/getProfileMetadata.ts +4 -2
  82. package/src/extensions/lens/read/resolveAddress.test.ts +23 -0
  83. package/src/extensions/lens/read/resolveAddress.ts +121 -0
  84. package/src/extensions/vote/read/getAll.ts +1 -1
  85. package/src/extensions/vote/read/getProposalVoteCounts.ts +4 -3
  86. package/src/react/core/hooks/transaction/useSendAndConfirmTransaction.ts +30 -5
  87. package/src/react/native/hooks/transaction/useSendTransaction.tsx +11 -0
  88. package/src/react/web/ui/ConnectWallet/Details.tsx +1 -0
  89. package/src/react/web/ui/TransactionButton/index.tsx +22 -6
  90. package/src/transaction/actions/send-and-confirm-transaction.ts +15 -0
  91. package/src/transaction/actions/send-transaction.ts +13 -0
  92. package/src/version.ts +1 -1
@@ -0,0 +1,121 @@
1
+ import type { Chain } from "../../../chains/types.js";
2
+ import type { ThirdwebClient } from "../../../client/client.js";
3
+ import { ZERO_ADDRESS } from "../../../constants/addresses.js";
4
+ import { getAddress, isAddress } from "../../../utils/address.js";
5
+ import { withCache } from "../../../utils/promise/withCache.js";
6
+
7
+ /**
8
+ * @extension LENS
9
+ */
10
+ export type ResolveLensAddressParams = {
11
+ /**
12
+ * Either a full lens handle, or a lens localName
13
+ * Examples:
14
+ * 1. Full handle: "lens/vitalik"
15
+ * 2. Just local name: "vitalik"
16
+ */
17
+ name: string;
18
+ /**
19
+ * a [`ThirdwebClient`](https://portal.thirdweb.com/references/typescript/v5/ThirdwebClient)
20
+ */
21
+ client: ThirdwebClient;
22
+ /**
23
+ * Override parameters for Lens contract, defaults to LensHandle contract on Polygon
24
+ */
25
+ overrides?: {
26
+ /**
27
+ * The contract address of the [`LensHandle contract`](https://www.lens.xyz/docs/resources/smart-contracts)
28
+ */
29
+ lensHandleContractAddress?: string;
30
+ /**
31
+ * The chain which `lensHandleContractAddress` is deployed on
32
+ */
33
+ chain?: Chain;
34
+ };
35
+ };
36
+
37
+ /**
38
+ * Take in a Lens handle or local-name and return the wallet address behind that handle/local-name.
39
+ * For example, "lens/vitalik" is a handle, with "lens" being the namespace and "vitalik" being the local name
40
+ * @extension LENS
41
+ * @example
42
+ * ```ts
43
+ * import { resolveAddress } from "thirdweb/extensions/lens";
44
+ *
45
+ * const walletAddress = await resolveAddress({
46
+ * name: "vitalik",
47
+ * client,
48
+ * });
49
+ * ```
50
+ */
51
+ export async function resolveAddress(
52
+ options: ResolveLensAddressParams,
53
+ ): Promise<string> {
54
+ const { name, overrides, client } = options;
55
+ if (isAddress(name)) {
56
+ return getAddress(name);
57
+ }
58
+ return withCache(
59
+ async (): Promise<string> => {
60
+ const [
61
+ { getContract },
62
+ { getTokenId },
63
+ { ownerOf },
64
+ { polygon },
65
+ { LENS_HANDLE_ADDRESS },
66
+ ] = await Promise.all([
67
+ import("../../../contract/contract.js"),
68
+ import("../__generated__/LensHandle/read/getTokenId.js"),
69
+ import("../../erc721/__generated__/IERC721A/read/ownerOf.js"),
70
+ import("../../../chains/chain-definitions/polygon.js"),
71
+ import("../consts.js"),
72
+ ]);
73
+ const contract = getContract({
74
+ address: overrides?.lensHandleContractAddress || LENS_HANDLE_ADDRESS,
75
+ chain: overrides?.chain || polygon,
76
+ client,
77
+ });
78
+ /**
79
+ * For better UX, we accept both handle and local name
80
+ * The difference: handle = <namespace>/<local-name>
81
+ * For example, "lens/vitalik" is a handle, with "lens" being the namespace and "vitalik" being the local name
82
+ * Currently there's only 1 namespace called "lens" but we should make sure the code can scale when there are more
83
+ *
84
+ * Since lens does not allow "/" in the name,
85
+ * if the string contains "/", it is either invalid, or it definitely contains the namespace
86
+ * In that case we remove the possible namespace because the `getTokenId` method only accepts localName
87
+ */
88
+ const isPossibleHandle = name.includes("/");
89
+ const localName = isPossibleHandle ? name.split("/")[1] : name;
90
+ if (!localName) {
91
+ throw new Error(`missing local name from ${name}`);
92
+ }
93
+ const tokenId = await getTokenId({ contract, localName });
94
+ if (!tokenId) {
95
+ throw new Error(
96
+ `Could not retrieve tokenId from localName: ${localName}`,
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Another thing to note is that even if you enter an invalid localName,
102
+ * `getTokenId` still returns you a tokenId - so never rely on the result alone.
103
+ * Check if the tokenId truly exists using `exists` or in this case, `ownerOf`
104
+ */
105
+ const address = await ownerOf({ contract, tokenId }).catch(
106
+ () => ZERO_ADDRESS,
107
+ );
108
+ if (address === ZERO_ADDRESS) {
109
+ throw new Error(
110
+ `Could not fetch the wallet address for lens handle: ${name}`,
111
+ );
112
+ }
113
+ return address;
114
+ },
115
+ {
116
+ cacheKey: `lens:addr:${name}`,
117
+ // 1min cache
118
+ cacheTime: 60 * 1000,
119
+ },
120
+ );
121
+ }
@@ -42,7 +42,7 @@ export type ProposalItem = {
42
42
  */
43
43
  stateLabel: string | undefined;
44
44
  /**
45
- * The current vote info. See type ProposalVoteInfo for more context
45
+ * The current vote info. See type [`ProposalVoteInfo`](https://portal.thirdweb.com/references/typescript/v5/ProposalItem) for more context
46
46
  */
47
47
  votes: ProposalVoteInfo;
48
48
  /**
@@ -12,6 +12,7 @@ export type ProposalVoteInfo = { [K in keyof typeof VoteType]: bigint };
12
12
  * Get the info about Against, For and Abstain votes of a proposal
13
13
  * @param options
14
14
  * @returns the object containing the info about Against, For and Abstain votes of a proposal
15
+ * Note: the count is displayed in "wei"
15
16
  * @extension VOTE
16
17
  * @example
17
18
  * ```ts
@@ -21,9 +22,9 @@ export type ProposalVoteInfo = { [K in keyof typeof VoteType]: bigint };
21
22
  *
22
23
  * // Example result
23
24
  * {
24
- * against: 12n, // 12 users voted against the proposal
25
- * for: 104n, // 104 users support the proposal
26
- * abstain: 3n, // 3 users voted abstain on this proposal
25
+ * for: 12000000000000000000n, // 12 tokens (with a decimals of 18) were used to vote "for"
26
+ * against: 7000000000000000000n, // 7 tokens (with a decimals of 18) were used to vote "against"
27
+ * abstain: 0n, // no user has voted abstain on this proposal
27
28
  * }
28
29
  * ```
29
30
  */
@@ -1,9 +1,21 @@
1
1
  import { type UseMutationResult, useMutation } from "@tanstack/react-query";
2
+ import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js";
2
3
  import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js";
3
4
  import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
4
5
  import type { TransactionReceipt } from "../../../../transaction/types.js";
5
6
  import { useActiveAccount } from "../wallets/useActiveAccount.js";
6
7
 
8
+ /**
9
+ * Configuration for the `useSendTransaction` hook.
10
+ */
11
+ export type SendAndConfirmTransactionConfig = {
12
+ /**
13
+ * Configuration for gasless transactions.
14
+ * Refer to [`GaslessOptions`](https://portal.thirdweb.com/references/typescript/v5/GaslessOptions) for more details.
15
+ */
16
+ gasless?: GaslessOptions;
17
+ };
18
+
7
19
  /**
8
20
  * A hook to send a transaction.
9
21
  * @returns A mutation object to send a transaction.
@@ -15,14 +27,26 @@ import { useActiveAccount } from "../wallets/useActiveAccount.js";
15
27
  * // later
16
28
  * sendAndConfirmTx(tx);
17
29
  * ```
30
+ *
31
+ *
32
+ * ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine)
33
+ * ```tsx
34
+ * import { useSendAndConfirmTransaction } from "thirdweb/react";
35
+ * const mutation = useSendAndConfirmTransaction({
36
+ * gasless: {
37
+ * provider: "engine",
38
+ * relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***",
39
+ * relayerForwarderAddress: "0x...",
40
+ * }
41
+ * });
42
+ * ```
18
43
  * @transaction
19
44
  */
20
- export function useSendAndConfirmTransaction(): UseMutationResult<
21
- TransactionReceipt,
22
- Error,
23
- PreparedTransaction
24
- > {
45
+ export function useSendAndConfirmTransaction(
46
+ config: SendAndConfirmTransactionConfig = {},
47
+ ): UseMutationResult<TransactionReceipt, Error, PreparedTransaction> {
25
48
  const account = useActiveAccount();
49
+ const { gasless } = config;
26
50
  return useMutation({
27
51
  mutationFn: async (transaction) => {
28
52
  if (!account) {
@@ -31,6 +55,7 @@ export function useSendAndConfirmTransaction(): UseMutationResult<
31
55
  return await sendAndConfirmTransaction({
32
56
  transaction,
33
57
  account,
58
+ gasless,
34
59
  });
35
60
  },
36
61
  });
@@ -19,6 +19,17 @@ import { useSwitchActiveWalletChain } from "../../../core/hooks/wallets/useSwitc
19
19
  * sendTx(tx);
20
20
  * ```
21
21
  *
22
+ * ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine)
23
+ * ```tsx
24
+ * import { useSendTransaction } from "thirdweb/react";
25
+ * const mutation = useSendTransaction({
26
+ * gasless: {
27
+ * provider: "engine",
28
+ * relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***",
29
+ * relayerForwarderAddress: "0x...",
30
+ * }
31
+ * });
32
+ * ```
22
33
  * @transaction
23
34
  */
24
35
  export function useSendTransaction(config: SendTransactionConfig = {}) {
@@ -214,6 +214,7 @@ export const ConnectedWalletDetails: React.FC<{
214
214
  border: `1px solid ${theme.colors.borderColor}`,
215
215
  textOverflow: "ellipsis",
216
216
  width: "115px",
217
+ height: "50px",
217
218
  whiteSpace: "nowrap",
218
219
  borderRadius: `0 ${radius.md} ${radius.md} 0`,
219
220
  }}
@@ -15,6 +15,8 @@ import { Button } from "../components/buttons.js";
15
15
  * @param props - The props for this component.
16
16
  * Refer to [TransactionButtonProps](https://portal.thirdweb.com/references/typescript/v5/TransactionButtonProps) for details.
17
17
  * @example
18
+ *
19
+ * ### Basic usage
18
20
  * ```tsx
19
21
  * <TransactionButton
20
22
  * transaction={() => {}}
@@ -24,7 +26,8 @@ import { Button } from "../components/buttons.js";
24
26
  * Confirm Transaction
25
27
  * </TransactionButton>
26
28
  * ```
27
- * Customize the styling by passing the `unstyled` prop and your inline styles and/or classes:
29
+ *
30
+ * ### Customize the styling by passing the `unstyled` prop and your inline styles and/or classes:
28
31
  * ```tsx
29
32
  * <TransactionButton
30
33
  * transaction={() => {}}
@@ -35,7 +38,7 @@ import { Button } from "../components/buttons.js";
35
38
  * </TransactionButton>
36
39
  * ```
37
40
  *
38
- * Handle errors
41
+ * ### Handle errors
39
42
  * ```tsx
40
43
  * <TransactionButton
41
44
  * transaction={() => ...}
@@ -48,7 +51,7 @@ import { Button } from "../components/buttons.js";
48
51
  * </TransactionButton>
49
52
  * ```
50
53
  *
51
- * Alert when a transaction is sent
54
+ * ### Alert when a transaction is sent
52
55
  * ```tsx
53
56
  * <TransactionButton
54
57
  * transaction={() => ...}
@@ -61,7 +64,7 @@ import { Button } from "../components/buttons.js";
61
64
  * </TransactionButton>
62
65
  * ```
63
66
  *
64
- * Alert when a transaction is completed
67
+ * ### Alert when a transaction is completed
65
68
  * ```tsx
66
69
  * <TransactionButton
67
70
  * transaction={() => ...}
@@ -75,7 +78,7 @@ import { Button } from "../components/buttons.js";
75
78
  * </TransactionButton>
76
79
  * ```
77
80
  *
78
- * The onClick prop, if provided, will be called before the transaction is sent.
81
+ * ### The onClick prop, if provided, will be called before the transaction is sent.
79
82
  * ```tsx
80
83
  * <TransactionButton
81
84
  * onClick={() => alert("Transaction is about to be sent")}
@@ -85,7 +88,7 @@ import { Button } from "../components/buttons.js";
85
88
  * </TransactionButton>
86
89
  * ```
87
90
  *
88
- * Attach custom Pay metadata
91
+ * ### Attach custom Pay metadata
89
92
  * ```tsx
90
93
  * <TransactionButton
91
94
  * payModal={{
@@ -99,6 +102,19 @@ import { Button } from "../components/buttons.js";
99
102
  * ...
100
103
  * </TransactionButton>
101
104
  * ```
105
+ *
106
+ * ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine)
107
+ * ```tsx
108
+ * <TransactionButton
109
+ * gasless={{
110
+ * provider: "engine",
111
+ * relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***",
112
+ * relayerForwarderAddress: "0x...",
113
+ * }}
114
+ * >
115
+ * ...
116
+ * </TransactionButton>
117
+ * ```
102
118
  * @component
103
119
  */
104
120
  export function TransactionButton(props: TransactionButtonProps) {
@@ -12,6 +12,8 @@ import { waitForReceipt } from "./wait-for-tx-receipt.js";
12
12
  * @throws An error if the wallet is not connected.
13
13
  * @transaction
14
14
  * @example
15
+ *
16
+ * ### Basic usage
15
17
  * ```ts
16
18
  * import { sendAndConfirmTransaction } from "thirdweb";
17
19
  *
@@ -20,6 +22,19 @@ import { waitForReceipt } from "./wait-for-tx-receipt.js";
20
22
  * transaction
21
23
  * });
22
24
  * ```
25
+ *
26
+ * ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine)
27
+ * ```ts
28
+ * const transactionReceipt = await sendAndConfirmTransaction({
29
+ * account,
30
+ * transaction,
31
+ * gasless: {
32
+ * provider: "engine",
33
+ * relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***",
34
+ * relayerForwarderAddress: "0x...",
35
+ * }
36
+ * });
37
+ * ```
23
38
  */
24
39
  export async function sendAndConfirmTransaction(
25
40
  options: SendTransactionOptions,
@@ -99,6 +99,19 @@ export type SendTransactionOptions = {
99
99
  * transaction,
100
100
  * });
101
101
  * ```
102
+ *
103
+ * ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine)
104
+ * ```ts
105
+ * const { transactionHash } = await sendTransaction({
106
+ * account,
107
+ * transaction,
108
+ * gasless: {
109
+ * provider: "engine",
110
+ * relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***",
111
+ * relayerForwarderAddress: "0x...",
112
+ * }
113
+ * });
114
+ * ```
102
115
  */
103
116
  export async function sendTransaction(
104
117
  options: SendTransactionOptions,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.47.0-nightly-f0d6e343eea28cd49863ba4794b89d6b070c52b2-20240818000714";
1
+ export const version = "5.47.1-nightly-574ff0295dcbb39f2ddd753c9e8a264498aae99e-20240819000344";