Skip to content

Commit 271840e

Browse files
committed
lint
1 parent 1cc003d commit 271840e

31 files changed

+178
-204
lines changed

apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { cn } from "../../../../lib/utils";
1818
import { CollapsibleSection } from "../../sign-in/components/CollapsibleSection";
1919
import { ColorFormGroup } from "../../sign-in/components/ColorFormGroup";
2020
import type { BridgeComponentsPlaygroundOptions } from "../components/types";
21+
import { Address, isAddress } from "thirdweb";
2122

2223
export function LeftSection(props: {
2324
options: BridgeComponentsPlaygroundOptions;
@@ -134,8 +135,20 @@ export function LeftSection(props: {
134135
<Input
135136
id="token-address"
136137
placeholder="0x..."
137-
value={tokenAddress}
138-
onChange={(e) => setTokenAddress(e.target.value)}
138+
value={payOptions.buyTokenAddress}
139+
onChange={(e) => {
140+
const addressCheck = isAddress(e.target.value);
141+
if (!addressCheck) {
142+
return;
143+
}
144+
setOptions((v) => ({
145+
...v,
146+
payOptions: {
147+
...v.payOptions,
148+
buyTokenAddress: e.target.value as Address,
149+
},
150+
}));
151+
}}
139152
className={cn("bg-card")}
140153
/>
141154
</div>
@@ -155,15 +168,19 @@ export function LeftSection(props: {
155168
placeholder="0x..."
156169
className="bg-card"
157170
value={payOptions.sellerAddress || ""}
158-
onChange={(e) =>
171+
onChange={(e) => {
172+
const addressCheck = isAddress(e.target.value);
173+
if (!addressCheck) {
174+
return;
175+
}
159176
setOptions((v) => ({
160177
...v,
161178
payOptions: {
162179
...v.payOptions,
163-
sellerAddress: e.target.value,
180+
sellerAddress: e.target.value as Address,
164181
},
165-
}))
166-
}
182+
}));
183+
}}
167184
/>
168185
</div>
169186

apps/playground-web/src/app/connect/pay/embed/RightSection.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
22
import { usePathname } from "next/navigation";
33
import { useState } from "react";
4-
import { type Address, getContract, toWei } from "thirdweb";
5-
import { arbitrum, base } from "thirdweb/chains";
4+
import { getContract, toUnits } from "thirdweb";
5+
import { base } from "thirdweb/chains";
66
import { claimTo } from "thirdweb/extensions/erc1155";
77
import {
88
BuyWidget,
@@ -17,6 +17,8 @@ import { THIRDWEB_CLIENT } from "../../../../lib/client";
1717
import { cn } from "../../../../lib/utils";
1818
import { CodeGen } from "../components/CodeGen";
1919
import type { BridgeComponentsPlaygroundOptions } from "../components/types";
20+
import { useQuery } from "@tanstack/react-query";
21+
import { getCurrencyMetadata } from "thirdweb/extensions/erc20";
2022

2123
const nftContract = getContract({
2224
address: "0xf0d0CBf84005Dd4eC81364D1f5D7d896Bd53D1B8",
@@ -41,6 +43,18 @@ export function RightSection(props: {
4143
}
4244

4345
const account = useActiveAccount();
46+
const { data: tokenData } = useQuery({
47+
queryKey: ["token", props.options.payOptions.buyTokenAddress],
48+
queryFn: () =>
49+
getCurrencyMetadata({
50+
contract: getContract({
51+
address: props.options.payOptions.buyTokenAddress,
52+
chain: props.options.payOptions.buyTokenChain,
53+
client: THIRDWEB_CLIENT,
54+
}),
55+
}),
56+
enabled: !!props.options.payOptions.buyTokenAddress,
57+
});
4458

4559
const themeObj =
4660
props.options.theme.type === "dark"
@@ -60,7 +74,10 @@ export function RightSection(props: {
6074
title={props.options.payOptions.title}
6175
tokenAddress={props.options.payOptions.buyTokenAddress}
6276
chain={props.options.payOptions.buyTokenChain}
63-
amount={toWei(props.options.payOptions.buyTokenAmount)}
77+
amount={toUnits(
78+
props.options.payOptions.buyTokenAmount,
79+
tokenData?.decimals || 18,
80+
)}
6481
/>
6582
);
6683
}
@@ -73,7 +90,10 @@ export function RightSection(props: {
7390
name={props.options.payOptions.title}
7491
tokenAddress={props.options.payOptions.buyTokenAddress}
7592
chain={props.options.payOptions.buyTokenChain}
76-
amount={toWei(props.options.payOptions.buyTokenAmount)}
93+
amount={toUnits(
94+
props.options.payOptions.buyTokenAmount,
95+
tokenData?.decimals || 18,
96+
)}
7797
seller={props.options.payOptions.sellerAddress}
7898
presetOptions={[1, 2, 3]}
7999
purchaseData={{

packages/thirdweb/src/exports/react.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ export {
142142
TransactionWidget,
143143
type TransactionWidgetProps,
144144
} from "../react/web/ui/Bridge/TransactionWidget.js";
145+
export {
146+
useBridgeRoutes,
147+
type UseBridgeRoutesParams,
148+
} from "../react/core/hooks/useBridgeRoutes.js";
145149
export {
146150
PayEmbed,
147151
type PayEmbedProps,

packages/thirdweb/src/react/core/hooks/useBridgeQuote.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function useBridgeQuote({
3838
// if ssame token and chain, use transfer
3939
if (
4040
checksumAddress(originToken.address) ===
41-
checksumAddress(destinationToken.address) &&
41+
checksumAddress(destinationToken.address) &&
4242
originToken.chainId === destinationToken.chainId
4343
) {
4444
const transfer = await Transfer.prepare({
@@ -51,8 +51,6 @@ export function useBridgeQuote({
5151
});
5252
return transfer;
5353
}
54-
55-
console.log("AMOUNT", destinationAmount);
5654
const quote = await Buy.quote({
5755
originChainId: originToken.chainId,
5856
originTokenAddress: originToken.address,

packages/thirdweb/src/react/core/hooks/useStepExecutor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useQuery } from "@tanstack/react-query";
12
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
23
import type { status as OnrampStatus } from "../../../bridge/OnrampStatus.js";
34
import { ApiError } from "../../../bridge/types/Errors.js";
@@ -9,15 +10,14 @@ import type { Status } from "../../../bridge/types/Status.js";
910
import { getCachedChain } from "../../../chains/utils.js";
1011
import type { ThirdwebClient } from "../../../client/client.js";
1112
import { waitForReceipt } from "../../../transaction/actions/wait-for-tx-receipt.js";
13+
import { stringify } from "../../../utils/json.js";
1214
import type { Account, Wallet } from "../../../wallets/interfaces/wallet.js";
1315
import type { WindowAdapter } from "../adapters/WindowAdapter.js";
1416
import {
15-
useBridgePrepare,
1617
type BridgePrepareRequest,
1718
type BridgePrepareResult,
19+
useBridgePrepare,
1820
} from "./useBridgePrepare.js";
19-
import { useQuery } from "@tanstack/react-query";
20-
import { stringify } from "../../../utils/json.js";
2121

2222
/**
2323
* Type for completed status results from Bridge.status and Onramp.status
@@ -27,9 +27,9 @@ export type CompletedStatusResult =
2727
| ({ type: "sell" } & Extract<Status, { status: "COMPLETED" }>)
2828
| ({ type: "transfer" } & Extract<Status, { status: "COMPLETED" }>)
2929
| ({ type: "onramp" } & Extract<
30-
OnrampStatus.Result,
31-
{ status: "COMPLETED" }
32-
>);
30+
OnrampStatus.Result,
31+
{ status: "COMPLETED" }
32+
>);
3333

3434
/**
3535
* Options for the step executor hook

packages/thirdweb/src/react/core/hooks/wallets/useAutoConnectCore.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe("useAutoConnectCore", () => {
125125
{
126126
wallets: [wallet],
127127
client: TEST_CLIENT,
128-
onTimeout: () => console.info("TIMEOUTTED"),
128+
onTimeout: () => {},
129129
timeout: 0,
130130
},
131131
(id: WalletId) =>

packages/thirdweb/src/react/core/machines/paymentMachine.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import type { Address } from "../../../utils/address.js";
44
import type { AsyncStorage } from "../../../utils/storage/AsyncStorage.js";
55
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
66
import type { WindowAdapter } from "../adapters/WindowAdapter.js";
7-
import type { CompletedStatusResult } from "../hooks/useStepExecutor.js";
87
import type {
98
BridgePrepareRequest,
109
BridgePrepareResult,
1110
} from "../hooks/useBridgePrepare.js";
11+
import type { CompletedStatusResult } from "../hooks/useStepExecutor.js";
1212

1313
/**
1414
* Payment modes supported by BridgeEmbed
@@ -20,17 +20,17 @@ export type PaymentMode = "fund_wallet" | "direct_payment" | "transaction";
2020
*/
2121
export type PaymentMethod =
2222
| {
23-
type: "wallet";
24-
payerWallet: Wallet;
25-
originToken: Token;
26-
balance: bigint;
27-
}
23+
type: "wallet";
24+
payerWallet: Wallet;
25+
originToken: Token;
26+
balance: bigint;
27+
}
2828
| {
29-
type: "fiat";
30-
payerWallet: Wallet;
31-
currency: string;
32-
onramp: "stripe" | "coinbase" | "transak";
33-
};
29+
type: "fiat";
30+
payerWallet: Wallet;
31+
currency: string;
32+
onramp: "stripe" | "coinbase" | "transak";
33+
};
3434

3535
/**
3636
* Payment machine context - holds all flow state data
@@ -70,17 +70,17 @@ export interface PaymentMachineContext {
7070
*/
7171
export type PaymentMachineEvent =
7272
| {
73-
type: "DESTINATION_CONFIRMED";
74-
destinationToken: Token;
75-
destinationAmount: string;
76-
receiverAddress: Address;
77-
}
73+
type: "DESTINATION_CONFIRMED";
74+
destinationToken: Token;
75+
destinationAmount: string;
76+
receiverAddress: Address;
77+
}
7878
| { type: "PAYMENT_METHOD_SELECTED"; paymentMethod: PaymentMethod }
7979
| {
80-
type: "QUOTE_RECEIVED";
81-
quote: BridgePrepareResult;
82-
request: BridgePrepareRequest;
83-
}
80+
type: "QUOTE_RECEIVED";
81+
quote: BridgePrepareResult;
82+
request: BridgePrepareRequest;
83+
}
8484
| { type: "ROUTE_CONFIRMED" }
8585
| { type: "EXECUTION_COMPLETE"; completedStatuses: CompletedStatusResult[] }
8686
| { type: "ERROR_OCCURRED"; error: Error }

packages/thirdweb/src/react/core/utils/persist.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export async function saveSnapshot(
4242
completedStatuses: context.completedStatuses,
4343
currentError: context.currentError
4444
? {
45-
name: context.currentError.name,
46-
message: context.currentError.message,
47-
stack: context.currentError.stack,
48-
}
45+
name: context.currentError.name,
46+
message: context.currentError.message,
47+
stack: context.currentError.stack,
48+
}
4949
: undefined,
5050
retryState: context.retryState,
5151
},

0 commit comments

Comments
 (0)