Skip to content

Properly type purchaseData as Record<string, unknown> #7508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
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/orange-files-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

properly type purchaseData
5 changes: 3 additions & 2 deletions packages/thirdweb/src/bridge/Buy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Address as ox__Address } from "ox";
import { defineChain } from "../chains/utils.js";
import type { ThirdwebClient } from "../client/client.js";
import type { PurchaseData } from "../pay/types.js";
import { getThirdwebBaseUrl } from "../utils/domains.js";
import { getClientFetch } from "../utils/fetch.js";
import { stringify } from "../utils/json.js";
Expand Down Expand Up @@ -413,7 +414,7 @@ export declare namespace prepare {
receiver: ox__Address.Address;
amount: bigint;
client: ThirdwebClient;
purchaseData?: unknown;
purchaseData?: PurchaseData;
maxSteps?: number;
/**
* @hidden
Expand All @@ -430,7 +431,7 @@ export declare namespace prepare {
amount: bigint;
sender: ox__Address.Address;
receiver: ox__Address.Address;
purchaseData?: unknown;
purchaseData?: PurchaseData;
};
};
}
7 changes: 4 additions & 3 deletions packages/thirdweb/src/bridge/Onramp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Address as ox__Address } from "ox";
import { defineChain } from "../chains/utils.js";
import type { ThirdwebClient } from "../client/client.js";
import type { PurchaseData } from "../pay/types.js";
import { getThirdwebBaseUrl } from "../utils/domains.js";
import { getClientFetch } from "../utils/fetch.js";
import { stringify } from "../utils/json.js";
Expand All @@ -17,7 +18,7 @@ type OnrampIntent = {
tokenAddress: ox__Address.Address;
receiver: ox__Address.Address;
amount?: string; // Corresponds to buyAmountWei in some other contexts
purchaseData?: unknown;
purchaseData?: PurchaseData;
sender?: ox__Address.Address;
onrampTokenAddress?: ox__Address.Address;
onrampChainId?: number;
Expand Down Expand Up @@ -46,7 +47,7 @@ interface OnrampApiRequestBody {
tokenAddress: ox__Address.Address;
receiver: ox__Address.Address;
amount?: string;
purchaseData?: unknown;
purchaseData?: PurchaseData;
sender?: ox__Address.Address;
onrampTokenAddress?: ox__Address.Address;
onrampChainId?: number;
Expand Down Expand Up @@ -265,7 +266,7 @@ export declare namespace prepare {
tokenAddress: ox__Address.Address;
receiver: ox__Address.Address;
amount?: bigint;
purchaseData?: unknown;
purchaseData?: PurchaseData;
sender?: ox__Address.Address;
onrampTokenAddress?: ox__Address.Address;
onrampChainId?: number;
Expand Down
9 changes: 5 additions & 4 deletions packages/thirdweb/src/bridge/OnrampStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Hex as ox__Hex } from "ox";
import type { ThirdwebClient } from "../client/client.js";
import type { PurchaseData } from "../pay/types.js";
import { getThirdwebBaseUrl } from "../utils/domains.js";
import { getClientFetch } from "../utils/fetch.js";
import { ApiError } from "./types/Errors.js";
Expand Down Expand Up @@ -108,30 +109,30 @@ export declare namespace status {
chainId: number;
transactionHash: ox__Hex.Hex;
}>;
purchaseData?: unknown;
purchaseData?: PurchaseData;
}
| {
status: "PENDING";
transactions: Array<{
chainId: number;
transactionHash: ox__Hex.Hex;
}>;
purchaseData?: unknown;
purchaseData?: PurchaseData;
}
| {
status: "CREATED";
transactions: Array<{
chainId: number;
transactionHash: ox__Hex.Hex;
}>;
purchaseData?: unknown;
purchaseData?: PurchaseData;
}
| {
status: "FAILED";
transactions: Array<{
chainId: number;
transactionHash: ox__Hex.Hex;
}>;
purchaseData?: unknown;
purchaseData?: PurchaseData;
};
}
5 changes: 3 additions & 2 deletions packages/thirdweb/src/bridge/Sell.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Address as ox__Address } from "ox";
import { defineChain } from "../chains/utils.js";
import type { ThirdwebClient } from "../client/client.js";
import type { PurchaseData } from "../pay/types.js";
import { getThirdwebBaseUrl } from "../utils/domains.js";
import { getClientFetch } from "../utils/fetch.js";
import { stringify } from "../utils/json.js";
Expand Down Expand Up @@ -402,7 +403,7 @@ export declare namespace prepare {
sender: ox__Address.Address;
receiver: ox__Address.Address;
client: ThirdwebClient;
purchaseData?: unknown;
purchaseData?: PurchaseData;
maxSteps?: number;
/**
* @hidden
Expand All @@ -419,7 +420,7 @@ export declare namespace prepare {
amount: bigint;
sender: ox__Address.Address;
receiver: ox__Address.Address;
purchaseData?: unknown;
purchaseData?: PurchaseData;
};
};
}
5 changes: 3 additions & 2 deletions packages/thirdweb/src/bridge/Transfer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Address as ox__Address } from "ox";
import { defineChain } from "../chains/utils.js";
import type { ThirdwebClient } from "../client/client.js";
import type { PurchaseData } from "../pay/types.js";
import { getThirdwebBaseUrl } from "../utils/domains.js";
import { getClientFetch } from "../utils/fetch.js";
import { stringify } from "../utils/json.js";
Expand Down Expand Up @@ -258,7 +259,7 @@ export declare namespace prepare {
receiver: ox__Address.Address;
amount: bigint;
client: ThirdwebClient;
purchaseData?: unknown;
purchaseData?: PurchaseData;
feePayer?: "sender" | "receiver";
/**
* @hidden
Expand All @@ -273,7 +274,7 @@ export declare namespace prepare {
amount: bigint;
sender: ox__Address.Address;
receiver: ox__Address.Address;
purchaseData?: unknown;
purchaseData?: PurchaseData;
feePayer?: "sender" | "receiver";
};
};
Expand Down
7 changes: 4 additions & 3 deletions packages/thirdweb/src/bridge/types/Status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Address as ox__Address, Hex as ox__Hex } from "ox";
import type { PurchaseData } from "../../pay/types.js";
import type { Token } from "./Token.js";
export type Status =
| {
Expand All @@ -18,7 +19,7 @@ export type Status =
chainId: number;
transactionHash: ox__Hex.Hex;
}>;
purchaseData?: unknown;
purchaseData?: PurchaseData;
}
| {
status: "PENDING";
Expand All @@ -36,7 +37,7 @@ export type Status =
chainId: number;
transactionHash: ox__Hex.Hex;
}>;
purchaseData?: unknown;
purchaseData?: PurchaseData;
}
| {
status: "FAILED";
Expand All @@ -45,7 +46,7 @@ export type Status =
chainId: number;
transactionHash: ox__Hex.Hex;
}>;
purchaseData?: unknown;
purchaseData?: PurchaseData;
}
| {
status: "NOT_FOUND";
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
import { getContract } from "../../contract/contract.js";
import { decimals } from "../../extensions/erc20/read/decimals.js";
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
import type { PurchaseData } from "../types.js";
import type {
QuoteApprovalInfo,
QuotePaymentToken,
Expand Down Expand Up @@ -76,7 +77,7 @@ export type GetBuyWithCryptoQuoteParams = {
*
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
*/
purchaseData?: object;
purchaseData?: PurchaseData;

/**
* The maximum slippage in basis points (bps) allowed for the swap.
Expand Down
13 changes: 7 additions & 6 deletions packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { ThirdwebClient } from "../../client/client.js";
import type { Hex } from "../../utils/encoding/hex.js";
import { toTokens } from "../../utils/units.js";
import type { PurchaseData } from "../types.js";
import type {
PayOnChainTransactionDetails,
PayTokenInfo,
Expand Down Expand Up @@ -80,7 +81,7 @@
toAddress: string;
failureMessage?: string;
bridge?: string;
purchaseData?: object;
purchaseData?: PurchaseData;
};

export type ValidBuyWithCryptoStatus = Exclude<
Expand Down Expand Up @@ -162,7 +163,7 @@
originTokenAddress: result.originTokenAddress,
originTransaction,
paymentId: result.paymentId,
purchaseData: result.purchaseData as object | undefined,
purchaseData: result.purchaseData,

Check warning on line 166 in packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts#L166

Added line #L166 was not covered by tests
receiver: result.receiver,
sender: result.sender,
status: result.status,
Expand All @@ -178,7 +179,7 @@
originToken: result.originToken,
originTokenAddress: result.originTokenAddress,
paymentId: result.paymentId,
purchaseData: result.purchaseData as object | undefined,
purchaseData: result.purchaseData,

Check warning on line 182 in packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts#L182

Added line #L182 was not covered by tests
receiver: result.receiver,
sender: result.sender,
status: result.status,
Expand All @@ -202,7 +203,7 @@
originTokenAddress: "",
originTransaction,
paymentId: "",
purchaseData: result.purchaseData as object | undefined,
purchaseData: result.purchaseData,

Check warning on line 206 in packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts#L206

Added line #L206 was not covered by tests
receiver: "",
sender: "",
status: result.status,
Expand Down Expand Up @@ -230,7 +231,7 @@
originChainId: number;
destinationChainId: number;
status: Status["status"];
purchaseData?: object;
purchaseData?: PurchaseData;
sender: string;
receiver: string;
paymentId: string;
Expand Down Expand Up @@ -277,7 +278,7 @@
transactionHash: destinationTransaction?.transactionHash ?? "",
},
fromAddress: sender,
purchaseData: purchaseData as object | undefined, // TODO transfer type?
purchaseData: purchaseData,

Check warning on line 281 in packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts#L281

Added line #L281 was not covered by tests
quote: {
createdAt: new Date().toISOString(),
estimated: {
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
import { getContract } from "../../contract/contract.js";
import { decimals } from "../../extensions/erc20/read/decimals.js";
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
import type { PurchaseData } from "../types.js";
import type { QuoteApprovalInfo, QuotePaymentToken } from "./commonTypes.js";

/**
Expand Down Expand Up @@ -54,7 +55,7 @@ export type GetBuyWithCryptoTransferParams = {
*
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
*/
purchaseData?: object;
purchaseData?: PurchaseData;

/**
* For direct transfers, specify who will pay for the transfer fee. Can be "sender" or "receiver".
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/pay/buyWithFiat/getQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getContract } from "../../contract/contract.js";
import { decimals } from "../../extensions/erc20/read/decimals.js";
import type { CurrencyMeta } from "../../react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js";
import { toTokens, toUnits } from "../../utils/units.js";
import type { PurchaseData } from "../types.js";
import type { FiatProvider, PayTokenInfo } from "../utils/commonTypes.js";
/**
* Parameters for [`getBuyWithFiatQuote`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatQuote) function
Expand Down Expand Up @@ -80,7 +81,7 @@ export type GetBuyWithFiatQuoteParams = {
*
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
*/
purchaseData?: object;
purchaseData?: PurchaseData;

/**
* Optional parameter to onramp gas with the purchase
Expand Down
7 changes: 4 additions & 3 deletions packages/thirdweb/src/pay/buyWithFiat/getStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { status as onrampStatus } from "../../bridge/OnrampStatus.js";
import type { ThirdwebClient } from "../../client/client.js";
import type { PurchaseData } from "../types.js";
import type {
PayOnChainTransactionDetails,
PayTokenInfo,
Expand Down Expand Up @@ -109,7 +110,7 @@
/**
* Arbitrary data sent at the time of fetching the quote
*/
purchaseData?: object;
purchaseData?: PurchaseData;
};

/**
Expand Down Expand Up @@ -202,7 +203,7 @@
| "PENDING_PAYMENT"
| "PAYMENT_FAILED"
| "ON_RAMP_TRANSFER_COMPLETED";
purchaseData?: unknown;
purchaseData?: PurchaseData;
}): BuyWithFiatStatus {
const { intentId, status, purchaseData } = args;

Expand Down Expand Up @@ -253,7 +254,7 @@
const base: Exclude<BuyWithFiatStatus, { status: "NOT_FOUND" }> = {
fromAddress: "",
intentId,
purchaseData: purchaseData as object | undefined,
purchaseData,

Check warning on line 257 in packages/thirdweb/src/pay/buyWithFiat/getStatus.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/pay/buyWithFiat/getStatus.ts#L257

Added line #L257 was not covered by tests
quote,
status,
toAddress: "",
Expand Down
1 change: 1 addition & 0 deletions packages/thirdweb/src/pay/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type PurchaseData = Record<string, unknown>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js";
import type { PurchaseData } from "../../../../pay/types.js";
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
import type { AssetTabs } from "../../../../react/web/ui/ConnectWallet/screens/ViewAssets.js";
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
Expand Down Expand Up @@ -117,7 +118,7 @@ export type PayUIOptions = Prettify<
*
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
*/
purchaseData?: object;
purchaseData?: PurchaseData;

/**
* Callback to be called when the user successfully completes the purchase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as Bridge from "../../../../bridge/index.js";
import type { Chain } from "../../../../chains/types.js";
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
import type { PurchaseData } from "../../../../pay/types.js";
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js";
import { sendTransaction } from "../../../../transaction/actions/send-transaction.js";
Expand Down Expand Up @@ -65,7 +66,7 @@ export type SendTransactionPayModalConfig =
testMode?: boolean;
preferredProvider?: FiatProvider;
};
purchaseData?: object;
purchaseData?: PurchaseData;
/**
* Callback to be called when the user successfully completes the purchase.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useCallback, useMemo } from "react";
import type { Token } from "../../../../bridge/types/Token.js";
import type { ThirdwebClient } from "../../../../client/client.js";
import type { PurchaseData } from "../../../../pay/types.js";
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
import type { Address } from "../../../../utils/address.js";
import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
Expand Down Expand Up @@ -102,7 +103,7 @@ export interface BridgeOrchestratorProps {
/**
* Optional purchase data for the payment
*/
purchaseData: object | undefined;
purchaseData?: PurchaseData;

/**
* Optional payment link ID for the payment
Expand Down
Loading
Loading