Skip to content

Commit

Permalink
Merge pull request #171 from thepower/feat/eth-transactions
Browse files Browse the repository at this point in the history
fix(cli,tssdk): fixed format acc balance
  • Loading branch information
jackkru69 authored Oct 24, 2024
2 parents 6b064e6 + cc5284b commit 7b96bf8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 88 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/commands/acc/get-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { WalletApi } from '@thepowereco/tssdk';
import { colorize } from 'json-colorizer';

import color from '@oclif/color';
import { formatUnits } from 'viem/utils';
import { initializeNetworkApi, loadWallet } from '../../helpers/network.helper';
import { BaseCommand } from '../../baseCommand';

Expand Down Expand Up @@ -55,7 +56,7 @@ export default class AccGetBalance extends BaseCommand {

const wallet = new WalletApi(networkApi);
const result = await wallet.loadBalance(walletAddress);

result.amount = Object.keys(result.amount).reduce((acc, key) => Object.assign(acc, { [key]: formatUnits(result.amount[key], networkApi.decimals[key]) }), {});
ux.action.stop();

if (result !== undefined) {
Expand Down
3 changes: 1 addition & 2 deletions packages/tssdk/src/libs/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export class NetworkApi {
public upload() {
const {
currentChain, currentNodes, nodeIndex, feeSettings, gasSettings, decimals,
} =
this;
} = this;
return {
currentChain,
currentNodes,
Expand Down
16 changes: 3 additions & 13 deletions packages/tssdk/src/libs/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AddressApi } from './address/address';
import { NetworkApi } from './network/network';
import { TransactionsApi } from './transactions';
import { COIN, CryptoApi, DERIVATION_PATH_BASE } from './crypto/crypto';
import { correctAmount, correctAmountsObject } from '../utils/numbers';
import { Maybe, RegisteredAccount } from '../typings';
import { NetworkEnum } from '../config/network.enum';

Expand Down Expand Up @@ -157,7 +156,7 @@ export class WalletApi {
);
if (payment) {
tx.cur = payment.cur;
tx.amount = correctAmount(payment.amount, tx.cur);
tx.amount = payment.amount;
}
}
if (!tx.cur || !tx.amount) {
Expand All @@ -171,11 +170,8 @@ export class WalletApi {
{},
)
: [];
} else if (tx.amount) {
tx.amount = correctAmount(tx.amount, tx.cur);
}

// Common conversions
if (tx.address) {
tx.address = AddressApi.hexToTextAddress(tx.address);
}
Expand Down Expand Up @@ -204,10 +200,7 @@ export class WalletApi {
// Correct the sums and addresses: we bring the addresses to text form, and the sums to the required number of characters after the decimal point
block.bals = Object.keys(block.bals).reduce(
(acc, key) => Object.assign(acc, {
[AddressApi.hexToTextAddress(key)]: {
...block.bals[key],
amount: correctAmountsObject(block.bals[key].amount),
},
[AddressApi.hexToTextAddress(key)]: block.bals[key],
}),
{},
);
Expand All @@ -223,10 +216,7 @@ export class WalletApi {
public async loadBalance(address: string) {
const walletData = await this.networkApi.getWallet(address);

return {
...walletData,
amount: correctAmountsObject(walletData.amount),
};
return walletData;
}

public async getWalletSequence(address: string) {
Expand Down
72 changes: 0 additions & 72 deletions packages/tssdk/src/utils/numbers.ts

This file was deleted.

0 comments on commit 7b96bf8

Please sign in to comment.