thirdweb 5.108.1 → 5.108.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/bridge/Buy.js +2 -2
- package/dist/cjs/bridge/Chains.js +1 -1
- package/dist/cjs/bridge/Routes.js +1 -1
- package/dist/cjs/bridge/Sell.js +2 -2
- package/dist/cjs/bridge/Status.js +1 -1
- package/dist/cjs/bridge/Token.js +3 -3
- package/dist/cjs/bridge/Transfer.js +1 -1
- package/dist/cjs/bridge/Webhook.js +1 -1
- package/dist/cjs/exports/react.js +3 -1
- package/dist/cjs/exports/react.js.map +1 -1
- package/dist/cjs/exports/thirdweb.js +1 -1
- package/dist/cjs/react/core/hooks/useStepExecutor.js +1 -21
- package/dist/cjs/react/core/hooks/useStepExecutor.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js +5 -6
- package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/StepRunner.js +2 -2
- package/dist/cjs/react/web/ui/Bridge/StepRunner.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/TransactionPayment.js +1 -0
- package/dist/cjs/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/bridge-widget/bridge-widget.js +95 -0
- package/dist/cjs/react/web/ui/Bridge/bridge-widget/bridge-widget.js.map +1 -0
- package/dist/cjs/react/web/ui/Bridge/payment-details/PaymentOverview.js +1 -0
- package/dist/cjs/react/web/ui/Bridge/payment-details/PaymentOverview.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/swap-widget/SwapWidget.js +13 -1
- package/dist/cjs/react/web/ui/Bridge/swap-widget/SwapWidget.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/swap-widget/select-chain.js +12 -1
- package/dist/cjs/react/web/ui/Bridge/swap-widget/select-chain.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/swap-widget/select-token-ui.js +13 -4
- package/dist/cjs/react/web/ui/Bridge/swap-widget/select-token-ui.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/swap-widget/swap-ui.js +6 -10
- package/dist/cjs/react/web/ui/Bridge/swap-widget/swap-ui.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +2 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/cjs/script-exports/bridge-widget-script.js +17 -0
- package/dist/cjs/script-exports/bridge-widget-script.js.map +1 -0
- package/dist/cjs/script-exports/bridge-widget.js +13 -0
- package/dist/cjs/script-exports/bridge-widget.js.map +1 -0
- package/dist/cjs/stories/Bridge/BridgeOrchestrator.stories.js +30 -1
- package/dist/cjs/stories/Bridge/BridgeOrchestrator.stories.js.map +1 -1
- package/dist/cjs/stories/Bridge/BridgeWidget/bridge-widget-script.stories.js +47 -0
- package/dist/cjs/stories/Bridge/BridgeWidget/bridge-widget-script.stories.js.map +1 -0
- package/dist/cjs/stories/Bridge/StepRunner.stories.js +1 -21
- package/dist/cjs/stories/Bridge/StepRunner.stories.js.map +1 -1
- package/dist/cjs/stories/Bridge/UnsupportedTokenScreen.stories.js +4 -4
- package/dist/cjs/stories/Bridge/UnsupportedTokenScreen.stories.js.map +1 -1
- package/dist/cjs/utils/units.js +3 -0
- package/dist/cjs/utils/units.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/x402/common.js +41 -41
- package/dist/cjs/x402/common.js.map +1 -1
- package/dist/cjs/x402/facilitator.js +1 -0
- package/dist/cjs/x402/facilitator.js.map +1 -1
- package/dist/cjs/x402/fetchWithPayment.js +1 -1
- package/dist/cjs/x402/fetchWithPayment.js.map +1 -1
- package/dist/cjs/x402/schemas.js +3 -0
- package/dist/cjs/x402/schemas.js.map +1 -1
- package/dist/cjs/x402/settle-payment.js +4 -3
- package/dist/cjs/x402/settle-payment.js.map +1 -1
- package/dist/cjs/x402/types.js.map +1 -1
- package/dist/cjs/x402/verify-payment.js +2 -1
- package/dist/cjs/x402/verify-payment.js.map +1 -1
- package/dist/esm/bridge/Buy.js +2 -2
- package/dist/esm/bridge/Chains.js +1 -1
- package/dist/esm/bridge/Routes.js +1 -1
- package/dist/esm/bridge/Sell.js +2 -2
- package/dist/esm/bridge/Status.js +1 -1
- package/dist/esm/bridge/Token.js +3 -3
- package/dist/esm/bridge/Transfer.js +1 -1
- package/dist/esm/bridge/Webhook.js +1 -1
- package/dist/esm/exports/react.js +1 -0
- package/dist/esm/exports/react.js.map +1 -1
- package/dist/esm/exports/thirdweb.js +1 -1
- package/dist/esm/react/core/hooks/useStepExecutor.js +1 -21
- package/dist/esm/react/core/hooks/useStepExecutor.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js +5 -6
- package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/StepRunner.js +2 -2
- package/dist/esm/react/web/ui/Bridge/StepRunner.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/TransactionPayment.js +1 -0
- package/dist/esm/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/bridge-widget/bridge-widget.js +92 -0
- package/dist/esm/react/web/ui/Bridge/bridge-widget/bridge-widget.js.map +1 -0
- package/dist/esm/react/web/ui/Bridge/payment-details/PaymentOverview.js +1 -0
- package/dist/esm/react/web/ui/Bridge/payment-details/PaymentOverview.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/swap-widget/SwapWidget.js +13 -1
- package/dist/esm/react/web/ui/Bridge/swap-widget/SwapWidget.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/swap-widget/select-chain.js +13 -2
- package/dist/esm/react/web/ui/Bridge/swap-widget/select-chain.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/swap-widget/select-token-ui.js +13 -4
- package/dist/esm/react/web/ui/Bridge/swap-widget/select-token-ui.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/swap-widget/swap-ui.js +6 -10
- package/dist/esm/react/web/ui/Bridge/swap-widget/swap-ui.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +2 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/esm/script-exports/bridge-widget-script.js +14 -0
- package/dist/esm/script-exports/bridge-widget-script.js.map +1 -0
- package/dist/esm/script-exports/bridge-widget.js +10 -0
- package/dist/esm/script-exports/bridge-widget.js.map +1 -0
- package/dist/esm/stories/Bridge/BridgeOrchestrator.stories.js +29 -0
- package/dist/esm/stories/Bridge/BridgeOrchestrator.stories.js.map +1 -1
- package/dist/esm/stories/Bridge/BridgeWidget/bridge-widget-script.stories.js +40 -0
- package/dist/esm/stories/Bridge/BridgeWidget/bridge-widget-script.stories.js.map +1 -0
- package/dist/esm/stories/Bridge/StepRunner.stories.js +2 -22
- package/dist/esm/stories/Bridge/StepRunner.stories.js.map +1 -1
- package/dist/esm/stories/Bridge/UnsupportedTokenScreen.stories.js +4 -4
- package/dist/esm/stories/Bridge/UnsupportedTokenScreen.stories.js.map +1 -1
- package/dist/esm/utils/units.js +3 -0
- package/dist/esm/utils/units.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/x402/common.js +42 -42
- package/dist/esm/x402/common.js.map +1 -1
- package/dist/esm/x402/facilitator.js +1 -0
- package/dist/esm/x402/facilitator.js.map +1 -1
- package/dist/esm/x402/fetchWithPayment.js +1 -1
- package/dist/esm/x402/fetchWithPayment.js.map +1 -1
- package/dist/esm/x402/schemas.js +3 -0
- package/dist/esm/x402/schemas.js.map +1 -1
- package/dist/esm/x402/settle-payment.js +4 -3
- package/dist/esm/x402/settle-payment.js.map +1 -1
- package/dist/esm/x402/types.js.map +1 -1
- package/dist/esm/x402/verify-payment.js +2 -1
- package/dist/esm/x402/verify-payment.js.map +1 -1
- package/dist/scripts/bridge-widget.d.ts +1118 -0
- package/dist/scripts/bridge-widget.js +532 -0
- package/dist/types/bridge/Buy.d.ts +2 -2
- package/dist/types/bridge/Chains.d.ts +1 -1
- package/dist/types/bridge/Routes.d.ts +1 -1
- package/dist/types/bridge/Sell.d.ts +2 -2
- package/dist/types/bridge/Status.d.ts +1 -1
- package/dist/types/bridge/Token.d.ts +3 -3
- package/dist/types/bridge/Transfer.d.ts +1 -1
- package/dist/types/bridge/Webhook.d.ts +1 -1
- package/dist/types/bridge/types/Chain.d.ts +1 -1
- package/dist/types/exports/react.d.ts +1 -0
- package/dist/types/exports/react.d.ts.map +1 -1
- package/dist/types/exports/thirdweb.d.ts +1 -1
- package/dist/types/react/core/hooks/useStepExecutor.d.ts +3 -4
- package/dist/types/react/core/hooks/useStepExecutor.d.ts.map +1 -1
- package/dist/types/react/core/hooks/useTransactionDetails.d.ts +1 -1
- package/dist/types/react/core/hooks/useTransactionDetails.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +1 -1
- package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/StepRunner.d.ts +6 -2
- package/dist/types/react/web/ui/Bridge/StepRunner.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/TransactionPayment.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/bridge-widget/bridge-widget.d.ts +218 -0
- package/dist/types/react/web/ui/Bridge/bridge-widget/bridge-widget.d.ts.map +1 -0
- package/dist/types/react/web/ui/Bridge/swap-widget/SwapWidget.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/swap-widget/select-chain.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/swap-widget/select-token-ui.d.ts +1 -1
- package/dist/types/react/web/ui/Bridge/swap-widget/select-token-ui.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/swap-widget/swap-ui.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
- package/dist/types/script-exports/bridge-widget-script.d.ts +49 -0
- package/dist/types/script-exports/bridge-widget-script.d.ts.map +1 -0
- package/dist/types/script-exports/bridge-widget.d.ts +4 -0
- package/dist/types/script-exports/bridge-widget.d.ts.map +1 -0
- package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts +4 -0
- package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts.map +1 -1
- package/dist/types/stories/Bridge/BridgeWidget/bridge-widget-script.stories.d.ts +10 -0
- package/dist/types/stories/Bridge/BridgeWidget/bridge-widget-script.stories.d.ts.map +1 -0
- package/dist/types/stories/Bridge/StepRunner.stories.d.ts +0 -6
- package/dist/types/stories/Bridge/StepRunner.stories.d.ts.map +1 -1
- package/dist/types/utils/domains.d.ts +1 -1
- package/dist/types/utils/units.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/x402/common.d.ts.map +1 -1
- package/dist/types/x402/facilitator.d.ts +1 -0
- package/dist/types/x402/facilitator.d.ts.map +1 -1
- package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
- package/dist/types/x402/schemas.d.ts +2 -1
- package/dist/types/x402/schemas.d.ts.map +1 -1
- package/dist/types/x402/settle-payment.d.ts +4 -2
- package/dist/types/x402/settle-payment.d.ts.map +1 -1
- package/dist/types/x402/types.d.ts +2 -1
- package/dist/types/x402/types.d.ts.map +1 -1
- package/dist/types/x402/verify-payment.d.ts +2 -1
- package/dist/types/x402/verify-payment.d.ts.map +1 -1
- package/package.json +7 -4
- package/src/bridge/Buy.ts +2 -2
- package/src/bridge/Chains.ts +1 -1
- package/src/bridge/Routes.ts +1 -1
- package/src/bridge/Sell.ts +2 -2
- package/src/bridge/Status.ts +1 -1
- package/src/bridge/Token.ts +3 -3
- package/src/bridge/Transfer.ts +1 -1
- package/src/bridge/Webhook.ts +1 -1
- package/src/bridge/types/Chain.ts +1 -1
- package/src/exports/react.ts +4 -0
- package/src/exports/thirdweb.ts +1 -1
- package/src/react/core/hooks/useStepExecutor.ts +5 -30
- package/src/react/core/hooks/useTransactionDetails.ts +1 -1
- package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +6 -9
- package/src/react/web/ui/Bridge/BuyWidget.tsx +1 -1
- package/src/react/web/ui/Bridge/StepRunner.tsx +11 -2
- package/src/react/web/ui/Bridge/TransactionPayment.tsx +1 -0
- package/src/react/web/ui/Bridge/bridge-widget/bridge-widget.tsx +344 -0
- package/src/react/web/ui/Bridge/payment-details/PaymentOverview.tsx +1 -0
- package/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx +14 -0
- package/src/react/web/ui/Bridge/swap-widget/select-chain.tsx +17 -2
- package/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx +14 -5
- package/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx +6 -14
- package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +3 -1
- package/src/script-exports/bridge-widget-script.tsx +72 -0
- package/src/script-exports/bridge-widget.tsx +17 -0
- package/src/script-exports/readme.md +72 -0
- package/src/stories/Bridge/BridgeOrchestrator.stories.tsx +31 -0
- package/src/stories/Bridge/BridgeWidget/bridge-widget-script.stories.tsx +79 -0
- package/src/stories/Bridge/StepRunner.stories.tsx +6 -23
- package/src/stories/Bridge/UnsupportedTokenScreen.stories.tsx +4 -4
- package/src/utils/domains.ts +1 -1
- package/src/utils/units.test.ts +13 -0
- package/src/utils/units.ts +4 -0
- package/src/version.ts +1 -1
- package/src/wallets/eip5792/send-calls.ts +1 -1
- package/src/wallets/smart/smart-wallet-modular.test.ts +1 -1
- package/src/x402/common.ts +46 -52
- package/src/x402/facilitator.ts +1 -0
- package/src/x402/fetchWithPayment.ts +3 -1
- package/src/x402/schemas.ts +5 -1
- package/src/x402/settle-payment.ts +4 -3
- package/src/x402/types.ts +2 -1
- package/src/x402/verify-payment.ts +2 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Bridge Widget
|
|
2
|
+
|
|
3
|
+
Add the script in document head and the element where you want to render the bridge widget in your page
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<!-- add the bridge-widget script in the head of the document, it adds the `BridgeWidget` global variable to the window object -->
|
|
7
|
+
<script src="https://unpkg.com/thirdweb/scripts/bridge-widget.js"></script>
|
|
8
|
+
|
|
9
|
+
<!-- add a unique id to an element where you want to render the bridge widget -->
|
|
10
|
+
<div id="bridge-widget"></div>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script>
|
|
17
|
+
// get the element where you want to render the bridge widget
|
|
18
|
+
const node = document.getElementById("bridge-widget");
|
|
19
|
+
|
|
20
|
+
// render the widget
|
|
21
|
+
BridgeWidget.render(node, {
|
|
22
|
+
clientId: "your-client-id",
|
|
23
|
+
theme: "dark",
|
|
24
|
+
buy: {
|
|
25
|
+
chainId: 8453,
|
|
26
|
+
amount: "0.1",
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
</script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Custom Theme
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<script>
|
|
36
|
+
BridgeWidget.render(node, {
|
|
37
|
+
clientId: "your-client-id",
|
|
38
|
+
theme: {
|
|
39
|
+
type: "dark",
|
|
40
|
+
colors: {
|
|
41
|
+
modalBg: "red",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
buy: {
|
|
45
|
+
chainId: 8453,
|
|
46
|
+
amount: "0.1",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
</script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Customizing Swap UI
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script>
|
|
56
|
+
BridgeWidget.render(node, {
|
|
57
|
+
clientId: "your-client-id",
|
|
58
|
+
swap: {
|
|
59
|
+
prefill: {
|
|
60
|
+
buyToken: {
|
|
61
|
+
chainId: 8453,
|
|
62
|
+
tokenAddress: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
buy: {
|
|
67
|
+
chainId: 8453,
|
|
68
|
+
amount: "0.1",
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
</script>
|
|
72
|
+
```
|
|
@@ -241,6 +241,37 @@ export const TransactionLight: Story = {
|
|
|
241
241
|
},
|
|
242
242
|
};
|
|
243
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Transaction mode in light theme showing an ERC20 token transfer.
|
|
246
|
+
*/
|
|
247
|
+
export const TransactionJPYCurrency: Story = {
|
|
248
|
+
args: {
|
|
249
|
+
connectLocale: undefined,
|
|
250
|
+
connectOptions: undefined,
|
|
251
|
+
onCancel: undefined,
|
|
252
|
+
onComplete: undefined,
|
|
253
|
+
onError: undefined,
|
|
254
|
+
paymentLinkId: undefined,
|
|
255
|
+
presetOptions: undefined,
|
|
256
|
+
purchaseData: undefined,
|
|
257
|
+
receiverAddress: undefined,
|
|
258
|
+
theme: "light",
|
|
259
|
+
uiOptions: {
|
|
260
|
+
...TRANSACTION_UI_OPTIONS.erc20Transfer,
|
|
261
|
+
currency: "JPY",
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
parameters: {
|
|
265
|
+
backgrounds: { default: "light" },
|
|
266
|
+
docs: {
|
|
267
|
+
description: {
|
|
268
|
+
story:
|
|
269
|
+
"Light theme version of transaction mode showing an ERC20 token transfer with proper token amount formatting and USD conversion.",
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
|
|
244
275
|
export const CustompresetOptions: Story = {
|
|
245
276
|
args: {
|
|
246
277
|
connectLocale: undefined,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Meta } from "@storybook/react";
|
|
2
|
+
import { BridgeWidgetScript } from "../../../script-exports/bridge-widget-script.js";
|
|
3
|
+
import { storyClient } from "../../utils.js";
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof BridgeWidgetScript> = {
|
|
6
|
+
title: "Bridge/BridgeWidgetScript",
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: "centered",
|
|
9
|
+
},
|
|
10
|
+
decorators: [
|
|
11
|
+
(Story) => {
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<Story />
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
export default meta;
|
|
21
|
+
|
|
22
|
+
export function BasicUsage() {
|
|
23
|
+
return (
|
|
24
|
+
<BridgeWidgetScript
|
|
25
|
+
clientId={storyClient.clientId}
|
|
26
|
+
buy={{ chainId: 8453, amount: "0.1" }}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function LightTheme() {
|
|
32
|
+
return (
|
|
33
|
+
<BridgeWidgetScript
|
|
34
|
+
clientId={storyClient.clientId}
|
|
35
|
+
theme="light"
|
|
36
|
+
buy={{ chainId: 8453, amount: "0.1" }}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function CurrencySet() {
|
|
42
|
+
return (
|
|
43
|
+
<BridgeWidgetScript
|
|
44
|
+
clientId={storyClient.clientId}
|
|
45
|
+
currency="JPY"
|
|
46
|
+
buy={{ chainId: 8453, amount: "0.1" }}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function NoThirdwebBranding() {
|
|
52
|
+
return (
|
|
53
|
+
<BridgeWidgetScript
|
|
54
|
+
clientId={storyClient.clientId}
|
|
55
|
+
theme="light"
|
|
56
|
+
buy={{ chainId: 8453, amount: "0.1" }}
|
|
57
|
+
showThirdwebBranding={false}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function CustomTheme() {
|
|
63
|
+
return (
|
|
64
|
+
<BridgeWidgetScript
|
|
65
|
+
clientId={storyClient.clientId}
|
|
66
|
+
buy={{ chainId: 8453, amount: "0.1" }}
|
|
67
|
+
theme={{
|
|
68
|
+
type: "light",
|
|
69
|
+
colors: {
|
|
70
|
+
modalBg: "#FFFFF0",
|
|
71
|
+
tertiaryBg: "#DBE4C9",
|
|
72
|
+
borderColor: "#8AA624",
|
|
73
|
+
secondaryText: "#3E3F29",
|
|
74
|
+
accentText: "#E43636",
|
|
75
|
+
},
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -7,7 +7,11 @@ import type { CompletedStatusResult } from "../../react/core/hooks/useStepExecut
|
|
|
7
7
|
import { StepRunner } from "../../react/web/ui/Bridge/StepRunner.js";
|
|
8
8
|
import type { Wallet } from "../../wallets/interfaces/wallet.js";
|
|
9
9
|
import { ModalThemeWrapper, storyClient } from "../utils.js";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
STORY_MOCK_WALLET,
|
|
12
|
+
simpleBuyQuote,
|
|
13
|
+
simpleBuyRequest,
|
|
14
|
+
} from "./fixtures.js";
|
|
11
15
|
|
|
12
16
|
// Mock window adapter
|
|
13
17
|
const mockWindowAdapter: WindowAdapter = {
|
|
@@ -32,7 +36,7 @@ const StepRunnerWithTheme = (props: StepRunnerWithThemeProps) => {
|
|
|
32
36
|
const { theme, ...componentProps } = props;
|
|
33
37
|
return (
|
|
34
38
|
<ModalThemeWrapper theme={theme}>
|
|
35
|
-
<StepRunner {...componentProps} />
|
|
39
|
+
<StepRunner {...componentProps} preparedQuote={simpleBuyQuote} />
|
|
36
40
|
</ModalThemeWrapper>
|
|
37
41
|
);
|
|
38
42
|
};
|
|
@@ -59,29 +63,8 @@ const meta = {
|
|
|
59
63
|
},
|
|
60
64
|
component: StepRunnerWithTheme,
|
|
61
65
|
parameters: {
|
|
62
|
-
docs: {
|
|
63
|
-
description: {
|
|
64
|
-
component:
|
|
65
|
-
"**StepRunner** executes prepared route steps sequentially, showing real-time progress and transaction status.\n\n" +
|
|
66
|
-
"## Features\n" +
|
|
67
|
-
"- **Real Execution**: Uses useStepExecutor hook for actual transaction processing\n" +
|
|
68
|
-
"- **Progress Tracking**: Visual progress bar and step-by-step status updates\n" +
|
|
69
|
-
"- **Error Handling**: Retry functionality for failed transactions\n" +
|
|
70
|
-
"- **Transaction Batching**: Optimizes multiple transactions when possible\n" +
|
|
71
|
-
"- **Onramp Support**: Handles fiat-to-crypto onramp flows\n\n" +
|
|
72
|
-
"## Props\n" +
|
|
73
|
-
"- `steps`: Array of RouteStep objects from Bridge.prepare()\n" +
|
|
74
|
-
"- `wallet`: Connected wallet for transaction signing\n" +
|
|
75
|
-
"- `client`: ThirdwebClient instance\n" +
|
|
76
|
-
"- `windowAdapter`: Platform-specific window/URL handler\n" +
|
|
77
|
-
"- `onramp`: Optional onramp configuration\n\n" +
|
|
78
|
-
"## Integration\n" +
|
|
79
|
-
"This component is typically used within the BridgeOrchestrator after route preparation.",
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
66
|
layout: "centered",
|
|
83
67
|
},
|
|
84
|
-
tags: ["autodocs"],
|
|
85
68
|
title: "Bridge/StepRunner",
|
|
86
69
|
} satisfies Meta<typeof StepRunnerWithTheme>;
|
|
87
70
|
|
|
@@ -68,7 +68,7 @@ export const TokenNotSupported: Story = {
|
|
|
68
68
|
docs: {
|
|
69
69
|
description: {
|
|
70
70
|
story:
|
|
71
|
-
"Shows the loading state when a token is being indexed by the
|
|
71
|
+
"Shows the loading state when a token is being indexed by the Bridge on a mainnet chain.",
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
74
|
},
|
|
@@ -85,7 +85,7 @@ export const TokenNotSupportedLight: Story = {
|
|
|
85
85
|
docs: {
|
|
86
86
|
description: {
|
|
87
87
|
story:
|
|
88
|
-
"Shows the loading state when a token is being indexed by the
|
|
88
|
+
"Shows the loading state when a token is being indexed by the Bridge on a mainnet chain (light theme).",
|
|
89
89
|
},
|
|
90
90
|
},
|
|
91
91
|
},
|
|
@@ -102,7 +102,7 @@ export const TestnetNotSupported: Story = {
|
|
|
102
102
|
docs: {
|
|
103
103
|
description: {
|
|
104
104
|
story:
|
|
105
|
-
"Shows the error state when trying to use the
|
|
105
|
+
"Shows the error state when trying to use the Bridge on a testnet chain (Sepolia in this example).",
|
|
106
106
|
},
|
|
107
107
|
},
|
|
108
108
|
},
|
|
@@ -119,7 +119,7 @@ export const TestnetNotSupportedLight: Story = {
|
|
|
119
119
|
docs: {
|
|
120
120
|
description: {
|
|
121
121
|
story:
|
|
122
|
-
"Shows the error state when trying to use the
|
|
122
|
+
"Shows the error state when trying to use the Bridge on a testnet chain (Sepolia in this example, light theme).",
|
|
123
123
|
},
|
|
124
124
|
},
|
|
125
125
|
},
|
package/src/utils/domains.ts
CHANGED
package/src/utils/units.test.ts
CHANGED
|
@@ -199,6 +199,19 @@ describe("toUnits", () => {
|
|
|
199
199
|
expect(toUnits("69.59000000059", 9)).toMatchInlineSnapshot("69590000001n");
|
|
200
200
|
expect(toUnits("69.59000002359", 9)).toMatchInlineSnapshot("69590000024n");
|
|
201
201
|
});
|
|
202
|
+
|
|
203
|
+
it("scientific notation", () => {
|
|
204
|
+
// negative exponents
|
|
205
|
+
expect(toUnits("1e-18", 18)).toMatchInlineSnapshot("1n");
|
|
206
|
+
expect(toUnits("1e-16", 18)).toMatchInlineSnapshot("100n");
|
|
207
|
+
expect(toUnits("1.23456789012345e-7", 18)).toMatchInlineSnapshot(
|
|
208
|
+
"123456789012n",
|
|
209
|
+
);
|
|
210
|
+
// positive exponents
|
|
211
|
+
expect(toUnits("1.234e3", 18)).toMatchInlineSnapshot(
|
|
212
|
+
"1234000000000000000000n",
|
|
213
|
+
);
|
|
214
|
+
});
|
|
202
215
|
});
|
|
203
216
|
|
|
204
217
|
describe("toWei", () => {
|
package/src/utils/units.ts
CHANGED
|
@@ -73,6 +73,10 @@ export function toEther(wei: bigint) {
|
|
|
73
73
|
* @utils
|
|
74
74
|
*/
|
|
75
75
|
export function toUnits(tokens: string, decimals: number): bigint {
|
|
76
|
+
if (tokens.includes("e")) {
|
|
77
|
+
tokens = Number(tokens).toFixed(decimals);
|
|
78
|
+
}
|
|
79
|
+
|
|
76
80
|
let [integerPart, fractionPart = ""] = tokens.split(".") as [string, string];
|
|
77
81
|
const prefix = integerPart.startsWith("-") ? "-" : "";
|
|
78
82
|
if (prefix) {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.108.
|
|
1
|
+
export const version = "5.108.2";
|
|
@@ -113,7 +113,7 @@ export type SendCallsResult = Prettify<{
|
|
|
113
113
|
* });
|
|
114
114
|
* ```
|
|
115
115
|
* We recommend proxying any paymaster calls via an API route you setup and control.
|
|
116
|
-
*
|
|
116
|
+
*
|
|
117
117
|
* @extension EIP5792
|
|
118
118
|
*/
|
|
119
119
|
export async function sendCalls<const ID extends WalletId>(
|
package/src/x402/common.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ERC20TokenAmount,
|
|
3
|
-
type Money,
|
|
4
|
-
moneySchema,
|
|
5
|
-
type Network,
|
|
6
|
-
SupportedEVMNetworks,
|
|
7
|
-
} from "x402/types";
|
|
1
|
+
import { type ERC20TokenAmount, type Money, moneySchema } from "x402/types";
|
|
8
2
|
import { getAddress } from "../utils/address.js";
|
|
9
3
|
import { decodePayment } from "./encode.js";
|
|
10
4
|
import type { facilitator as facilitatorType } from "./facilitator.js";
|
|
11
5
|
import {
|
|
12
|
-
type FacilitatorNetwork,
|
|
13
6
|
networkToChainId,
|
|
14
7
|
type RequestedPaymentPayload,
|
|
15
8
|
type RequestedPaymentRequirements,
|
|
@@ -54,9 +47,28 @@ export async function decodePaymentRequest(
|
|
|
54
47
|
errorMessages,
|
|
55
48
|
discoverable,
|
|
56
49
|
} = routeConfig;
|
|
50
|
+
|
|
51
|
+
let chainId: number;
|
|
52
|
+
try {
|
|
53
|
+
chainId = networkToChainId(network);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return {
|
|
56
|
+
status: 402,
|
|
57
|
+
responseHeaders: { "Content-Type": "application/json" },
|
|
58
|
+
responseBody: {
|
|
59
|
+
x402Version,
|
|
60
|
+
error:
|
|
61
|
+
error instanceof Error
|
|
62
|
+
? error.message
|
|
63
|
+
: `Invalid network: ${network}`,
|
|
64
|
+
accepts: [],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
const atomicAmountForAsset = await processPriceToAtomicAmount(
|
|
58
70
|
price,
|
|
59
|
-
|
|
71
|
+
chainId,
|
|
60
72
|
facilitator,
|
|
61
73
|
);
|
|
62
74
|
if ("error" in atomicAmountForAsset) {
|
|
@@ -74,45 +86,28 @@ export async function decodePaymentRequest(
|
|
|
74
86
|
|
|
75
87
|
const paymentRequirements: RequestedPaymentRequirements[] = [];
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
network
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
type: "http",
|
|
95
|
-
method,
|
|
96
|
-
discoverable: discoverable ?? true,
|
|
97
|
-
...inputSchema,
|
|
98
|
-
},
|
|
99
|
-
output: outputSchema,
|
|
100
|
-
},
|
|
101
|
-
extra: (asset as ERC20TokenAmount["asset"]).eip712,
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
return {
|
|
105
|
-
status: 402,
|
|
106
|
-
responseHeaders: {
|
|
107
|
-
"Content-Type": "application/json",
|
|
108
|
-
},
|
|
109
|
-
responseBody: {
|
|
110
|
-
x402Version,
|
|
111
|
-
error: `Unsupported network: ${network}`,
|
|
112
|
-
accepts: paymentRequirements,
|
|
89
|
+
paymentRequirements.push({
|
|
90
|
+
scheme: "exact",
|
|
91
|
+
network: `eip155:${chainId}`,
|
|
92
|
+
maxAmountRequired,
|
|
93
|
+
resource: resourceUrl,
|
|
94
|
+
description: description ?? "",
|
|
95
|
+
mimeType: mimeType ?? "application/json",
|
|
96
|
+
payTo: getAddress(payTo),
|
|
97
|
+
maxTimeoutSeconds: maxTimeoutSeconds ?? 300,
|
|
98
|
+
asset: getAddress(asset.address),
|
|
99
|
+
// TODO: Rename outputSchema to requestStructure
|
|
100
|
+
outputSchema: {
|
|
101
|
+
input: {
|
|
102
|
+
type: "http",
|
|
103
|
+
method,
|
|
104
|
+
discoverable: discoverable ?? true,
|
|
105
|
+
...inputSchema,
|
|
113
106
|
},
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
output: outputSchema,
|
|
108
|
+
},
|
|
109
|
+
extra: (asset as ERC20TokenAmount["asset"]).eip712,
|
|
110
|
+
});
|
|
116
111
|
|
|
117
112
|
// Check for payment header
|
|
118
113
|
if (!paymentData) {
|
|
@@ -188,7 +183,7 @@ export async function decodePaymentRequest(
|
|
|
188
183
|
*/
|
|
189
184
|
async function processPriceToAtomicAmount(
|
|
190
185
|
price: Money | ERC20TokenAmount,
|
|
191
|
-
|
|
186
|
+
chainId: number,
|
|
192
187
|
facilitator: ReturnType<typeof facilitatorType>,
|
|
193
188
|
): Promise<
|
|
194
189
|
| { maxAmountRequired: string; asset: ERC20TokenAmount["asset"] }
|
|
@@ -207,10 +202,10 @@ async function processPriceToAtomicAmount(
|
|
|
207
202
|
};
|
|
208
203
|
}
|
|
209
204
|
const parsedUsdAmount = parsedAmount.data;
|
|
210
|
-
const defaultAsset = await getDefaultAsset(
|
|
205
|
+
const defaultAsset = await getDefaultAsset(chainId, facilitator);
|
|
211
206
|
if (!defaultAsset) {
|
|
212
207
|
return {
|
|
213
|
-
error: `Unable to get default asset on ${
|
|
208
|
+
error: `Unable to get default asset on chain ${chainId}. Please specify an asset in the payment requirements.`,
|
|
214
209
|
};
|
|
215
210
|
}
|
|
216
211
|
asset = defaultAsset;
|
|
@@ -228,11 +223,10 @@ async function processPriceToAtomicAmount(
|
|
|
228
223
|
}
|
|
229
224
|
|
|
230
225
|
async function getDefaultAsset(
|
|
231
|
-
|
|
226
|
+
chainId: number,
|
|
232
227
|
facilitator: ReturnType<typeof facilitatorType>,
|
|
233
228
|
): Promise<ERC20TokenAmount["asset"] | undefined> {
|
|
234
229
|
const supportedAssets = await facilitator.supported();
|
|
235
|
-
const chainId = networkToChainId(network);
|
|
236
230
|
const matchingAsset = supportedAssets.kinds.find(
|
|
237
231
|
(supported) => supported.network === `eip155:${chainId}`,
|
|
238
232
|
);
|
package/src/x402/facilitator.ts
CHANGED
|
@@ -28,6 +28,7 @@ const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402";
|
|
|
28
28
|
* ```ts
|
|
29
29
|
* import { facilitator } from "thirdweb/x402";
|
|
30
30
|
* import { createThirdwebClient } from "thirdweb";
|
|
31
|
+
* import { paymentMiddleware } from 'x402-hono'
|
|
31
32
|
*
|
|
32
33
|
* const client = createThirdwebClient({
|
|
33
34
|
* secretKey: "your-secret-key",
|
|
@@ -84,7 +84,9 @@ export function wrapFetchWithPayment(
|
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
if (BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue) {
|
|
87
|
-
throw new Error(
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Payment amount exceeds maximum allowed (currently set to ${maxValue} in base units)`,
|
|
89
|
+
);
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
const paymentChainId = networkToChainId(
|
package/src/x402/schemas.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
SettleResponseSchema,
|
|
8
8
|
} from "x402/types";
|
|
9
9
|
import { z } from "zod";
|
|
10
|
+
import type { Chain } from "../chains/types.js";
|
|
10
11
|
|
|
11
12
|
const FacilitatorNetworkSchema = z.union([
|
|
12
13
|
z.literal("base-sepolia"),
|
|
@@ -55,7 +56,10 @@ export type FacilitatorSettleResponse = z.infer<
|
|
|
55
56
|
typeof FacilitatorSettleResponseSchema
|
|
56
57
|
>;
|
|
57
58
|
|
|
58
|
-
export function networkToChainId(network: string): number {
|
|
59
|
+
export function networkToChainId(network: string | Chain): number {
|
|
60
|
+
if (typeof network === "object") {
|
|
61
|
+
return network.id;
|
|
62
|
+
}
|
|
59
63
|
if (network.startsWith("eip155:")) {
|
|
60
64
|
const chainId = parseInt(network.split(":")[1] ?? "0");
|
|
61
65
|
if (!Number.isNaN(chainId) && chainId > 0) {
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
* // Usage in a Next.js API route
|
|
26
26
|
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
27
27
|
* import { createThirdwebClient } from "thirdweb";
|
|
28
|
+
* import { arbitrumSepolia } from "thirdweb/chains";
|
|
28
29
|
*
|
|
29
30
|
* const client = createThirdwebClient({
|
|
30
31
|
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
@@ -44,7 +45,7 @@ import {
|
|
|
44
45
|
* method: "GET",
|
|
45
46
|
* paymentData,
|
|
46
47
|
* payTo: "0x1234567890123456789012345678901234567890",
|
|
47
|
-
* network:
|
|
48
|
+
* network: arbitrumSepolia, // or any other chain
|
|
48
49
|
* price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
|
|
49
50
|
* facilitator: thirdwebFacilitator,
|
|
50
51
|
* routeConfig: {
|
|
@@ -74,6 +75,7 @@ import {
|
|
|
74
75
|
* import express from "express";
|
|
75
76
|
* import { settlePayment, facilitator } from "thirdweb/x402";
|
|
76
77
|
* import { createThirdwebClient } from "thirdweb";
|
|
78
|
+
* import { arbitrumSepolia } from "thirdweb/chains";
|
|
77
79
|
*
|
|
78
80
|
* const client = createThirdwebClient({
|
|
79
81
|
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
@@ -93,7 +95,7 @@ import {
|
|
|
93
95
|
* method: req.method,
|
|
94
96
|
* paymentData: req.headers["x-payment"],
|
|
95
97
|
* payTo: "0x1234567890123456789012345678901234567890",
|
|
96
|
-
* network:
|
|
98
|
+
* network: arbitrumSepolia, // or any other chain
|
|
97
99
|
* price: "$0.05",
|
|
98
100
|
* facilitator: thirdwebFacilitator,
|
|
99
101
|
* });
|
|
@@ -136,7 +138,6 @@ export async function settlePayment(
|
|
|
136
138
|
const { selectedPaymentRequirements, decodedPayment, paymentRequirements } =
|
|
137
139
|
decodePaymentResult;
|
|
138
140
|
|
|
139
|
-
// Settle payment
|
|
140
141
|
try {
|
|
141
142
|
const settlement = await facilitator.settle(
|
|
142
143
|
decodedPayment,
|
package/src/x402/types.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
Money,
|
|
4
4
|
PaymentMiddlewareConfig,
|
|
5
5
|
} from "x402/types";
|
|
6
|
+
import type { Chain } from "../chains/types.js";
|
|
6
7
|
import type { Address } from "../utils/address.js";
|
|
7
8
|
import type { Prettify } from "../utils/type-utils.js";
|
|
8
9
|
import type { facilitator as facilitatorType } from "./facilitator.js";
|
|
@@ -30,7 +31,7 @@ export type PaymentArgs = {
|
|
|
30
31
|
/** The wallet address that should receive the payment */
|
|
31
32
|
payTo: Address;
|
|
32
33
|
/** The blockchain network where the payment should be processed */
|
|
33
|
-
network: FacilitatorNetwork;
|
|
34
|
+
network: FacilitatorNetwork | Chain;
|
|
34
35
|
/** The price for accessing the resource - either a USD amount (e.g., "$0.10") or a specific token amount */
|
|
35
36
|
price: Money | ERC20TokenAmount;
|
|
36
37
|
/** The payment facilitator instance used to verify and settle payments */
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
* // Usage in a Next.js API route
|
|
18
18
|
* import { verifyPayment, facilitator } from "thirdweb/x402";
|
|
19
19
|
* import { createThirdwebClient } from "thirdweb";
|
|
20
|
+
* import { arbitrumSepolia } from "thirdweb/chains";
|
|
20
21
|
*
|
|
21
22
|
* const client = createThirdwebClient({
|
|
22
23
|
* secretKey: process.env.THIRDWEB_SECRET_KEY,
|
|
@@ -35,7 +36,7 @@ import {
|
|
|
35
36
|
* method: "GET",
|
|
36
37
|
* paymentData,
|
|
37
38
|
* payTo: "0x1234567890123456789012345678901234567890",
|
|
38
|
-
* network:
|
|
39
|
+
* network: arbitrumSepolia, // or any other chain
|
|
39
40
|
* price: "$0.10", // or { amount: "100000", asset: { address: "0x...", decimals: 6 } }
|
|
40
41
|
* facilitator: thirdwebFacilitator,
|
|
41
42
|
* routeConfig: {
|