Add new parseLink and encodePayLink methods#680
Conversation
src/core/currency/uri-tools.ts
Outdated
| displayName: currencyName, | ||
| networkLocation: { | ||
| contractAddress, | ||
| type: (token as any).type // Undocumented EVM token type |
There was a problem hiding this comment.
Where did this come from?
8d4e20f to
1ed9bd8
Compare
e4e1c70 to
a4c6f67
Compare
a4c6f67 to
77a0617
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| readonly encodePayLink: ( | ||
| link: EdgePayLink, | ||
| opts: { allTokens: EdgeTokenMap } | ||
| ) => Promise<string> |
There was a problem hiding this comment.
New EdgeCurrencyTools methods missing optional markers
High Severity
parseLink and encodePayLink on EdgeCurrencyTools are declared as required (non-optional) properties, but the runtime code in plugin-api.ts and currency-wallet-api.ts guards them with != null checks and falls back to the deprecated parseUri/encodeUri. This means the type contract requires all currency plugin implementations to provide these new methods, breaking backward compatibility for plugins that only implement the deprecated methods. Both properties need to be optional (?) to match the intended fallback behavior.
Additional Locations (1)
| if (link.token != null) { | ||
| out.token = makeMetaToken(link.token) | ||
| // @ts-expect-error Undocumented "ERC20" field: | ||
| out.token.type = link.token.networkLocation.type |
There was a problem hiding this comment.
Missing null check on networkLocation causes crash
Medium Severity
In linkToParsedUri, link.token.networkLocation.type is accessed without checking whether networkLocation is defined. EdgeToken.networkLocation is typed as JsonObject | undefined and is documented as being undefined for special built-in tokens like staking balances. If a plugin's parseLink returns an EdgeParsedLink with a token whose networkLocation is undefined, this line throws a TypeError at runtime. This function is called from the wallet's deprecated parseUri backward-compatibility path, so the crash surfaces to callers of an existing API.


CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneDescription
noneNote
Medium Risk
Touches core URI/link encoding pathways and plugin interfaces, so compatibility and tokenId/currencyCode mapping regressions are possible despite fallback logic and new tests.
Overview
Adds new plugin-facing link APIs:
EdgeCurrencyTools.parseLink/encodePayLinkand account-facing wrappersEdgeCurrencyConfig.parseLink/encodePayLink, introducing new types (EdgeParsedLink,EdgePayLink, etc.) for richer link semantics (pay request, payment protocol, private key, custom token, WalletConnect).Keeps backward compatibility by routing
EdgeCurrencyWallet.encodeUri/parseUrithrough the new tools when available, otherwise falling back to legacyencodeUri/parseUriand converting between formats via newuri-toolshelpers (with tokenId/currencyCode bridging). Also tweaks wallet-splitting restoration to always persist unarchive/undelete state updates, and updates/adds tests & fakes accordingly.Written by Cursor Bugbot for commit 77a0617. This will update automatically on new commits. Configure here.