Skip to content

Conversation

@peachbits
Copy link
Contributor

@peachbits peachbits commented Nov 24, 2025

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

EdgeApp/edge-core-js#688

Description

none

Note

Refactors wallet engine APIs to use tokenId (null for mainnet) instead of currencyCode for balances, transactions, and sync state, updating all engines, Ethereum adapters, and tests.

  • Core/Common:
    • Replace currencyCode-keyed data with tokenId (use null for mainnet); persist null as empty string in JSON.
    • Introduce getCurrencyCode(tokenId) and getDenomination(tokenId) helpers.
    • Change APIs: updateBalance(tokenId, ...), addTransaction(tokenId, ...), getBalance({ tokenId }), findTransaction(tokenId, ...), etc.
    • Convert sync status maps to Map<EdgeTokenId, number>.
    • Remove currency-code token lookups; simplify token validation/helpers.
  • Engines (Algorand, Cardano, Cosmos/Thorchain, EOS, Ethereum, Filecoin, FIO, Hedera, Piratechain, Polkadot, Ripple, Solana, Stellar, Sui, Tezos, TON, Tron, Zano, Zcash):
    • Update balance/transaction processing, spend logic, fees, and progress reporting to use tokenId.
    • Ensure mainnet paths pass tokenId = null; adapt denomination/currency code retrieval.
    • Adjust detection of new tokens and unactivated tokens to tokenId.
  • Ethereum Network/Adapters:
    • Refactor adapter interfaces to pass tokenId; use Maps for tokenBal/tokenTxs.
    • Update transaction processing context to forWhichTokenId.
    • Prefer pluginId in logs.
  • Tests:
    • Migrate fixtures and assertions to tokenId (with empty-string key for mainnet) and updated method signatures.
  • CHANGELOG:
    • Add entry: "Index internal wallet data with tokenIds".

Written by Cursor Bugbot for commit a75e721. This will update automatically on new commits. Configure here.


Comment on lines +268 to +275
const mainnetDenom = this.currencyInfo.denominations.find(
d => d.name === this.currencyInfo.currencyCode
)
if (mainnetDenom == null) {
throw new Error(
`Improbable case where we cannot find the mainnet denom`
)
}
return mainnetDenom
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the universal standard is that denominations[0] is always the main one, so we can skip the search and just use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but it isn't enforced anywhere

this.ethEngine.tokenCheckTransactionsStatus[currencyCode] = 1
const tuple: EdgeTransactionsBlockHeightTuple = tokenTxs[currencyCode]
for (const [tokenId, tuple] of tokenTxs) {
if (tokenId == null) continue
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Main currency transactions skipped in Ethereum network update

The if (tokenId == null) continue statement skips processing the main currency's transactions. The tokenTxs Map is expected to contain an entry for null (main currency), as seen at line 328 where tokenTxs.set(null, ...) is called. Skipping null means main currency transactions won't be added via addTransaction, transaction status won't be updated, and query heights won't be saved for the main currency.

Fix in Cursor Fix in Web

for (const token of activeTokens) {
const balanceStatus = this.tokenCheckBalanceStatus[token] ?? 0
const txStatus = this.tokenCheckTransactionsStatus[token] ?? 0
for (const tokenId of activeTokenIds) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Main currency excluded from sync progress calculation

The updateOnAddressesChecked function only iterates over enabledTokenIds, which no longer includes null for the main currency. Other places in the codebase correctly use [null, ...this.enabledTokenIds] to include the main currency (e.g., lines 729, 456 in AlgorandEngine, 726 in CosmosEngine). The main currency's balance and transaction status, tracked with tokenId = null, are not included in the sync progress calculation. Additionally, if no tokens are enabled, this causes a division by zero (1 / 0).

Fix in Cursor Fix in Web

out.newNonce = nonce
if (out.tokenBal != null)
out.tokenBal[this.ethEngine.currencyInfo.currencyCode] = balance
if (out.tokenBal != null) out.tokenBal.set(null, balance)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Token balances not stored correctly in Blockbook Map

The code uses bracket notation out.tokenBal[symbol] = balance on a Map object instead of the .set() method. This sets an object property on the Map rather than adding an entry to the map's internal storage. The values won't be retrievable via Map.get(). Additionally, symbol is a currency code, but the Map is now keyed by EdgeTokenId (tokenId). The main currency line at 103 was correctly updated to use .set(null, balance), but this token balance line was not updated to match.

Fix in Cursor Fix in Web

They'll use empty string as the null key to maintain JSON compatibility
@peachbits peachbits force-pushed the matthew/no-more-currency-codes branch from a836714 to 2378b55 Compare December 9, 2025 22:14
@peachbits peachbits force-pushed the matthew/no-more-currency-codes branch from 2378b55 to a75e721 Compare December 9, 2025 22:39
@peachbits peachbits enabled auto-merge December 9, 2025 22:53
@peachbits peachbits merged commit de28fef into master Dec 9, 2025
3 checks passed
@peachbits peachbits deleted the matthew/no-more-currency-codes branch December 9, 2025 22:57
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.

3 participants