Skip to content
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- changed: Index internal wallet data with tokenIds

## 4.66.0 (2025-12-04)

- added: (Zano) BTCx token
Expand Down
36 changes: 15 additions & 21 deletions src/algorand/AlgorandEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,27 @@ export class AlgorandEngine extends CurrencyEngine<
)
const { assets, amount, 'min-balance': minBalance, round } = accountInfo

this.updateBalance(this.currencyInfo.currencyCode, amount.toString())
this.updateBalance(null, amount.toString())

this.totalReserve = minBalance.toString()

const detectedTokenIds: string[] = []
const newUnactivatedTokenIds: string[] = []
for (const [tokenId, edgeToken] of Object.entries(this.allTokensMap)) {
for (const tokenId of Object.keys(this.allTokensMap)) {
const asset = assets.find(
asset => asset['asset-id'].toFixed() === tokenId
)

if (asset != null) {
const balance = asset.amount.toString()
this.updateBalance(edgeToken.currencyCode, balance)
this.updateBalance(tokenId, balance)

if (gt(balance, '0') && !this.enabledTokenIds.includes(tokenId)) {
detectedTokenIds.push(tokenId)
}
} else {
// Enabled tokens that don't have a balance are unactivated
this.updateBalance(edgeToken.currencyCode, '0')
this.updateBalance(tokenId, '0')
if (this.enabledTokenIds.includes(tokenId)) {
newUnactivatedTokenIds.push(tokenId)
}
Expand Down Expand Up @@ -267,7 +267,6 @@ export class AlgorandEngine extends CurrencyEngine<
sender
} = tx

let currencyCode: string
let tokenId: EdgeTokenId
let nativeAmount: string
let networkFee: string
Expand All @@ -292,7 +291,6 @@ export class AlgorandEngine extends CurrencyEngine<
return
}

currencyCode = this.currencyInfo.currencyCode
tokenId = null
break
}
Expand All @@ -316,9 +314,6 @@ export class AlgorandEngine extends CurrencyEngine<
return
}

const edgeToken: EdgeToken | undefined = this.allTokensMap[assetId]
if (edgeToken == null) return
currencyCode = edgeToken.currencyCode
tokenId = assetId.toString()

break
Expand All @@ -342,7 +337,6 @@ export class AlgorandEngine extends CurrencyEngine<
return
}

currencyCode = this.currencyInfo.currencyCode
tokenId = null
break
}
Expand Down Expand Up @@ -370,6 +364,9 @@ export class AlgorandEngine extends CurrencyEngine<
}
}

const currencyCode = this.getCurrencyCode(tokenId)
if (currencyCode == null) return

const edgeTransaction: EdgeTransaction = {
blockHeight: confirmedRound,
currencyCode,
Expand All @@ -387,7 +384,7 @@ export class AlgorandEngine extends CurrencyEngine<
walletId: this.walletId
}

this.addTransaction(this.currencyInfo.currencyCode, edgeTransaction)
this.addTransaction(tokenId, edgeTransaction)
}

async queryTransactions(): Promise<void> {
Expand Down Expand Up @@ -444,8 +441,7 @@ export class AlgorandEngine extends CurrencyEngine<

latestRound = latestRound ?? this.walletLocalData.blockHeight
const progress = (latestRound - progressRound) / (latestRound - minRound)
this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] =
progress
this.tokenCheckTransactionsStatus.set(null, progress)
this.updateOnAddressesChecked()

nextQueryToken = nextToken
Expand All @@ -457,8 +453,8 @@ export class AlgorandEngine extends CurrencyEngine<
this.walletLocalDataDirty = true
}

for (const cc of this.enabledTokens) {
this.tokenCheckTransactionsStatus[cc] = 1
for (const tokenId of [null, ...this.enabledTokenIds]) {
this.tokenCheckTransactionsStatus.set(tokenId, 1)
}
this.updateOnAddressesChecked()
this.sendTransactionEvents()
Expand Down Expand Up @@ -565,7 +561,7 @@ export class AlgorandEngine extends CurrencyEngine<
const { type }: BaseTxOpts = asMaybe(asBaseTxOpts)(
edgeSpendInfo.otherParams
) ?? {
type: currencyCode === this.currencyInfo.currencyCode ? 'pay' : 'axfer'
type: tokenId == null ? 'pay' : 'axfer'
}

const note =
Expand Down Expand Up @@ -601,12 +597,10 @@ export class AlgorandEngine extends CurrencyEngine<
break
}
case 'axfer': {
const edgeTokenId = Object.keys(this.allTokensMap).find(
tokenId => this.allTokensMap[tokenId].currencyCode === currencyCode
)
if (edgeTokenId == null) throw new Error('Unrecognized asset')
const edgeToken = this.allTokensMap[tokenId as string]
if (edgeToken == null) throw new Error('Unrecognized asset')
const networkLocation = asMaybeContractAddressLocation(
this.allTokensMap?.[edgeTokenId]?.networkLocation
edgeToken.networkLocation
)

if (networkLocation == null) throw new Error('Unrecognized asset')
Expand Down
20 changes: 11 additions & 9 deletions src/cardano/CardanoEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class CardanoEngine extends CurrencyEngine<
}

// Network balance may be out of date, so we'll calculate it from utxos:
this.updateBalanceFromUtxos(this.currencyInfo.currencyCode)
this.updateBalanceFromUtxos(null)
} catch (e) {
this.log.warn('queryBalance error: ', e)
}
Expand Down Expand Up @@ -299,25 +299,27 @@ export class CardanoEngine extends CurrencyEngine<
for (let i = 0; i < txs.length; i++) {
const tx = txs[i]
const edgeTx = processCardanoTransaction({
currencyCode: this.currencyInfo.currencyCode,
currencyCode: this.getCurrencyCode(null),
address: this.walletInfo.keys.bech32Address,
tokenId: null,
tx,
walletId: this.walletId
})
this.addTransaction(this.currencyInfo.currencyCode, edgeTx)
this.addTransaction(null, edgeTx)
this.otherData.latestQueryTransactionsBlockHeight = tx.block_height
this.otherData.latestQueryTransactionsTxid = tx.tx_hash
progressCurrent++
}

this.walletLocalDataDirty = true
this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] =
this.tokenCheckTransactionsStatus.set(
null,
progressCurrent / progressTotal
)
this.updateOnAddressesChecked()
}

this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] = 1
this.tokenCheckTransactionsStatus.set(null, 1)
this.updateOnAddressesChecked()
this.sendTransactionEvents()
}
Expand Down Expand Up @@ -526,7 +528,7 @@ export class CardanoEngine extends CurrencyEngine<
})

// Update balance incase the UTXO set changed:
this.updateBalanceFromUtxos(this.currencyInfo.currencyCode)
this.updateBalanceFromUtxos(null)
}

async signTx(
Expand Down Expand Up @@ -624,9 +626,9 @@ export class CardanoEngine extends CurrencyEngine<
)
}

private updateBalanceFromUtxos(currencyCode: string): void {
private updateBalanceFromUtxos(tokenId: EdgeTokenId): void {
const balance = this.utxos.reduce((acc, utxo) => add(acc, utxo.value), '0')
this.updateBalance(currencyCode, balance)
this.updateBalance(tokenId, balance)
}

getStakeAddress = async (): Promise<string> => {
Expand Down Expand Up @@ -691,7 +693,7 @@ export class CardanoEngine extends CurrencyEngine<

const edgeTransaction: EdgeTransaction = {
blockHeight: 0,
currencyCode: this.currencyInfo.currencyCode,
currencyCode: this.getCurrencyCode(null),
date: 0,
isSend: isDeposit,
memos: [],
Expand Down
Loading
Loading