-
Notifications
You must be signed in to change notification settings - Fork 619
[SDK] Fix: Skip payment method selection when balance is sufficient #7813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
83a84d1
ac18def
3c1cdeb
4fdccea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "thirdweb": patch | ||
| --- | ||
|
|
||
| Skips payment selection in the TransactionWidget if the user's balance is sufficient to complete the transaction. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import { useChainMetadata } from "../../../core/hooks/others/useChainQuery.js"; | |
| import { useTransactionDetails } from "../../../core/hooks/useTransactionDetails.js"; | ||
| import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js"; | ||
| import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js"; | ||
| import type { PaymentMachineEvent } from "../../../core/machines/paymentMachine.js"; | ||
| import { ConnectButton } from "../ConnectWallet/ConnectButton.js"; | ||
| import { PoweredByThirdweb } from "../ConnectWallet/PoweredByTW.js"; | ||
| import { Container, Line } from "../components/basic.js"; | ||
|
|
@@ -48,6 +49,11 @@ export interface TransactionPaymentProps { | |
| */ | ||
| onContinue: (amount: string, token: Token, receiverAddress: Address) => void; | ||
|
|
||
| /** | ||
| * Send arbitrary payment events for UI flow control | ||
| */ | ||
| sendEvent: (event: PaymentMachineEvent) => void; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @greg the components should not be aware of the state machine. This should just be a 'executrTx' function and the orchestrator is the one that sends state machine events Otherwise this opens up for the next contributor to just bypass the whole structure we have in place. Slippery slope |
||
|
|
||
| /** | ||
| * Connect options for wallet connection | ||
| */ | ||
|
|
@@ -64,6 +70,7 @@ export function TransactionPayment({ | |
| uiOptions, | ||
| client, | ||
| onContinue, | ||
| sendEvent, | ||
| connectOptions, | ||
| showThirdwebBranding = true, | ||
| }: TransactionPaymentProps) { | ||
|
|
@@ -378,6 +385,18 @@ export function TransactionPayment({ | |
| return; | ||
| } | ||
|
|
||
| // If the user has enough to pay, skip the payment step altogether | ||
| if ( | ||
| userBalance && | ||
| Number(userBalance) >= | ||
| Number(transactionDataQuery.data.totalCost) | ||
| ) { | ||
| sendEvent({ | ||
| type: "CONTINUE_TO_TRANSACTION", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // otherwise, use the full transaction cost | ||
| onContinue( | ||
| transactionDataQuery.data.totalCost, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be exported