Skip to content

fix(coinpay): map coin.chain field in coinToPaymentCurrency - #304

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
emil07770:patch-3
May 29, 2026
Merged

fix(coinpay): map coin.chain field in coinToPaymentCurrency#304
ralyodio merged 1 commit into
profullstack:masterfrom
emil07770:patch-3

Conversation

@emil07770

Copy link
Copy Markdown
Contributor

CoinPay OAuth userinfo returns wallets as { address, chain: "BTC" } but coinToPaymentCurrency() only checks coin.symbol/code/currency/id — never coin.chain. This causes the symbol to be empty and the wallet to be dropped, resulting in workerWallets = [] and the 409 error when creating invoices.

Fix: include coin.chain in the symbol lookup so { chain: "BTC" } correctly maps to "btc".

Fixes #301

CoinPay OAuth userinfo returns wallets as { address, chain: "BTC" } but coinToPaymentCurrency() only checks coin.symbol/code/currency/id — never coin.chain. This causes the symbol to be empty and the wallet to be dropped, resulting in workerWallets = [] and the 409 error when creating invoices.

Fix: include coin.chain in the symbol lookup so { chain: "BTC" } correctly maps to "btc".

Fixes profullstack#301
@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug where coinToPaymentCurrency() returned null for wallets returned by the CoinPay OAuth userinfo endpoint in the shape { address, chain: "BTC" }, because the symbol-lookup chain only checked coin.symbol, coin.code, coin.currency, and coin.id — never coin.chain. As a result, such wallets were silently dropped (workerWallets = []), causing 409 errors during invoice creation.

  • Adds coin.chain as a final fallback in the symbol variable assignment inside coinToPaymentCurrency, so { chain: "BTC" } now correctly resolves to "btc".
  • The chain variable (used for USDT/USDC network disambiguation) already read from coin.chain; only the symbol lookup was missing it.

Confidence Score: 4/5

Safe to merge — the change is a one-line, well-scoped addition to an existing fallback chain with no side effects on paths that already have a symbol/code/currency/id.

The fix correctly addresses the described bug: BTC/ETH/SOL wallets returned with only a chain field will now resolve to the right currency. The only open question is whether USDT/USDC wallets from the same endpoint always carry an explicit symbol, which would make the coin.chain fallback safe for all cases; if not, a USDT-on-ETH wallet could silently mis-map to the native "eth" currency instead of a USDT variant.

src/lib/coinpayportal.ts — specifically the USDT/USDC chain-disambiguation branches that follow the updated symbol lookup.

Important Files Changed

Filename Overview
src/lib/coinpayportal.ts Adds coin.chain as a final fallback in the symbol lookup within coinToPaymentCurrency, fixing the case where CoinPay OAuth returns wallets with only a chain field (e.g. { address, chain: "BTC" }). The change is minimal and correctly scoped.

Comments Outside Diff (1)

  1. src/lib/coinpayportal.ts, line 284-304 (link)

    P2 Chain-as-symbol ambiguity for multi-token chains

    When coin.chain is the sole identifier and represents a generic chain (e.g. "ETH" or "SOL"), the function now maps it to a native-coin entry ("eth" or "sol"). For BTC wallets this is correct, but if CoinPay ever returns a USDT-on-ETH wallet without a symbol field — only { address, chain: "ETH" } — the fallback would silently resolve to "eth" instead of a usdt_* variant. Worth confirming with the CoinPay OAuth userinfo spec that USDT/USDC wallets always carry an explicit symbol (or equivalent) field, so the chain-fallback path is only exercised for single-asset chains like BTC.

Reviews (1): Last reviewed commit: "fix(coinpay): map coin.chain field in co..." | Re-trigger Greptile

@emil07770

Copy link
Copy Markdown
Contributor Author

@ralyodio this is blocking all workers from sending invoices on ugig.net right now. The Greptile review scores it 4/5 "Safe to merge" and Socket Security passed. One-line fix, no conflicts. Could you merge this urgently? Workers have completed gigs but cannot get paid due to this bug.

@ralyodio

Copy link
Copy Markdown
Contributor

what is coin.chain?

@ralyodio
ralyodio merged commit 7b98a05 into profullstack:master May 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(coinpay): coinToPaymentCurrency does not map chain field from CoinPay OAuth userinfo

2 participants