Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-steaks-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Allow passing overrides to common extension functions
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
TableRow,
} from "../ui/table";

const url = `http://${process.env.NEXT_PUBLIC_API_URL}`;
const url = `https://${process.env.NEXT_PUBLIC_API_URL}`;

const chain = baseSepolia;
const editionDropAddress = "0x638263e3eAa3917a53630e61B1fBa685308024fa";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../transaction/types.js";
import { getClaimParams } from "../../../../utils/extensions/drops/get-claim-params.js";
import { isGetContractMetadataSupported } from "../../../common/read/getContractMetadata.js";
import * as GeneratedClaim from "../../__generated__/IDrop1155/write/claim.js";
Expand Down Expand Up @@ -51,7 +54,9 @@ export type ClaimToParams = {
* @throws If no claim condition is set
* @returns The prepared transaction
*/
export function claimTo(options: BaseTransactionOptions<ClaimToParams>) {
export function claimTo(
options: BaseTransactionOptions<WithOverrides<ClaimToParams>>,
) {
return GeneratedClaim.claim({
async asyncParams() {
const params = await getClaimParams({
Expand All @@ -70,6 +75,7 @@ export function claimTo(options: BaseTransactionOptions<ClaimToParams>) {
};
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Hex } from "viem";
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../transaction/types.js";
import type { ClaimCondition } from "../../../../utils/extensions/drops/types.js";
import {
isSetClaimConditionsSupported,
Expand Down Expand Up @@ -40,7 +43,9 @@ export type ResetClaimEligibilityParams = GetClaimConditionsParams;
* ```
*/
export function resetClaimEligibility(
options: BaseTransactionOptions<ResetClaimEligibilityParams> & {
options: BaseTransactionOptions<
WithOverrides<ResetClaimEligibilityParams>
> & {
singlePhaseDrop?: boolean;
},
) {
Expand Down Expand Up @@ -79,6 +84,7 @@ export function resetClaimEligibility(
};
},
contract: options.contract,
overrides: options.overrides,
});
}
// download existing conditions
Expand All @@ -101,6 +107,7 @@ export function resetClaimEligibility(
};
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../transaction/types.js";
import { getMulticallSetClaimConditionTransactions } from "../../../../utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js";
import type { ClaimConditionsInput } from "../../../../utils/extensions/drops/types.js";
import { isSetContractURISupported } from "../../../common/__generated__/IContractMetadata/write/setContractURI.js";
Expand Down Expand Up @@ -49,7 +52,7 @@ export type SetClaimConditionsParams = {
* ```
*/
export function setClaimConditions(
options: BaseTransactionOptions<SetClaimConditionsParams>,
options: BaseTransactionOptions<WithOverrides<SetClaimConditionsParams>>,
) {
return multicall({
asyncParams: async () => {
Expand All @@ -65,6 +68,7 @@ export function setClaimConditions(
};
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../transaction/types.js";
import type { NFT, NFTInput } from "../../../../utils/nft/parseNft.js";
import * as BaseURICount from "../../../erc721/__generated__/IBatchMintMetadata/read/getBaseURICount.js";
import * as BatchAtIndex from "../../__generated__/BatchMintMetadata/read/getBatchIdAtIndex.js";
Expand Down Expand Up @@ -116,12 +119,13 @@ async function getUpdateMetadataParams(
* ```
*/
export function updateMetadata(
options: BaseTransactionOptions<UpdateMetadataParams>,
options: BaseTransactionOptions<WithOverrides<UpdateMetadataParams>>,
) {
const { contract } = options;
return BatchBaseURI.updateBatchBaseURI({
asyncParams: async () => getUpdateMetadataParams(options),
contract,
overrides: options.overrides,
});
}

Expand Down
10 changes: 7 additions & 3 deletions packages/thirdweb/src/extensions/erc1155/write/lazyMint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { FileOrBufferOrString } from "../../../storage/upload/types.js";
import type { BaseTransactionOptions } from "../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../transaction/types.js";
import {
getBaseUriFromBatch,
uploadOrExtractURIs,
Expand Down Expand Up @@ -31,9 +34,9 @@ type NFTInput = Prettify<
/**
* @extension ERC1155
*/
export type LazyMintParams = {
export type LazyMintParams = WithOverrides<{
nfts: (NFTInput | string)[];
};
}>;

/**
* Lazily mints ERC1155 tokens.
Expand Down Expand Up @@ -83,6 +86,7 @@ export function lazyMint(options: BaseTransactionOptions<LazyMintParams>) {
} as const;
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import type { BaseTransactionOptions } from "../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../transaction/types.js";
import * as URI from "../__generated__/IERC1155/read/uri.js";
import * as MintTo from "../__generated__/IMintableERC1155/write/mintTo.js";

/**
* @extension ERC1155
*/
export type MintAdditionalSupplyToParams = {
export type MintAdditionalSupplyToParams = WithOverrides<{
to: string;
tokenId: bigint;
supply: bigint;
};
}>;

/**
* Mints a "supply" number of additional ERC1155 tokens to the specified "to" address.
Expand Down Expand Up @@ -46,6 +49,7 @@ export function mintAdditionalSupplyTo(
};
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { upload } from "../../../storage/upload.js";
import type { BaseTransactionOptions } from "../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../transaction/types.js";
import type { NFTInput } from "../../../utils/nft/parseNft.js";
import {
type SetTokenURIParams,
Expand All @@ -10,10 +13,10 @@ export { isSetTokenURISupported as isUpdateTokenURISupported } from "../../erc11
/**
* @extension ERC1155
*/
export type UpdateTokenURIParams = {
export type UpdateTokenURIParams = WithOverrides<{
tokenId: bigint;
newMetadata: NFTInput;
};
}>;

/**
* This function is an abstracted layer of the [`setTokenURI` extension](https://portal.thirdweb.com/references/typescript/v5/erc1155/setTokenURI),
Expand Down Expand Up @@ -47,6 +50,7 @@ export function updateTokenURI(
return setTokenURI({
asyncParams: async () => getUpdateTokenParams(options),
contract,
overrides: options.overrides,
});
}

Expand Down
10 changes: 8 additions & 2 deletions packages/thirdweb/src/extensions/erc20/drops/write/claimTo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Address } from "abitype";
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../transaction/types.js";
import { getClaimParams } from "../../../../utils/extensions/drops/get-claim-params.js";
import { isGetContractMetadataSupported } from "../../../common/read/getContractMetadata.js";
import * as GeneratedClaim from "../../__generated__/IDropERC20/write/claim.js";
Expand Down Expand Up @@ -51,7 +54,9 @@ export type ClaimToParams = {
* @throws If no claim condition is set
* @returns A promise that resolves with the submitted transaction hash.
*/
export function claimTo(options: BaseTransactionOptions<ClaimToParams>) {
export function claimTo(
options: BaseTransactionOptions<WithOverrides<ClaimToParams>>,
) {
return GeneratedClaim.claim({
asyncParams: async () => {
const quantity = await (async () => {
Expand All @@ -77,6 +82,7 @@ export function claimTo(options: BaseTransactionOptions<ClaimToParams>) {
});
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Hex } from "viem";
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../transaction/types.js";
import type { ClaimCondition } from "../../../../utils/extensions/drops/types.js";
import {
isSetClaimConditionsSupported,
Expand Down Expand Up @@ -28,7 +31,9 @@ import {
* await sendTransaction({ transaction, account });
* ```
*/
export function resetClaimEligibility(options: BaseTransactionOptions) {
export function resetClaimEligibility(
options: BaseTransactionOptions<WithOverrides<{}>>,
) {
// download existing conditions
return setClaimConditions({
asyncParams: async () => {
Expand All @@ -48,6 +53,7 @@ export function resetClaimEligibility(options: BaseTransactionOptions) {
};
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { BaseTransactionOptions } from "../../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../../transaction/types.js";
import { getMulticallSetClaimConditionTransactions } from "../../../../utils/extensions/drops/get-multicall-set-claim-claim-conditon-transactions.js";
import type { ClaimConditionsInput } from "../../../../utils/extensions/drops/types.js";
import { isSetContractURISupported } from "../../../common/__generated__/IContractMetadata/write/setContractURI.js";
Expand Down Expand Up @@ -47,7 +50,7 @@ export type SetClaimConditionsParams = {
* ```
*/
export function setClaimConditions(
options: BaseTransactionOptions<SetClaimConditionsParams>,
options: BaseTransactionOptions<WithOverrides<SetClaimConditionsParams>>,
) {
return multicall({
asyncParams: async () => {
Expand All @@ -62,6 +65,7 @@ export function setClaimConditions(
};
},
contract: options.contract,
overrides: options.overrides,
});
}

Expand Down
24 changes: 15 additions & 9 deletions packages/thirdweb/src/extensions/erc20/write/approve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Address } from "abitype";
import type { BaseTransactionOptions } from "../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../transaction/types.js";
import type { Prettify } from "../../../utils/type-utils.js";
import { toUnits } from "../../../utils/units.js";
import { approve as generatedApprove } from "../__generated__/IERC20/write/approve.js";
Expand All @@ -9,14 +12,16 @@ import { approve as generatedApprove } from "../__generated__/IERC20/write/appro
* @extension ERC20
*/
export type ApproveParams = Prettify<
{ spender: Address } & (
| {
amount: number | string;
}
| {
amountWei: bigint;
}
)
WithOverrides<
{ spender: Address } & (
| {
amount: number | string;
}
| {
amountWei: bigint;
}
)
>
>;

/**
Expand Down Expand Up @@ -58,6 +63,7 @@ export function approve(options: BaseTransactionOptions<ApproveParams>) {
amountWei: amount,
tokenAddress: options.contract.address,
},
...options.overrides,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object spread syntax error will cause runtime failure. The line ...options.overrides, is spreading options.overrides directly into the asyncParams object, but overrides should be spread at the transaction level, not inside the async parameters. This will either cause a TypeError if overrides is undefined, or incorrectly merge override properties into the async params object instead of the transaction options. The fix is to move this spread outside the asyncParams object to the same level as contract and spender.

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

},
spender: options.spender,
value: amount,
Expand Down
11 changes: 8 additions & 3 deletions packages/thirdweb/src/extensions/erc20/write/deposit.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { prepareContractCall } from "../../../transaction/prepare-contract-call.js";
import type { BaseTransactionOptions } from "../../../transaction/types.js";
import type {
BaseTransactionOptions,
WithOverrides,
} from "../../../transaction/types.js";
import { toWei } from "../../../utils/units.js";
import { FN_SELECTOR } from "../__generated__/IWETH/write/deposit.js";

/**
* @extension ERC20
*/
export type DepositParams =
export type DepositParams = WithOverrides<
| {
amount: string;
}
| { amountWei: bigint };
| { amountWei: bigint }
>;

/**
* Calls the "deposit" function on the contract (useful to wrap ETH).
Expand Down Expand Up @@ -38,5 +42,6 @@
},
method: [FN_SELECTOR, [], []] as const,
value,
...options.overrides,

Check warning on line 45 in packages/thirdweb/src/extensions/erc20/write/deposit.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc20/write/deposit.ts#L45

Added line #L45 was not covered by tests
});
}
Loading
Loading