Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 fix: dynex frozen balance #4514

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/engine/src/vaults/impl/dynex/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getTimeDurationMs } from '@onekeyhq/kit/src/utils/helper';
import debugLogger from '@onekeyhq/shared/src/logger/debugLogger';
import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils';

import simpleDb from '../../../dbs/simple/simpleDb';
import { InvalidAddress, NotImplemented } from '../../../errors';
import {
type IApproveInfo,
Expand Down Expand Up @@ -344,6 +345,44 @@ export default class Vault extends VaultBase {
);
}

override async getFrozenBalance(): Promise<number | Record<string, number>> {
// Because dynex does not provide an interface for getting available utxos,
// it can only be calculated when all pending transactions are completed.
try {
let frozenBalance = 0;
let hasLocalTxOutInPending = false;
const localHistory = (
await simpleDb.history.getAccountHistory({
accountId: this.accountId,
networkId: this.networkId,
isPending: true,
limit: 10,
})
).items;

for (let i = 0, len = localHistory.length; i < len; i = +1) {
const item = localHistory[i];
const action = item.decodedTx.actions[0];
if (
action.type === IDecodedTxActionType.NATIVE_TRANSFER &&
(IDecodedTxDirection.OUT === action.direction ||
IDecodedTxDirection.SELF === action.direction)
) {
hasLocalTxOutInPending = true;
break;
}
}
if (hasLocalTxOutInPending) {
frozenBalance = -1;
}

return frozenBalance ?? 0;
} catch (e) {
console.error(e);
return 0;
}
}

_validateAddressMemo = memoizee(
async (address: string) => {
const client = await this.getClient();
Expand Down
Loading