-
Notifications
You must be signed in to change notification settings - Fork 47
fix(invoice): auto-select worker's coinpay wallet when poster creates invoice #482
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
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 |
|---|---|---|
|
|
@@ -234,12 +234,19 @@ | |
|
|
||
| setIsCreating(true); | ||
| setError(null); | ||
| const selectedWallet = | ||
| wallets.find((wallet) => walletKey(wallet) === selectedWalletKey) || null; | ||
| if (!selectedWallet) { | ||
| setError("Select a CoinPay receiving wallet"); | ||
| setIsCreating(false); | ||
| return; | ||
| let selectedWalletCurrency: string | undefined; | ||
| let selectedWalletAddress: string | undefined; | ||
|
|
||
| if (isWorker) { | ||
| const selectedWallet = | ||
| wallets.find((wallet) => walletKey(wallet) === selectedWalletKey) || null; | ||
| if (!selectedWallet) { | ||
| setError("Select a CoinPay receiving wallet"); | ||
| setIsCreating(false); | ||
| return; | ||
| } | ||
| selectedWalletCurrency = selectedWallet.currency; | ||
| selectedWalletAddress = selectedWallet.address; | ||
| } | ||
|
|
||
| try { | ||
|
|
@@ -251,8 +258,8 @@ | |
| items: lineItems, | ||
| amount: total, | ||
| currency: "USD", | ||
| payment_currency: selectedWallet.currency, | ||
| merchant_wallet_address: selectedWallet.address, | ||
| payment_currency: selectedWalletCurrency, | ||
| merchant_wallet_address: selectedWalletAddress, | ||
| notes: notes || undefined, | ||
| due_date: dueDate || undefined, | ||
| pr_links: prLinks.length > 0 ? prLinks : undefined, | ||
|
|
@@ -844,7 +851,8 @@ | |
| /> | ||
| </div> | ||
|
|
||
| <div className="space-y-2 rounded-md border border-border bg-background p-3"> | ||
| {isWorker && ( | ||
| <div className="space-y-2 rounded-md border border-border bg-background p-3"> | ||
| <div className="flex items-center justify-between gap-3"> | ||
| <label className="text-xs font-medium text-muted-foreground"> | ||
| CoinPay receiving wallet | ||
|
|
@@ -906,14 +914,15 @@ | |
| )} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| {error && <p className="text-sm text-destructive">{error}</p>} | ||
|
|
||
| <div className="flex gap-2"> | ||
| <Button | ||
| onClick={onSubmit} | ||
| disabled={isCreating || total <= 0 || overCap || !hasWallets} | ||
| disabled={isCreating || total <= 0 || overCap || (isWorker && !hasWallets)} | ||
|
Comment on lines
854
to
+925
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.
|
||
| className="flex-1" | ||
| size="sm" | ||
| > | ||
|
|
||
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.
When
payment_currency/merchant_wallet_addressare absent (poster-initiated flow), the backend looks up the worker's wallet withw.currency === gigCoinusing strict equality. The frontendwalletMatchesCoinhelper uses a broader rule: it also accepts currencies whose key starts with${want}_(e.g."usdc_sol"matches gig coin"USDC"). IfpreferredCoinToPaymentCurrencymaps"USDC"to a canonical key that differs from the wallet's.currencyfield, the.find()silently fails and the code falls back toworkerWallets[0], which could be a completely different coin. The poster then creates a CoinPay invoice denominated in the wrong currency without any warning.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!