thirdweb 5.48.1 → 5.48.2
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.
- package/dist/cjs/exports/pay.js +3 -1
- package/dist/cjs/exports/pay.js.map +1 -1
- package/dist/cjs/exports/thirdweb.js +3 -1
- package/dist/cjs/exports/thirdweb.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/commonTypes.js +3 -0
- package/dist/cjs/pay/buyWithCrypto/commonTypes.js.map +1 -0
- package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js +95 -0
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -0
- package/dist/cjs/pay/utils/definitions.js +7 -1
- package/dist/cjs/pay/utils/definitions.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/ConnectedButton.js +5 -1
- package/dist/cjs/react/native/ui/connect/ConnectedButton.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/ConnectedModal.js +2 -1
- package/dist/cjs/react/native/ui/connect/ConnectedModal.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/TokenListScreen.js +5 -1
- package/dist/cjs/react/native/ui/connect/TokenListScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +28 -22
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js +9 -0
- package/dist/cjs/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js +9 -3
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +34 -2
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +8 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js +118 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js +7 -76
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/formatTokenBalance.js +2 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
- package/dist/cjs/stories/ConnectButton.stories.js +28 -0
- package/dist/cjs/stories/ConnectButton.stories.js.map +1 -0
- package/dist/cjs/stories/PayEmbed.stories.js +38 -0
- package/dist/cjs/stories/PayEmbed.stories.js.map +1 -0
- package/dist/cjs/stories/utils.js +27 -0
- package/dist/cjs/stories/utils.js.map +1 -0
- package/dist/cjs/transaction/actions/send-transaction.js.map +1 -1
- package/dist/cjs/utils/signatures/sign-message.js +13 -19
- package/dist/cjs/utils/signatures/sign-message.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js +4 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/exports/pay.js +2 -0
- package/dist/esm/exports/pay.js.map +1 -1
- package/dist/esm/exports/thirdweb.js +2 -0
- package/dist/esm/exports/thirdweb.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/commonTypes.js +2 -0
- package/dist/esm/pay/buyWithCrypto/commonTypes.js.map +1 -0
- package/dist/esm/pay/buyWithCrypto/getQuote.js +1 -1
- package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/getTransfer.js +92 -0
- package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -0
- package/dist/esm/pay/utils/definitions.js +5 -0
- package/dist/esm/pay/utils/definitions.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/native/ui/connect/ConnectedButton.js +5 -1
- package/dist/esm/react/native/ui/connect/ConnectedButton.js.map +1 -1
- package/dist/esm/react/native/ui/connect/ConnectedModal.js +2 -1
- package/dist/esm/react/native/ui/connect/ConnectedModal.js.map +1 -1
- package/dist/esm/react/native/ui/connect/TokenListScreen.js +5 -1
- package/dist/esm/react/native/ui/connect/TokenListScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +28 -22
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js +5 -0
- package/dist/esm/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +5 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js +8 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +35 -3
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +8 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js +115 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js +8 -77
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/formatTokenBalance.js +2 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
- package/dist/esm/stories/ConnectButton.stories.js +25 -0
- package/dist/esm/stories/ConnectButton.stories.js.map +1 -0
- package/dist/esm/stories/PayEmbed.stories.js +35 -0
- package/dist/esm/stories/PayEmbed.stories.js.map +1 -0
- package/dist/esm/stories/utils.js +24 -0
- package/dist/esm/stories/utils.js.map +1 -0
- package/dist/esm/transaction/actions/send-transaction.js.map +1 -1
- package/dist/esm/utils/signatures/sign-message.js +13 -19
- package/dist/esm/utils/signatures/sign-message.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js +4 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/types/exports/pay.d.ts +3 -1
- package/dist/types/exports/pay.d.ts.map +1 -1
- package/dist/types/exports/thirdweb.d.ts +3 -1
- package/dist/types/exports/thirdweb.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/commonTypes.d.ts +36 -0
- package/dist/types/pay/buyWithCrypto/commonTypes.d.ts.map +1 -0
- package/dist/types/pay/buyWithCrypto/getQuote.d.ts +1 -24
- package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -1
- package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/getTransfer.d.ts +85 -0
- package/dist/types/pay/buyWithCrypto/getTransfer.d.ts.map +1 -0
- package/dist/types/pay/buyWithFiat/getQuote.d.ts +1 -1
- package/dist/types/pay/buyWithFiat/getQuote.d.ts.map +1 -1
- package/dist/types/pay/utils/definitions.d.ts +5 -0
- package/dist/types/pay/utils/definitions.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +15 -0
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +3 -0
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/ConnectedButton.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/ConnectedModal.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/TokenListScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +6 -0
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.d.ts +3 -0
- package/dist/types/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.d.ts +2 -2
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts +3 -2
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.d.ts +20 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.d.ts +5 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/formatTokenBalance.d.ts.map +1 -1
- package/dist/types/stories/ConnectButton.stories.d.ts +18 -0
- package/dist/types/stories/ConnectButton.stories.d.ts.map +1 -0
- package/dist/types/stories/PayEmbed.stories.d.ts +19 -0
- package/dist/types/stories/PayEmbed.stories.d.ts.map +1 -0
- package/dist/types/stories/utils.d.ts +5 -0
- package/dist/types/stories/utils.d.ts.map +1 -0
- package/dist/types/transaction/actions/send-transaction.d.ts +12 -2
- package/dist/types/transaction/actions/send-transaction.d.ts.map +1 -1
- package/dist/types/utils/signatures/sign-message.d.ts +26 -3
- package/dist/types/utils/signatures/sign-message.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/package.json +15 -2
- package/src/exports/pay.ts +11 -2
- package/src/exports/thirdweb.ts +11 -2
- package/src/pay/buyWithCrypto/commonTypes.ts +40 -0
- package/src/pay/buyWithCrypto/getQuote.ts +8 -42
- package/src/pay/buyWithCrypto/getStatus.ts +1 -1
- package/src/pay/buyWithCrypto/getTransfer.ts +185 -0
- package/src/pay/buyWithFiat/getQuote.ts +1 -1
- package/src/pay/utils/definitions.ts +7 -0
- package/src/react/core/hooks/connection/ConnectButtonProps.ts +16 -0
- package/src/react/core/hooks/transaction/useSendTransaction.ts +3 -0
- package/src/react/native/ui/connect/ConnectedButton.tsx +6 -1
- package/src/react/native/ui/connect/ConnectedModal.tsx +2 -1
- package/src/react/native/ui/connect/TokenListScreen.tsx +6 -1
- package/src/react/web/ui/ConnectWallet/Details.tsx +93 -77
- package/src/react/web/ui/ConnectWallet/icons/currencies/JPYIcon.tsx +21 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +8 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.tsx +9 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts +47 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx +26 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.tsx +3 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx +284 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferFlow.tsx +29 -220
- package/src/react/web/ui/ConnectWallet/screens/formatTokenBalance.ts +3 -1
- package/src/stories/ConnectButton.stories.ts +31 -0
- package/src/stories/PayEmbed.stories.ts +42 -0
- package/src/stories/utils.tsx +29 -0
- package/src/transaction/actions/send-transaction.ts +12 -3
- package/src/utils/signatures/sign-message.test.ts +78 -50
- package/src/utils/signatures/sign-message.ts +44 -9
- package/src/version.ts +1 -1
- package/src/wallets/in-app/core/wallet/index.ts +2 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
import type { Hash } from "viem";
|
2
|
+
import { getCachedChain } from "../../chains/utils.js";
|
3
|
+
import type { ThirdwebClient } from "../../client/client.js";
|
4
|
+
import { getContract } from "../../contract/contract.js";
|
5
|
+
import { approve } from "../../extensions/erc20/write/approve.js";
|
6
|
+
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
|
7
|
+
import type { Address } from "../../utils/address.js";
|
8
|
+
import { getClientFetch } from "../../utils/fetch.js";
|
9
|
+
import { getPayBuyWithCryptoTransferEndpoint } from "../utils/definitions.js";
|
10
|
+
import type {
|
11
|
+
QuoteApprovalInfo,
|
12
|
+
QuotePaymentToken,
|
13
|
+
QuoteTokenInfo,
|
14
|
+
QuoteTransactionRequest,
|
15
|
+
} from "./commonTypes.js";
|
16
|
+
|
17
|
+
/**
|
18
|
+
* The parameters for [`getBuyWithCryptoTransfer`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithCryptoTransfer) function
|
19
|
+
* It facilitates a token transfer.
|
20
|
+
* @buyCrypto
|
21
|
+
*/
|
22
|
+
export type GetBuyWithCryptoTransferParams = {
|
23
|
+
/**
|
24
|
+
* A client is the entry point to the thirdweb SDK. It is required for all other actions.
|
25
|
+
*
|
26
|
+
* You can create a client using the `createThirdwebClient` function.
|
27
|
+
* Refer to the [Creating a Client](https://portal.thirdweb.com/typescript/v5/client) documentation for more information.
|
28
|
+
*
|
29
|
+
*/
|
30
|
+
client: ThirdwebClient;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* The address of wallet that pays for the tokens.
|
34
|
+
*/
|
35
|
+
fromAddress: string;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* The address of the wallet where the tokens are sent
|
39
|
+
*/
|
40
|
+
toAddress: string;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* The chain id of the transfer token.
|
44
|
+
*/
|
45
|
+
chainId: number;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* The token address of the transfer token.
|
49
|
+
*/
|
50
|
+
tokenAddress: string;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* The amount of token to be transferred.
|
54
|
+
*/
|
55
|
+
amount: string;
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Extra details to store with the purchase.
|
59
|
+
*
|
60
|
+
* This details will be stored with the purchase and can be retrieved later via the status API or Webhook
|
61
|
+
*/
|
62
|
+
purchaseData?: object;
|
63
|
+
};
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @buyCrypto
|
67
|
+
*/
|
68
|
+
type BuyWithCryptoTransferResponse = {
|
69
|
+
quoteId: string;
|
70
|
+
transactionRequest: QuoteTransactionRequest;
|
71
|
+
approval?: QuoteApprovalInfo;
|
72
|
+
fromAddress: string;
|
73
|
+
toAddress: string;
|
74
|
+
token: QuoteTokenInfo;
|
75
|
+
paymentToken: QuotePaymentToken;
|
76
|
+
processingFee: QuotePaymentToken;
|
77
|
+
estimatedGasCostUSDCents: number;
|
78
|
+
};
|
79
|
+
|
80
|
+
/**
|
81
|
+
* @buyCrypto
|
82
|
+
*/
|
83
|
+
export type BuyWithCryptoTransfer = {
|
84
|
+
transactionRequest: PrepareTransactionOptions;
|
85
|
+
approval?: PrepareTransactionOptions;
|
86
|
+
fromAddress: string;
|
87
|
+
toAddress: string;
|
88
|
+
paymentToken: QuotePaymentToken;
|
89
|
+
processingFee: QuotePaymentToken;
|
90
|
+
estimatedGasCostUSDCents: number;
|
91
|
+
client: ThirdwebClient;
|
92
|
+
};
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Get a quote of type [`BuyWithCryptoTransfer`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoTransfer) to facilitate a token transfer transaction.
|
96
|
+
* Using this instead of a native transfer allows you to receive status and webhooks about successful or failed payments.
|
97
|
+
*
|
98
|
+
* Once you have the quote, you can use `prepareTransaction` and prepare the transaction for submission.
|
99
|
+
* @param params - object of type [`GetBuyWithCryptoTransferParams`](https://portal.thirdweb.com/references/typescript/v5/GetBuyWithCryptoTransferParams)
|
100
|
+
* @returns Object of type [`BuyWithCryptoTransfer`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoTransfer) which contains the information about the transfer
|
101
|
+
* @example
|
102
|
+
*
|
103
|
+
* ```ts
|
104
|
+
* import { getBuyWithCryptoTransfer } from "thirdweb/pay";
|
105
|
+
*
|
106
|
+
* const transfer = await getBuyWithCryptoTransfer({
|
107
|
+
* client,
|
108
|
+
* fromAddress: "0x...", // wallet address
|
109
|
+
* toAddress: "0x...", // recipient address - likely to be your wallet
|
110
|
+
* chainId: 10, // chain id of the token
|
111
|
+
* tokenAddress: "0x...", // address of the token
|
112
|
+
* amount: "10", // amount of token to transfer
|
113
|
+
* purchaseData: { // any metadata for you to attribute this purchase
|
114
|
+
* "customerId": "yourId"
|
115
|
+
* }
|
116
|
+
* });
|
117
|
+
* ```
|
118
|
+
* @buyCrypto
|
119
|
+
*/
|
120
|
+
export async function getBuyWithCryptoTransfer(
|
121
|
+
params: GetBuyWithCryptoTransferParams,
|
122
|
+
): Promise<BuyWithCryptoTransfer> {
|
123
|
+
try {
|
124
|
+
const clientFetch = getClientFetch(params.client);
|
125
|
+
|
126
|
+
const response = await clientFetch(getPayBuyWithCryptoTransferEndpoint(), {
|
127
|
+
method: "POST",
|
128
|
+
headers: {
|
129
|
+
Accept: "application/json",
|
130
|
+
"Content-Type": "application/json",
|
131
|
+
},
|
132
|
+
body: JSON.stringify({
|
133
|
+
fromAddress: params.fromAddress,
|
134
|
+
toAddress: params.toAddress,
|
135
|
+
chainId: params.chainId,
|
136
|
+
tokenAddress: params.tokenAddress,
|
137
|
+
amount: params.amount,
|
138
|
+
purchaseData: params.purchaseData,
|
139
|
+
}),
|
140
|
+
});
|
141
|
+
|
142
|
+
if (!response.ok) {
|
143
|
+
const errorObj = await response.json();
|
144
|
+
if (errorObj && "error" in errorObj) {
|
145
|
+
throw errorObj;
|
146
|
+
}
|
147
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
148
|
+
}
|
149
|
+
|
150
|
+
const data: BuyWithCryptoTransferResponse = (await response.json()).result;
|
151
|
+
|
152
|
+
const transfer: BuyWithCryptoTransfer = {
|
153
|
+
transactionRequest: {
|
154
|
+
chain: getCachedChain(data.transactionRequest.chainId),
|
155
|
+
client: params.client,
|
156
|
+
data: data.transactionRequest.data as Hash,
|
157
|
+
to: data.transactionRequest.to as Address,
|
158
|
+
value: BigInt(data.transactionRequest.value),
|
159
|
+
gas: BigInt(data.transactionRequest.gasLimit),
|
160
|
+
},
|
161
|
+
approval: data.approval
|
162
|
+
? approve({
|
163
|
+
contract: getContract({
|
164
|
+
client: params.client,
|
165
|
+
address: data.approval.tokenAddress,
|
166
|
+
chain: getCachedChain(data.approval.chainId),
|
167
|
+
}),
|
168
|
+
spender: data.approval.spenderAddress as Address,
|
169
|
+
amountWei: BigInt(data.approval.amountWei),
|
170
|
+
})
|
171
|
+
: undefined,
|
172
|
+
fromAddress: data.fromAddress,
|
173
|
+
toAddress: data.toAddress,
|
174
|
+
paymentToken: data.paymentToken,
|
175
|
+
processingFee: data.processingFee,
|
176
|
+
estimatedGasCostUSDCents: data.estimatedGasCostUSDCents,
|
177
|
+
client: params.client,
|
178
|
+
};
|
179
|
+
|
180
|
+
return transfer;
|
181
|
+
} catch (error) {
|
182
|
+
console.error("Error getting buy with crypto transfer", error);
|
183
|
+
throw error;
|
184
|
+
}
|
185
|
+
}
|
@@ -38,7 +38,7 @@ export type GetBuyWithFiatQuoteParams = {
|
|
38
38
|
/**
|
39
39
|
* Symbol of the fiat currency to buy the token with.
|
40
40
|
*/
|
41
|
-
fromCurrencySymbol: "USD" | "CAD" | "GBP" | "EUR";
|
41
|
+
fromCurrencySymbol: "USD" | "CAD" | "GBP" | "EUR" | "JPY";
|
42
42
|
|
43
43
|
/**
|
44
44
|
* The maximum slippage in basis points (bps) allowed for the transaction.
|
@@ -20,6 +20,13 @@ export const getPayBuyWithCryptoStatusUrl = () =>
|
|
20
20
|
export const getPayBuyWithCryptoQuoteEndpoint = () =>
|
21
21
|
`${getPayBaseUrl()}/buy-with-crypto/quote/v1`;
|
22
22
|
|
23
|
+
/**
|
24
|
+
* Endpoint to get "Buy with Crypto" transfer.
|
25
|
+
* @internal
|
26
|
+
*/
|
27
|
+
export const getPayBuyWithCryptoTransferEndpoint = () =>
|
28
|
+
`${getPayBaseUrl()}/buy-with-crypto/transfer/v1`;
|
29
|
+
|
23
30
|
/**
|
24
31
|
* Endpoint to get a "Buy with Fiat" quote.
|
25
32
|
* @internal
|
@@ -82,6 +82,9 @@ export type PayUIOptions = Prettify<
|
|
82
82
|
buyWithFiat?:
|
83
83
|
| {
|
84
84
|
testMode?: boolean;
|
85
|
+
prefillSource?: {
|
86
|
+
currency?: "USD" | "CAD" | "GBP" | "EUR" | "JPY";
|
87
|
+
};
|
85
88
|
}
|
86
89
|
| false;
|
87
90
|
|
@@ -226,6 +229,19 @@ export type ConnectButton_detailsModalOptions = {
|
|
226
229
|
*/
|
227
230
|
networkSelector?: NetworkSelectorProps;
|
228
231
|
|
232
|
+
/**
|
233
|
+
* Hide the "Switch Wallet" button in the `ConnectButton` Details Modal.
|
234
|
+
*
|
235
|
+
* By default it is `false`
|
236
|
+
* @example
|
237
|
+
* ```tsx
|
238
|
+
* <ConnectButton detailsModal={{
|
239
|
+
* hideSwitchWallet: true
|
240
|
+
* }} />
|
241
|
+
* ```
|
242
|
+
*/
|
243
|
+
hideSwitchWallet?: boolean;
|
244
|
+
|
229
245
|
/**
|
230
246
|
* Hide the "Disconnect Wallet" button in the `ConnectButton` Details Modal.
|
231
247
|
*
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { StyleSheet, View } from "react-native";
|
2
|
+
import { formatNumber } from "../../../../utils/formatNumber.js";
|
2
3
|
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
|
3
4
|
import { parseTheme } from "../../../core/design-system/CustomThemeProvider.js";
|
4
5
|
import type { ConnectButtonProps } from "../../../core/hooks/connection/ConnectButtonProps.js";
|
@@ -64,7 +65,7 @@ export function ConnectedButton(
|
|
64
65
|
fontSize: fontSize.sm,
|
65
66
|
}}
|
66
67
|
>
|
67
|
-
{Number(balanceQuery.data.displayValue)
|
68
|
+
{formatBalanceOnButton(Number(balanceQuery.data.displayValue))}{" "}
|
68
69
|
{balanceQuery.data?.symbol}
|
69
70
|
</ThemedText>
|
70
71
|
) : (
|
@@ -80,6 +81,10 @@ export function ConnectedButton(
|
|
80
81
|
);
|
81
82
|
}
|
82
83
|
|
84
|
+
function formatBalanceOnButton(num: number) {
|
85
|
+
return formatNumber(num, num < 1 ? 5 : 4);
|
86
|
+
}
|
87
|
+
|
83
88
|
const styles = StyleSheet.create({
|
84
89
|
row: {
|
85
90
|
flexDirection: "row",
|
@@ -3,6 +3,7 @@ import { Linking, StyleSheet, TouchableOpacity, View } from "react-native";
|
|
3
3
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
4
4
|
import { getContract } from "../../../../contract/contract.js";
|
5
5
|
import { isContractDeployed } from "../../../../utils/bytecode/is-contract-deployed.js";
|
6
|
+
import { formatNumber } from "../../../../utils/formatNumber.js";
|
6
7
|
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
|
7
8
|
import type { Theme } from "../../../core/design-system/index.js";
|
8
9
|
import { useSiweAuth } from "../../../core/hooks/auth/useSiweAuth.js";
|
@@ -189,7 +190,7 @@ const AccountHeader = (props: ConnectedModalProps) => {
|
|
189
190
|
fontSize: fontSize.sm,
|
190
191
|
}}
|
191
192
|
>
|
192
|
-
{Number(balanceQuery.data.displayValue)
|
193
|
+
{formatNumber(Number(balanceQuery.data.displayValue), 5)}{" "}
|
193
194
|
{balanceQuery.data?.symbol}
|
194
195
|
</ThemedText>
|
195
196
|
) : (
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { ScrollView, StyleSheet, TouchableOpacity, View } from "react-native";
|
2
2
|
import type { Chain } from "../../../../chains/types.js";
|
3
3
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
4
|
+
import { formatNumber } from "../../../../utils/formatNumber.js";
|
4
5
|
import type { Theme } from "../../../core/design-system/index.js";
|
5
6
|
import { useWalletBalance } from "../../../core/hooks/others/useWalletBalance.js";
|
6
7
|
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
|
@@ -91,7 +92,7 @@ export const TokenRow = (props: {
|
|
91
92
|
<>
|
92
93
|
{balanceQuery.data ? (
|
93
94
|
<ThemedText theme={theme} type="subtext">
|
94
|
-
{Number(balanceQuery.data.displayValue)
|
95
|
+
{formatBalanceOnButton(Number(balanceQuery.data.displayValue))}{" "}
|
95
96
|
{balanceQuery.data?.symbol}
|
96
97
|
</ThemedText>
|
97
98
|
) : (
|
@@ -125,6 +126,10 @@ export const TokenRow = (props: {
|
|
125
126
|
);
|
126
127
|
};
|
127
128
|
|
129
|
+
function formatBalanceOnButton(num: number) {
|
130
|
+
return formatNumber(num, num < 1 ? 5 : 4);
|
131
|
+
}
|
132
|
+
|
128
133
|
const styles = StyleSheet.create({
|
129
134
|
listContainer: {
|
130
135
|
flexDirection: "column",
|
@@ -14,6 +14,7 @@ import type { Chain } from "../../../../chains/types.js";
|
|
14
14
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
15
15
|
import { getContract } from "../../../../contract/contract.js";
|
16
16
|
import { isContractDeployed } from "../../../../utils/bytecode/is-contract-deployed.js";
|
17
|
+
import { formatNumber } from "../../../../utils/formatNumber.js";
|
17
18
|
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
|
18
19
|
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
|
19
20
|
import type { AppMetadata } from "../../../../wallets/types.js";
|
@@ -246,9 +247,7 @@ export const ConnectedWalletDetails: React.FC<{
|
|
246
247
|
color="secondaryText"
|
247
248
|
weight={400}
|
248
249
|
>
|
249
|
-
{Number.
|
250
|
-
Number(balanceQuery.data.displayValue).toFixed(3),
|
251
|
-
)}{" "}
|
250
|
+
{formatBalanceOnButton(Number(balanceQuery.data.displayValue))}{" "}
|
252
251
|
{balanceQuery.data.symbol}
|
253
252
|
</Text>
|
254
253
|
) : (
|
@@ -352,9 +351,7 @@ function DetailsModal(props: {
|
|
352
351
|
{chainNameQuery.name || `Unknown chain #${walletChain?.id}`}
|
353
352
|
<Text color="secondaryText" size="xs">
|
354
353
|
{balanceQuery.data ? (
|
355
|
-
Number.
|
356
|
-
Number(balanceQuery.data.displayValue).toFixed(3),
|
357
|
-
)
|
354
|
+
formatNumber(Number(balanceQuery.data.displayValue), 5)
|
358
355
|
) : (
|
359
356
|
<Skeleton height="1em" width="100px" />
|
360
357
|
)}{" "}
|
@@ -374,84 +371,91 @@ function DetailsModal(props: {
|
|
374
371
|
</MenuButton>
|
375
372
|
);
|
376
373
|
|
374
|
+
const avatarContent = (
|
375
|
+
<Container
|
376
|
+
style={{
|
377
|
+
position: "relative",
|
378
|
+
height: `${iconSize.xl}px`,
|
379
|
+
width: `${iconSize.xl}px`,
|
380
|
+
}}
|
381
|
+
>
|
382
|
+
<Container
|
383
|
+
style={{
|
384
|
+
width: "100%",
|
385
|
+
height: "100%",
|
386
|
+
borderRadius: "100%",
|
387
|
+
overflow: "hidden",
|
388
|
+
}}
|
389
|
+
>
|
390
|
+
{ensAvatarQuery.data ? (
|
391
|
+
<img
|
392
|
+
src={ensAvatarQuery.data}
|
393
|
+
style={{
|
394
|
+
width: iconSize.xxl,
|
395
|
+
height: iconSize.xxl,
|
396
|
+
}}
|
397
|
+
alt=""
|
398
|
+
/>
|
399
|
+
) : (
|
400
|
+
activeAccount && (
|
401
|
+
<Blobbie
|
402
|
+
address={activeAccount.address}
|
403
|
+
size={Number(iconSize.xxl)}
|
404
|
+
/>
|
405
|
+
)
|
406
|
+
)}
|
407
|
+
</Container>
|
408
|
+
<Container
|
409
|
+
style={{
|
410
|
+
position: "absolute",
|
411
|
+
bottom: -2,
|
412
|
+
right: -2,
|
413
|
+
}}
|
414
|
+
>
|
415
|
+
<IconContainer
|
416
|
+
style={{
|
417
|
+
background: theme.colors.modalBg,
|
418
|
+
}}
|
419
|
+
padding="4px"
|
420
|
+
>
|
421
|
+
{activeWallet && (
|
422
|
+
<WalletImage
|
423
|
+
style={{ borderRadius: 0 }}
|
424
|
+
id={activeWallet.id}
|
425
|
+
client={client}
|
426
|
+
size="12"
|
427
|
+
/>
|
428
|
+
)}
|
429
|
+
</IconContainer>
|
430
|
+
</Container>
|
431
|
+
</Container>
|
432
|
+
);
|
433
|
+
|
377
434
|
let content = (
|
378
435
|
<div>
|
379
436
|
<Spacer y="xs" />
|
380
437
|
<Container p="lg" gap="sm" flex="row" center="y">
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
onKeyDown={(e) => {
|
387
|
-
if (e.key === "w") {
|
388
|
-
setScreen("wallet-manager");
|
389
|
-
}
|
390
|
-
}}
|
391
|
-
onClick={() => {
|
392
|
-
setScreen("wallet-manager");
|
393
|
-
}}
|
394
|
-
>
|
395
|
-
<Container
|
438
|
+
{props.detailsModal?.hideSwitchWallet ? (
|
439
|
+
avatarContent
|
440
|
+
) : (
|
441
|
+
<ToolTip tip="Switch wallet">
|
442
|
+
<div
|
396
443
|
style={{
|
397
|
-
|
398
|
-
|
399
|
-
|
444
|
+
cursor: "pointer",
|
445
|
+
}}
|
446
|
+
onKeyDown={(e) => {
|
447
|
+
if (e.key === "w") {
|
448
|
+
setScreen("wallet-manager");
|
449
|
+
}
|
450
|
+
}}
|
451
|
+
onClick={() => {
|
452
|
+
setScreen("wallet-manager");
|
400
453
|
}}
|
401
454
|
>
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
borderRadius: "100%",
|
407
|
-
overflow: "hidden",
|
408
|
-
}}
|
409
|
-
>
|
410
|
-
{ensAvatarQuery.data ? (
|
411
|
-
<img
|
412
|
-
src={ensAvatarQuery.data}
|
413
|
-
style={{
|
414
|
-
width: iconSize.xxl,
|
415
|
-
height: iconSize.xxl,
|
416
|
-
}}
|
417
|
-
alt=""
|
418
|
-
/>
|
419
|
-
) : (
|
420
|
-
activeAccount && (
|
421
|
-
<Blobbie
|
422
|
-
address={activeAccount.address}
|
423
|
-
size={Number(iconSize.xxl)}
|
424
|
-
/>
|
425
|
-
)
|
426
|
-
)}
|
427
|
-
</Container>
|
428
|
-
<Container
|
429
|
-
style={{
|
430
|
-
position: "absolute",
|
431
|
-
bottom: -2,
|
432
|
-
right: -2,
|
433
|
-
}}
|
434
|
-
>
|
435
|
-
<IconContainer
|
436
|
-
style={{
|
437
|
-
background: theme.colors.modalBg,
|
438
|
-
}}
|
439
|
-
padding="4px"
|
440
|
-
>
|
441
|
-
{activeWallet && (
|
442
|
-
<WalletImage
|
443
|
-
style={{ borderRadius: 0 }}
|
444
|
-
id={activeWallet.id}
|
445
|
-
client={client}
|
446
|
-
size="12"
|
447
|
-
/>
|
448
|
-
)}
|
449
|
-
</IconContainer>
|
450
|
-
</Container>
|
451
|
-
</Container>
|
452
|
-
</div>
|
453
|
-
</ToolTip>
|
454
|
-
|
455
|
+
{avatarContent}
|
456
|
+
</div>
|
457
|
+
</ToolTip>
|
458
|
+
)}
|
455
459
|
<Container flex="column" gap="3xs">
|
456
460
|
<div
|
457
461
|
style={{
|
@@ -909,6 +913,10 @@ function DetailsModal(props: {
|
|
909
913
|
);
|
910
914
|
}
|
911
915
|
|
916
|
+
function formatBalanceOnButton(num: number) {
|
917
|
+
return formatNumber(num, num < 1 ? 5 : 4);
|
918
|
+
}
|
919
|
+
|
912
920
|
const WalletInfoButton = /* @__PURE__ */ StyledButton((_) => {
|
913
921
|
const theme = useCustomTheme();
|
914
922
|
return {
|
@@ -1257,6 +1265,13 @@ export type UseWalletDetailsModalOptions = {
|
|
1257
1265
|
*/
|
1258
1266
|
hideDisconnect?: boolean;
|
1259
1267
|
|
1268
|
+
/**
|
1269
|
+
* Hide the "Switch Wallet" button in the Wallet Details Modal.
|
1270
|
+
*
|
1271
|
+
* By default it is `false`
|
1272
|
+
*/
|
1273
|
+
hideSwitchWallet?: boolean;
|
1274
|
+
|
1260
1275
|
/**
|
1261
1276
|
* Callback to be called when a wallet is disconnected by clicking the "Disconnect Wallet" button in the Wallet Details Modal.
|
1262
1277
|
*
|
@@ -1363,6 +1378,7 @@ export function useWalletDetailsModal() {
|
|
1363
1378
|
detailsModal={{
|
1364
1379
|
footer: props.footer,
|
1365
1380
|
hideDisconnect: props.hideDisconnect,
|
1381
|
+
hideSwitchWallet: props.hideSwitchWallet,
|
1366
1382
|
networkSelector: props.networkSelector,
|
1367
1383
|
payOptions: props.payOptions,
|
1368
1384
|
showTestnetFaucet: props.showTestnetFaucet,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { IconFC } from "../types.js";
|
2
|
+
|
3
|
+
export const JPYIcon: IconFC = (props) => {
|
4
|
+
return (
|
5
|
+
<svg
|
6
|
+
width={props.size}
|
7
|
+
height={props.size}
|
8
|
+
viewBox="0 0 32 32"
|
9
|
+
xmlns="http://www.w3.org/2000/svg"
|
10
|
+
role="presentation"
|
11
|
+
>
|
12
|
+
<g fill="none" fill-rule="evenodd">
|
13
|
+
<circle cx="16" cy="16" fill="#a81b1b" r="16" />
|
14
|
+
<path
|
15
|
+
d="M17.548 18.711v1.878h5.063v2.288h-5.063V25.5h-3.096v-2.623H9.389v-2.288h5.063v-1.878H9.389v-2.288h4.171L7.5 7.5h3.752l4.8 7.534L20.853 7.5H24.5l-6.086 8.923h4.197v2.288z"
|
16
|
+
fill="#ffffff"
|
17
|
+
/>
|
18
|
+
</g>
|
19
|
+
</svg>
|
20
|
+
);
|
21
|
+
};
|
@@ -325,12 +325,19 @@ function BuyScreenContent(props: BuyScreenContentProps) {
|
|
325
325
|
onBack={goBack}
|
326
326
|
payer={payer}
|
327
327
|
client={props.client}
|
328
|
-
onDone={onDone}
|
329
328
|
chain={toChain}
|
330
329
|
token={toToken}
|
331
330
|
tokenAmount={tokenAmount}
|
332
331
|
receiverAddress={receiverAddress}
|
333
332
|
transactionMode={props.payOptions.mode === "transaction"}
|
333
|
+
isEmbed={props.isEmbed}
|
334
|
+
onDone={onDone}
|
335
|
+
onTryAgain={() => {
|
336
|
+
setScreen({
|
337
|
+
id: "buy-with-crypto",
|
338
|
+
});
|
339
|
+
}}
|
340
|
+
onSuccess={onSwapSuccess}
|
334
341
|
/>
|
335
342
|
);
|
336
343
|
}
|
@@ -2,23 +2,24 @@ import { RadiobuttonIcon } from "@radix-ui/react-icons";
|
|
2
2
|
import { CADIcon } from "../../../icons/currencies/CADIcon.js";
|
3
3
|
import { EURIcon } from "../../../icons/currencies/EURIcon.js";
|
4
4
|
import { GBPIcon } from "../../../icons/currencies/GBPIcon.js";
|
5
|
+
import { JPYIcon } from "../../../icons/currencies/JPYIcon.js";
|
5
6
|
import { USDIcon } from "../../../icons/currencies/USDIcon.js";
|
6
7
|
import type { IconFC } from "../../../icons/types.js";
|
7
8
|
|
8
9
|
export type CurrencyMeta = {
|
9
|
-
shorthand: "USD" | "CAD" | "GBP" | "EUR";
|
10
|
+
shorthand: "USD" | "CAD" | "GBP" | "EUR" | "JPY";
|
10
11
|
name: string;
|
11
12
|
icon: IconFC;
|
12
13
|
};
|
13
14
|
|
14
|
-
export const
|
15
|
+
export const usdCurrency: CurrencyMeta = {
|
15
16
|
shorthand: "USD",
|
16
17
|
name: "US Dollar",
|
17
18
|
icon: USDIcon,
|
18
19
|
};
|
19
20
|
|
20
21
|
export const currencies: CurrencyMeta[] = [
|
21
|
-
|
22
|
+
usdCurrency,
|
22
23
|
{
|
23
24
|
shorthand: "CAD",
|
24
25
|
name: "Canadian Dollar",
|
@@ -34,6 +35,11 @@ export const currencies: CurrencyMeta[] = [
|
|
34
35
|
name: "Euro",
|
35
36
|
icon: EURIcon,
|
36
37
|
},
|
38
|
+
{
|
39
|
+
shorthand: "JPY",
|
40
|
+
name: "Japanese Yen",
|
41
|
+
icon: JPYIcon,
|
42
|
+
},
|
37
43
|
];
|
38
44
|
|
39
45
|
export function getCurrencyMeta(shorthand: string): CurrencyMeta {
|