Skip to content

Commit ca1fb84

Browse files
authored
Properly type purchaseData as Record<string, unknown> (#7508)
1 parent 087c29e commit ca1fb84

File tree

21 files changed

+63
-45
lines changed

21 files changed

+63
-45
lines changed

.changeset/orange-files-admire.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+
properly type purchaseData

packages/thirdweb/src/bridge/Buy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Address as ox__Address } from "ox";
22
import { defineChain } from "../chains/utils.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import type { PurchaseData } from "../pay/types.js";
45
import { getThirdwebBaseUrl } from "../utils/domains.js";
56
import { getClientFetch } from "../utils/fetch.js";
67
import { stringify } from "../utils/json.js";
@@ -413,7 +414,7 @@ export declare namespace prepare {
413414
receiver: ox__Address.Address;
414415
amount: bigint;
415416
client: ThirdwebClient;
416-
purchaseData?: unknown;
417+
purchaseData?: PurchaseData;
417418
maxSteps?: number;
418419
/**
419420
* @hidden
@@ -430,7 +431,7 @@ export declare namespace prepare {
430431
amount: bigint;
431432
sender: ox__Address.Address;
432433
receiver: ox__Address.Address;
433-
purchaseData?: unknown;
434+
purchaseData?: PurchaseData;
434435
};
435436
};
436437
}

packages/thirdweb/src/bridge/Onramp.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Address as ox__Address } from "ox";
22
import { defineChain } from "../chains/utils.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import type { PurchaseData } from "../pay/types.js";
45
import { getThirdwebBaseUrl } from "../utils/domains.js";
56
import { getClientFetch } from "../utils/fetch.js";
67
import { stringify } from "../utils/json.js";
@@ -17,7 +18,7 @@ type OnrampIntent = {
1718
tokenAddress: ox__Address.Address;
1819
receiver: ox__Address.Address;
1920
amount?: string; // Corresponds to buyAmountWei in some other contexts
20-
purchaseData?: unknown;
21+
purchaseData?: PurchaseData;
2122
sender?: ox__Address.Address;
2223
onrampTokenAddress?: ox__Address.Address;
2324
onrampChainId?: number;
@@ -46,7 +47,7 @@ interface OnrampApiRequestBody {
4647
tokenAddress: ox__Address.Address;
4748
receiver: ox__Address.Address;
4849
amount?: string;
49-
purchaseData?: unknown;
50+
purchaseData?: PurchaseData;
5051
sender?: ox__Address.Address;
5152
onrampTokenAddress?: ox__Address.Address;
5253
onrampChainId?: number;
@@ -265,7 +266,7 @@ export declare namespace prepare {
265266
tokenAddress: ox__Address.Address;
266267
receiver: ox__Address.Address;
267268
amount?: bigint;
268-
purchaseData?: unknown;
269+
purchaseData?: PurchaseData;
269270
sender?: ox__Address.Address;
270271
onrampTokenAddress?: ox__Address.Address;
271272
onrampChainId?: number;

packages/thirdweb/src/bridge/OnrampStatus.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Hex as ox__Hex } from "ox";
22
import type { ThirdwebClient } from "../client/client.js";
3+
import type { PurchaseData } from "../pay/types.js";
34
import { getThirdwebBaseUrl } from "../utils/domains.js";
45
import { getClientFetch } from "../utils/fetch.js";
56
import { ApiError } from "./types/Errors.js";
@@ -108,30 +109,30 @@ export declare namespace status {
108109
chainId: number;
109110
transactionHash: ox__Hex.Hex;
110111
}>;
111-
purchaseData?: unknown;
112+
purchaseData?: PurchaseData;
112113
}
113114
| {
114115
status: "PENDING";
115116
transactions: Array<{
116117
chainId: number;
117118
transactionHash: ox__Hex.Hex;
118119
}>;
119-
purchaseData?: unknown;
120+
purchaseData?: PurchaseData;
120121
}
121122
| {
122123
status: "CREATED";
123124
transactions: Array<{
124125
chainId: number;
125126
transactionHash: ox__Hex.Hex;
126127
}>;
127-
purchaseData?: unknown;
128+
purchaseData?: PurchaseData;
128129
}
129130
| {
130131
status: "FAILED";
131132
transactions: Array<{
132133
chainId: number;
133134
transactionHash: ox__Hex.Hex;
134135
}>;
135-
purchaseData?: unknown;
136+
purchaseData?: PurchaseData;
136137
};
137138
}

packages/thirdweb/src/bridge/Sell.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Address as ox__Address } from "ox";
22
import { defineChain } from "../chains/utils.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import type { PurchaseData } from "../pay/types.js";
45
import { getThirdwebBaseUrl } from "../utils/domains.js";
56
import { getClientFetch } from "../utils/fetch.js";
67
import { stringify } from "../utils/json.js";
@@ -402,7 +403,7 @@ export declare namespace prepare {
402403
sender: ox__Address.Address;
403404
receiver: ox__Address.Address;
404405
client: ThirdwebClient;
405-
purchaseData?: unknown;
406+
purchaseData?: PurchaseData;
406407
maxSteps?: number;
407408
/**
408409
* @hidden
@@ -419,7 +420,7 @@ export declare namespace prepare {
419420
amount: bigint;
420421
sender: ox__Address.Address;
421422
receiver: ox__Address.Address;
422-
purchaseData?: unknown;
423+
purchaseData?: PurchaseData;
423424
};
424425
};
425426
}

packages/thirdweb/src/bridge/Transfer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Address as ox__Address } from "ox";
22
import { defineChain } from "../chains/utils.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import type { PurchaseData } from "../pay/types.js";
45
import { getThirdwebBaseUrl } from "../utils/domains.js";
56
import { getClientFetch } from "../utils/fetch.js";
67
import { stringify } from "../utils/json.js";
@@ -258,7 +259,7 @@ export declare namespace prepare {
258259
receiver: ox__Address.Address;
259260
amount: bigint;
260261
client: ThirdwebClient;
261-
purchaseData?: unknown;
262+
purchaseData?: PurchaseData;
262263
feePayer?: "sender" | "receiver";
263264
/**
264265
* @hidden
@@ -273,7 +274,7 @@ export declare namespace prepare {
273274
amount: bigint;
274275
sender: ox__Address.Address;
275276
receiver: ox__Address.Address;
276-
purchaseData?: unknown;
277+
purchaseData?: PurchaseData;
277278
feePayer?: "sender" | "receiver";
278279
};
279280
};

packages/thirdweb/src/bridge/types/Status.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Address as ox__Address, Hex as ox__Hex } from "ox";
2+
import type { PurchaseData } from "../../pay/types.js";
23
import type { Token } from "./Token.js";
34
export type Status =
45
| {
@@ -18,7 +19,7 @@ export type Status =
1819
chainId: number;
1920
transactionHash: ox__Hex.Hex;
2021
}>;
21-
purchaseData?: unknown;
22+
purchaseData?: PurchaseData;
2223
}
2324
| {
2425
status: "PENDING";
@@ -36,7 +37,7 @@ export type Status =
3637
chainId: number;
3738
transactionHash: ox__Hex.Hex;
3839
}>;
39-
purchaseData?: unknown;
40+
purchaseData?: PurchaseData;
4041
}
4142
| {
4243
status: "FAILED";
@@ -45,7 +46,7 @@ export type Status =
4546
chainId: number;
4647
transactionHash: ox__Hex.Hex;
4748
}>;
48-
purchaseData?: unknown;
49+
purchaseData?: PurchaseData;
4950
}
5051
| {
5152
status: "NOT_FOUND";

packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
77
import { getContract } from "../../contract/contract.js";
88
import { decimals } from "../../extensions/erc20/read/decimals.js";
99
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
10+
import type { PurchaseData } from "../types.js";
1011
import type {
1112
QuoteApprovalInfo,
1213
QuotePaymentToken,
@@ -76,7 +77,7 @@ export type GetBuyWithCryptoQuoteParams = {
7677
*
7778
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
7879
*/
79-
purchaseData?: object;
80+
purchaseData?: PurchaseData;
8081

8182
/**
8283
* The maximum slippage in basis points (bps) allowed for the swap.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Token } from "../../bridge/types/Token.js";
33
import type { ThirdwebClient } from "../../client/client.js";
44
import type { Hex } from "../../utils/encoding/hex.js";
55
import { toTokens } from "../../utils/units.js";
6+
import type { PurchaseData } from "../types.js";
67
import type {
78
PayOnChainTransactionDetails,
89
PayTokenInfo,
@@ -80,7 +81,7 @@ export type BuyWithCryptoStatus =
8081
toAddress: string;
8182
failureMessage?: string;
8283
bridge?: string;
83-
purchaseData?: object;
84+
purchaseData?: PurchaseData;
8485
};
8586

8687
export type ValidBuyWithCryptoStatus = Exclude<
@@ -162,7 +163,7 @@ export async function getBuyWithCryptoStatus(
162163
originTokenAddress: result.originTokenAddress,
163164
originTransaction,
164165
paymentId: result.paymentId,
165-
purchaseData: result.purchaseData as object | undefined,
166+
purchaseData: result.purchaseData,
166167
receiver: result.receiver,
167168
sender: result.sender,
168169
status: result.status,
@@ -178,7 +179,7 @@ export async function getBuyWithCryptoStatus(
178179
originToken: result.originToken,
179180
originTokenAddress: result.originTokenAddress,
180181
paymentId: result.paymentId,
181-
purchaseData: result.purchaseData as object | undefined,
182+
purchaseData: result.purchaseData,
182183
receiver: result.receiver,
183184
sender: result.sender,
184185
status: result.status,
@@ -202,7 +203,7 @@ export async function getBuyWithCryptoStatus(
202203
originTokenAddress: "",
203204
originTransaction,
204205
paymentId: "",
205-
purchaseData: result.purchaseData as object | undefined,
206+
purchaseData: result.purchaseData,
206207
receiver: "",
207208
sender: "",
208209
status: result.status,
@@ -230,7 +231,7 @@ function toBuyWithCryptoStatus(args: {
230231
originChainId: number;
231232
destinationChainId: number;
232233
status: Status["status"];
233-
purchaseData?: object;
234+
purchaseData?: PurchaseData;
234235
sender: string;
235236
receiver: string;
236237
paymentId: string;
@@ -277,7 +278,7 @@ function toBuyWithCryptoStatus(args: {
277278
transactionHash: destinationTransaction?.transactionHash ?? "",
278279
},
279280
fromAddress: sender,
280-
purchaseData: purchaseData as object | undefined, // TODO transfer type?
281+
purchaseData: purchaseData,
281282
quote: {
282283
createdAt: new Date().toISOString(),
283284
estimated: {

packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
77
import { getContract } from "../../contract/contract.js";
88
import { decimals } from "../../extensions/erc20/read/decimals.js";
99
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
10+
import type { PurchaseData } from "../types.js";
1011
import type { QuoteApprovalInfo, QuotePaymentToken } from "./commonTypes.js";
1112

1213
/**
@@ -54,7 +55,7 @@ export type GetBuyWithCryptoTransferParams = {
5455
*
5556
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
5657
*/
57-
purchaseData?: object;
58+
purchaseData?: PurchaseData;
5859

5960
/**
6061
* For direct transfers, specify who will pay for the transfer fee. Can be "sender" or "receiver".

packages/thirdweb/src/pay/buyWithFiat/getQuote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getContract } from "../../contract/contract.js";
66
import { decimals } from "../../extensions/erc20/read/decimals.js";
77
import type { CurrencyMeta } from "../../react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js";
88
import { toTokens, toUnits } from "../../utils/units.js";
9+
import type { PurchaseData } from "../types.js";
910
import type { FiatProvider, PayTokenInfo } from "../utils/commonTypes.js";
1011
/**
1112
* Parameters for [`getBuyWithFiatQuote`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatQuote) function
@@ -80,7 +81,7 @@ export type GetBuyWithFiatQuoteParams = {
8081
*
8182
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
8283
*/
83-
purchaseData?: object;
84+
purchaseData?: PurchaseData;
8485

8586
/**
8687
* Optional parameter to onramp gas with the purchase

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { status as onrampStatus } from "../../bridge/OnrampStatus.js";
22
import type { ThirdwebClient } from "../../client/client.js";
3+
import type { PurchaseData } from "../types.js";
34
import type {
45
PayOnChainTransactionDetails,
56
PayTokenInfo,
@@ -109,7 +110,7 @@ export type BuyWithFiatStatus =
109110
/**
110111
* Arbitrary data sent at the time of fetching the quote
111112
*/
112-
purchaseData?: object;
113+
purchaseData?: PurchaseData;
113114
};
114115

115116
/**
@@ -202,7 +203,7 @@ function buildPlaceholderStatus(args: {
202203
| "PENDING_PAYMENT"
203204
| "PAYMENT_FAILED"
204205
| "ON_RAMP_TRANSFER_COMPLETED";
205-
purchaseData?: unknown;
206+
purchaseData?: PurchaseData;
206207
}): BuyWithFiatStatus {
207208
const { intentId, status, purchaseData } = args;
208209

@@ -253,7 +254,7 @@ function buildPlaceholderStatus(args: {
253254
const base: Exclude<BuyWithFiatStatus, { status: "NOT_FOUND" }> = {
254255
fromAddress: "",
255256
intentId,
256-
purchaseData: purchaseData as object | undefined,
257+
purchaseData,
257258
quote,
258259
status,
259260
toAddress: "",

packages/thirdweb/src/pay/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type PurchaseData = Record<string, unknown>;

packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
44
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
55
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
66
import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js";
7+
import type { PurchaseData } from "../../../../pay/types.js";
78
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
89
import type { AssetTabs } from "../../../../react/web/ui/ConnectWallet/screens/ViewAssets.js";
910
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
@@ -117,7 +118,7 @@ export type PayUIOptions = Prettify<
117118
*
118119
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
119120
*/
120-
purchaseData?: object;
121+
purchaseData?: PurchaseData;
121122

122123
/**
123124
* Callback to be called when the user successfully completes the purchase.

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Bridge from "../../../../bridge/index.js";
66
import type { Chain } from "../../../../chains/types.js";
77
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
88
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
9+
import type { PurchaseData } from "../../../../pay/types.js";
910
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
1011
import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js";
1112
import { sendTransaction } from "../../../../transaction/actions/send-transaction.js";
@@ -65,7 +66,7 @@ export type SendTransactionPayModalConfig =
6566
testMode?: boolean;
6667
preferredProvider?: FiatProvider;
6768
};
68-
purchaseData?: object;
69+
purchaseData?: PurchaseData;
6970
/**
7071
* Callback to be called when the user successfully completes the purchase.
7172
*/

packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { useCallback, useMemo } from "react";
33
import type { Token } from "../../../../bridge/types/Token.js";
44
import type { ThirdwebClient } from "../../../../client/client.js";
5+
import type { PurchaseData } from "../../../../pay/types.js";
56
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
67
import type { Address } from "../../../../utils/address.js";
78
import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
@@ -102,7 +103,7 @@ export interface BridgeOrchestratorProps {
102103
/**
103104
* Optional purchase data for the payment
104105
*/
105-
purchaseData: object | undefined;
106+
purchaseData?: PurchaseData;
106107

107108
/**
108109
* Optional payment link ID for the payment

0 commit comments

Comments
 (0)