Skip to content

Commit 2aef50a

Browse files
authored
Merge branch 'main' into mintable-module
2 parents bd927ae + 686d0c3 commit 2aef50a

File tree

16 files changed

+158
-62
lines changed

16 files changed

+158
-62
lines changed

.changeset/early-shoes-applaud.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Respect custom bundler URL for getting gas fees + better DX for `predictSmartAccountAddress()`

.changeset/three-dancers-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Consolidate custom jwt and custom auth endpoint through common endpoint

apps/dashboard/src/components/settings/ApiKeys/validations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ export type ApiKeyPayConfigValidationSchema = z.infer<
149149
>;
150150

151151
// FIXME: Remove
152-
export const HIDDEN_SERVICES = ["relayer", "chainsaw", "insight"];
152+
export const HIDDEN_SERVICES = ["relayer", "chainsaw"];

apps/portal/src/app/typescript/v5/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const sidebar: SideBar = {
139139
},
140140
...[
141141
"smartWallet",
142-
"predictAddress",
142+
"predictSmartAccountAddress",
143143
"createAndSignUserOp",
144144
"createUnsignedUserOp",
145145
"signUserOp",

packages/thirdweb/src/exports/wallets/smart.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export {
1515
estimateUserOpGas,
1616
} from "../../wallets/smart/lib/bundler.js";
1717

18-
export { predictAddress } from "../../wallets/smart/lib/calls.js";
18+
export {
19+
predictAddress,
20+
predictSmartAccountAddress,
21+
} from "../../wallets/smart/lib/calls.js";
1922

2023
export { getPaymasterAndData } from "../../wallets/smart/lib/paymaster.js";
2124

packages/thirdweb/src/transaction/prepare-contract-call.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ export type PrepareContractCallOptions<
9292
* });
9393
* ```
9494
*
95+
* ### Usage with ERC20 value:
96+
*
97+
* For transactions that transfer ERC20 tokens, you can specify the value as the amount of tokens to transfer.
98+
*
99+
* You can use this in conjuction with the [`getApprovalForTransaction`](https://portal.thirdweb.com/references/typescript/v5/getApprovalForTransaction) function to easily create approval transactions for ERC20 tokens.
100+
*
101+
* This value will also be read by the react hooks and UI components to present to total cost to the user.
102+
*
103+
* ```ts
104+
* import { prepareContractCall } from "thirdweb";
105+
* import { toWei } from "thirdweb/utils";
106+
*
107+
* const transaction = prepareContractCall({
108+
* contract,
109+
* method: "function payWithCoin()",
110+
* params: [],
111+
* erc20Value: {
112+
* tokenAddress: "0x...", // the address of the ERC20 token
113+
* amountWei: toWei("0.1"), // the amount of tokens to transfer in wei
114+
* },
115+
* });
116+
* ```
117+
*
95118
* ### Usage with a JSON ABI function object:
96119
*
97120
* ```ts

packages/thirdweb/src/wallets/in-app/core/authentication/authEndpoint.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
import type { ThirdwebClient } from "../../../../client/client.js";
2-
import { getSessionHeaders } from "../../native/helpers/api/fetchers.js";
2+
import { getClientFetch } from "../../../../utils/fetch.js";
33
import { ROUTE_AUTH_ENDPOINT_CALLBACK } from "../../native/helpers/constants.js";
44
import { createErrorMessage } from "../../native/helpers/errors.js";
5-
import type { ClientScopedStorage } from "./client-scoped-storage.js";
5+
import type { Ecosystem } from "../wallet/types.js";
66
import type { AuthStoredTokenWithCookieReturnType } from "./types.js";
77

88
export async function authEndpoint(args: {
99
payload: string;
1010
client: ThirdwebClient;
11-
storage: ClientScopedStorage;
11+
ecosystem?: Ecosystem;
1212
}): Promise<AuthStoredTokenWithCookieReturnType> {
13-
const resp = await fetch(ROUTE_AUTH_ENDPOINT_CALLBACK, {
13+
const clientFetch = getClientFetch(args.client, args.ecosystem);
14+
15+
const res = await clientFetch(ROUTE_AUTH_ENDPOINT_CALLBACK, {
1416
method: "POST",
1517
headers: {
16-
...getSessionHeaders(),
18+
"Content-Type": "application/json",
1719
},
1820
body: JSON.stringify({
1921
payload: args.payload,
2022
developerClientId: args.client.clientId,
2123
}),
2224
});
23-
if (!resp.ok) {
24-
const error = await resp.json();
25+
26+
if (!res.ok) {
27+
const error = await res.json();
2528
throw new Error(
2629
`Custom auth endpoint authentication error: ${error.message}`,
2730
);
2831
}
2932

3033
try {
31-
const { verifiedToken } = await resp.json();
34+
const { verifiedToken } = await res.json();
3235

3336
return { storedToken: verifiedToken };
3437
} catch (e) {

packages/thirdweb/src/wallets/in-app/core/authentication/guest.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,22 @@ export async function guestAuthenticate(args: {
2929
}
3030

3131
const clientFetch = getClientFetch(args.client, args.ecosystem);
32-
const authResult = await (async () => {
33-
const path = getLoginCallbackUrl({
34-
authOption: "guest",
35-
client: args.client,
36-
ecosystem: args.ecosystem,
37-
});
38-
const res = await clientFetch(`${path}`, {
39-
method: "POST",
40-
headers: {
41-
"Content-Type": "application/json",
42-
},
43-
body: JSON.stringify({
44-
sessionId,
45-
}),
46-
});
32+
const path = getLoginCallbackUrl({
33+
authOption: "guest",
34+
client: args.client,
35+
ecosystem: args.ecosystem,
36+
});
37+
const res = await clientFetch(`${path}`, {
38+
method: "POST",
39+
headers: {
40+
"Content-Type": "application/json",
41+
},
42+
body: JSON.stringify({
43+
sessionId,
44+
}),
45+
});
4746

48-
if (!res.ok) throw new Error("Failed to generate guest account");
47+
if (!res.ok) throw new Error("Failed to generate guest account");
4948

50-
return (await res.json()) satisfies AuthStoredTokenWithCookieReturnType;
51-
})();
52-
return authResult;
49+
return (await res.json()) satisfies AuthStoredTokenWithCookieReturnType;
5350
}

packages/thirdweb/src/wallets/in-app/core/authentication/jwt.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
import type { ThirdwebClient } from "../../../../client/client.js";
2-
import { getSessionHeaders } from "../../native/helpers/api/fetchers.js";
2+
import { getClientFetch } from "../../../../utils/fetch.js";
33
import { ROUTE_AUTH_JWT_CALLBACK } from "../../native/helpers/constants.js";
44
import { createErrorMessage } from "../../native/helpers/errors.js";
5-
import type { ClientScopedStorage } from "./client-scoped-storage.js";
5+
import type { Ecosystem } from "../wallet/types.js";
66
import type { AuthStoredTokenWithCookieReturnType } from "./types.js";
77

88
export async function customJwt(args: {
99
jwt: string;
1010
client: ThirdwebClient;
11-
storage: ClientScopedStorage;
11+
ecosystem?: Ecosystem;
1212
}): Promise<AuthStoredTokenWithCookieReturnType> {
13-
const resp = await fetch(ROUTE_AUTH_JWT_CALLBACK, {
13+
const clientFetch = getClientFetch(args.client, args.ecosystem);
14+
15+
const res = await clientFetch(ROUTE_AUTH_JWT_CALLBACK, {
1416
method: "POST",
1517
headers: {
16-
...getSessionHeaders(),
18+
"Content-Type": "application/json",
1719
},
1820
body: JSON.stringify({
1921
jwt: args.jwt,
2022
developerClientId: args.client.clientId,
2123
}),
2224
});
2325

24-
if (!resp.ok) {
25-
const error = await resp.json();
26+
if (!res.ok) {
27+
const error = await res.json();
2628
throw new Error(`JWT authentication error: ${error.message}`);
2729
}
2830

2931
try {
30-
const { verifiedToken } = await resp.json();
32+
const { verifiedToken } = await res.json();
33+
3134
return { storedToken: verifiedToken };
3235
} catch (e) {
3336
throw new Error(

packages/thirdweb/src/wallets/in-app/native/helpers/api/fetchers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ECOSYSTEM_PARTNER_ID_HEADER = "x-ecosystem-partner-id";
1919

2020
let sessionNonce: Hex | undefined = undefined;
2121

22-
export function getSessionHeaders() {
22+
function getSessionHeaders() {
2323
if (!sessionNonce) {
2424
sessionNonce = randomBytesHex(16);
2525
}

0 commit comments

Comments
 (0)