fix(coinpay): read wallets whose chain field is a composite key like USDC_POL - #506
Open
clawedassistant26 wants to merge 1 commit into
Open
Conversation
CoinPayPortal's OIDC userinfo `wallets` claim returns one composite token
that names both the coin and its chain:
{ address: "0x...", chain: "USDC_POL", label, business_id }
coinToPaymentCurrency only understood a bare symbol ("USDC") plus a
separate chain ("POL"). It read "USDC_POL" into the symbol slot, matched
no branch and returned null, so normalizeGlobalWallets dropped every
wallet. Connected users saw wallets: [] with oauth_required: false and
could never send an invoice, even with active global wallet addresses on
CoinPay.
Resolve a composite identifier first, and split a symbol that carries its
own chain suffix ("USDC-POLYGON") so it still lands on the right branch.
The bare symbol plus separate chain shape from /api/get-tokens is
unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A user who has connected CoinPay with the
wallet:readscope, and who has active Global Wallet Addresses on CoinPayPortal, still gets an empty wallet list from ugig:oauth_required: falseshows the OAuth grant is fine, so the setup instructions ugig returns ("connect your CoinPay account", "paste those addresses into Settings > Global Wallet Addresses") send the user round a loop they cannot escape. Invoicing is blocked because the invoice route gates onworkerWallets.length === 0.Cause
getCoinpayGlobalWalletTokensreads wallets from CoinPayPortal's OIDC/api/oauth/userinfo. That endpoint returns each wallet as:{ "address": "0x...", "chain": "USDC_POL", "label": "...", "business_id": "..." }One composite token,
USDC_POL, names both the coin and its chain.coinToPaymentCurrencyonly handles a bare symbol plus a separate chain field:directCurrencylooks atcurrency,idandcode, none of which are present, so it is empty.symbolfalls through tocoin.chainand becomes"USDC_POL", which matches none of theBTC/ETH/USDT/USDCbranches.null, sonormalizeGlobalWalletshitsif (!currency || !address) continueand drops every wallet.The same shape appears in the
cryptocurrencycolumn ofmerchant_walletsandbusiness_wallets, so anything reading those rows directly is affected too. This became visible to more users after coinpayportal#197, which made userinfo return business wallets as well as account ones.Fix
compositeCurrencyKeyresolves an identifier that is already a supported currency key containing an underscore (usdc_pol,usdt_pol,usdc_eth, ...). A composite match wins over a bare symbol found elsewhere on the record, because it carries the chain too.cryptocurrency, and splits a symbol that carries its own chain suffix, soUSDC-POLYGONandUSDT_ETHEREUMresolve through the existing branches.{ symbol: "USDT", chain: "POL" }shape returned by/api/get-tokensis unchanged: a bare symbol splits to itself with no chain parts.Tests
Added to
src/lib/coinpayportal.test.ts:coinToPaymentCurrencyresolves composite tokens, still resolves the bare symbol plus chain shape, splits a suffixed symbol, and returnsnullwhen nothing identifies the coin.getCoinpayGlobalWalletTokensnormalizes a real userinfo payload into["usdc_pol", "usdt_pol"], and still drops a wallet whose address fails validation for its chain.The three new failing assertions reproduce the bug on
masterbefore the change (expected [] to deeply equal [ 'usdc_pol', 'usdt_pol' ]).Full suite after the change: 1803 tests across 197 files pass, and
tsc --noEmitis clean.