Skip to content

fix(coinpayportal): add coin.chain fallback to coinToPaymentCurrency#291

Closed
emil07770 wants to merge 1 commit into
profullstack:masterfrom
emil07770:patch-2
Closed

fix(coinpayportal): add coin.chain fallback to coinToPaymentCurrency#291
emil07770 wants to merge 1 commit into
profullstack:masterfrom
emil07770:patch-2

Conversation

@emil07770
Copy link
Copy Markdown
Contributor

CoinPay's /api/oauth/userinfo returns wallets as {address, chain: "SOL"} (not symbol). The symbol computation in coinToPaymentCurrency never checked coin.chain, so SOL wallets were never recognized and invoices failed with "Select a CoinPay receiving wallet" error.

CoinPay's /api/oauth/userinfo returns wallets as {address, chain: "SOL"} (not symbol). The symbol computation in coinToPaymentCurrency never checked coin.chain, so SOL wallets were never recognized and invoices failed with "Select a CoinPay receiving wallet" error.
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 28, 2026

Greptile Summary

This PR fixes a bug where SOL wallets returned by CoinPay's /api/oauth/userinfo endpoint — shaped as {address, chain: "SOL"} with no symbol field — were not recognized by coinToPaymentCurrency, causing invoices to fail with "Select a CoinPay receiving wallet". The fix adds coin.chain as the last fallback in the symbol OR-chain, so a wallet carrying only a chain identifier is now matched correctly.

  • Two-line change in coinToPaymentCurrency: normalizeCoinSymbol(coin.chain) is appended as the fifth fallback for the symbol variable, after coin.id. It is only reached when all of symbol, code, currency, and id are absent.
  • No impact on multi-token chains (USDT/USDC): For those coins the symbol field must already be set to "USDT"/"USDC" for correct chain disambiguation; the new fallback does not interfere with that logic because coin.chain is only consulted when the primary identifiers are all empty.

Confidence Score: 4/5

The change is a minimal, well-targeted fallback that resolves the stated SOL wallet recognition failure; safe to merge for native-coin wallets.

The two-line fix works correctly for any wallet where the only identifier is coin.chain and that chain maps directly to a single currency (SOL, ETH, BTC, POL). The one open question is whether the CoinPay userinfo endpoint also returns USDC/USDT wallets with only a chain field and no token symbol — if it does, those wallets would be mis-mapped to the native coin currency (e.g., "sol" instead of "usdc_sol"). Whether that edge case actually occurs depends on CoinPay API behaviour that cannot be confirmed from the code alone.

Only src/lib/coinpayportal.ts was changed; focus review on whether multi-token Solana/Polygon wallets from the userinfo endpoint carry a token symbol field alongside chain.

Important Files Changed

Filename Overview
src/lib/coinpayportal.ts Adds coin.chain as a final fallback for the symbol computation in coinToPaymentCurrency, fixing SOL wallet recognition when only {address, chain} is returned from the OAuth userinfo endpoint.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["coinToPaymentCurrency(coin)"] --> B["Check directCurrency\n(coin.currency, coin.id, coin.code)"]
    B -- "Match in SUPPORTED_CURRENCIES" --> C["Return matched SupportedCurrency"]
    B -- "No match" --> D["Compute symbol\ncoin.symbol || coin.code ||\ncoin.currency || coin.id\n|| coin.chain ← NEW"]
    D --> E["Compute chain\ncoin.chain || coin.network\n|| coin.blockchain"]
    E --> F{symbol?}
    F -- "BTC/BCH/ETH/POL/SOL" --> G["Return single-asset currency\ne.g. 'sol', 'eth'"]
    F -- "USDT" --> H{"chain?\nPOL / SOL / ETH"}
    H --> I["Return 'usdt_pol' / 'usdt_sol' / 'usdt_eth' / 'usdt'"]
    F -- "USDC" --> J{"chain?\nPOL / ETH"}
    J --> K["Return 'usdc_pol' / 'usdc_eth' / 'usdc_sol'"]
    F -- "no match" --> L["Return null"]
Loading

Comments Outside Diff (1)

  1. src/lib/coinpayportal.ts, line 280-289 (link)

    P2 USDC/USDT wallet on Solana identified only by chain will resolve to "sol"

    When the userinfo payload returns a USDC-on-Solana wallet as {address: "...", chain: "SOL"} (no symbol, code, currency, or id fields), the new fallback sets symbol = "SOL". The function then hits if (symbol === "SOL") return "sol" before ever reaching the USDC branch, so the wallet is returned as the native-SOL currency instead of "usdc_sol". If CoinPay only uses chain (not also a token symbol) to describe USDC/USDT wallets, those wallets will still be silently misclassified after this fix.

Reviews (1): Last reviewed commit: "fix(coinpayportal): add coin.chain fallb..." | Re-trigger Greptile

@ralyodio ralyodio closed this May 29, 2026
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.

2 participants