Skip to content

fix(coinpay): map OAuth wallet cryptocurrency chains - #311

Closed
Jorel97 wants to merge 2 commits into
profullstack:masterfrom
Jorel97:codex/fix-coinpay-oauth-chain-301
Closed

fix(coinpay): map OAuth wallet cryptocurrency chains#311
Jorel97 wants to merge 2 commits into
profullstack:masterfrom
Jorel97:codex/fix-coinpay-oauth-chain-301

Conversation

@Jorel97

@Jorel97 Jorel97 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #301.

CoinPay OAuth /api/oauth/userinfo wallet payloads can identify a wallet with cryptocurrency plus chain fields, for example { cryptocurrency: "USDC", chain: "POL" }. coinToPaymentCurrency already understood chain, but did not consider cryptocurrency as the coin symbol source, so those wallets could fail to map to usdc_pol, usdt_eth, etc.

Changes:

  • add cryptocurrency to the SupportedCoin shape
  • consider coin.cryptocurrency when deriving the normalized symbol
  • add regression coverage for USDC/POL, USDT/ETH, and SOL/SOL

Verification: local dependency checkout is not available here, so I did a targeted static inspection rather than running the full Vitest suite.

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes OAuth wallet payload mapping in coinToPaymentCurrency by recognising the cryptocurrency field that CoinPay sends alongside chain in /api/oauth/userinfo wallet objects. The change is minimal and follows the existing fallback pattern precisely.

  • cryptocurrency?: string is added to the SupportedCoin interface as an optional field, matching all other coin-descriptor fields in the same block.
  • normalizeCoinSymbol(coin.cryptocurrency) is inserted into the symbol-derivation chain after coin.currency and before coin.id, so it acts as a fallback only when the earlier, higher-priority fields are absent — exactly the case for OAuth wallet payloads.
  • Three new direct unit tests (USDC/POL, USDT/ETH, SOL/SOL) verify the described fix end-to-end.

Confidence Score: 5/5

Safe to merge — the change is a one-line addition to an existing fallback chain with no impact on the existing symbol-resolution priority order.

The fix is narrow: a single new optional interface field and one extra || fallback in the symbol-derivation chain. normalizeCoinSymbol returns an empty string for absent fields, so inserting cryptocurrency between currency and id only activates when the earlier fields are all undefined — precisely the OAuth wallet payload shape described. The three new tests directly exercise the corrected paths and all trace correctly through the implementation.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/coinpayportal.ts Adds cryptocurrency to SupportedCoin interface and inserts it into the symbol lookup fallback chain in coinToPaymentCurrency, correctly after currency and before id.
src/lib/coinpayportal.test.ts Imports coinToPaymentCurrency for direct testing and adds three regression cases covering USDC/POL, USDT/ETH, and SOL/SOL OAuth wallet payloads.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["coinToPaymentCurrency(coin)"] --> B["Try directCurrency\ncoin.currency / coin.id / coin.code\nnormalizeCurrencyKey → lowercase"]
    B --> C{isSupportedCurrency?}
    C -- Yes --> D["return SupportedCurrency"]
    C -- No --> E["Derive symbol\ncoin.symbol → coin.code → coin.currency\n→ coin.cryptocurrency ← NEW\n→ coin.id\nnormalizeCoinSymbol → UPPERCASE"]
    E --> F["Derive chain\ncoin.chain → coin.network → coin.blockchain"]
    F --> G{symbol?}
    G -- "BTC/BCH/ETH/POL/SOL" --> H["return simple key"]
    G -- "USDT" --> I{chain?}
    I -- "POL/POLYGON/MATIC" --> J["usdt_pol"]
    I -- "SOL/SOLANA" --> K["usdt_sol"]
    I -- "ETH/ETHEREUM" --> L["usdt_eth"]
    I -- other --> M["usdt"]
    G -- "USDC" --> N{chain?}
    N -- "POL/POLYGON/MATIC" --> O["usdc_pol"]
    N -- "ETH/ETHEREUM" --> P["usdc_eth"]
    N -- other --> Q["usdc_sol"]
    G -- no match --> R["return null"]
Loading

Reviews (1): Last reviewed commit: "test(coinpay): cover oauth cryptocurrenc..." | Re-trigger Greptile

@ralyodio

Copy link
Copy Markdown
Contributor

@Jorel97 plesae resolve conflicts

@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.

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

2 participants