Skip to content
Closed
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions src/core/blockchain/cosmos/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountType, IAccountState } from '../../../redux/wallets/state';
import { Blockchain, IBlockchainAccountUtils } from '../types';
import { AccountType, IAccountState, ITokenState } from '../../../redux/wallets/state';
import { Blockchain, ChainIdType, IBlockchainAccountUtils, IFeeOptions } from '../types';
import { BigNumber } from 'bignumber.js';
import { config } from './config';
import { convert } from '../common/account';
Expand All @@ -8,6 +8,8 @@ import bech32 from 'bech32';
import { createHash } from 'crypto';
import secp256k1 from 'secp256k1';
import { generateTokensConfig } from '../../../redux/tokens/static-selectors';
import { PosBasicActionType } from '../types/token';
import { availableAmount } from '../../utils/available-funds';

export class CosmosAccountUtils implements IBlockchainAccountUtils {
public getAccountDerivationPath(accountIndex: number): string {
Expand Down Expand Up @@ -72,4 +74,14 @@ export class CosmosAccountUtils implements IBlockchainAccountUtils {
public convertUnit(value: BigNumber, from: string, to: string): BigNumber {
return convert(value, from, to, config);
}

public async availableAmount(
account: IAccountState,
value: string,
token: ITokenState,
chainId: ChainIdType,
options: { feeOptions?: IFeeOptions; action?: PosBasicActionType | 'transfer' }
): Promise<string> {
return availableAmount(account, token, chainId, options.feeOptions, value);
}
}
16 changes: 14 additions & 2 deletions src/core/blockchain/ethereum/account.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { AccountType, IAccountState } from '../../../redux/wallets/state';
import { Blockchain, IBlockchainAccountUtils } from '../types';
import { AccountType, IAccountState, ITokenState } from '../../../redux/wallets/state';
import { Blockchain, ChainIdType, IBlockchainAccountUtils, IFeeOptions } from '../types';
import * as Util from 'ethereumjs-util';
import { BigNumber } from 'bignumber.js';
import { convert } from '../common/account';
import { config } from './config';
import HDNode from 'hdkey';
import { generateTokensConfig } from '../../../redux/tokens/static-selectors';
import { PosBasicActionType } from '../types/token';
import { availableAmount } from '../../utils/available-funds';

export class EthereumAccountUtils implements IBlockchainAccountUtils {
public getAccountDerivationPath(accountIndex: number): string {
Expand Down Expand Up @@ -63,4 +65,14 @@ export class EthereumAccountUtils implements IBlockchainAccountUtils {
public convertUnit(value: BigNumber, from: string, to: string): BigNumber {
return convert(value, from, to, config);
}

public async availableAmount(
account: IAccountState,
value: string,
token: ITokenState,
chainId: ChainIdType,
options: { feeOptions?: IFeeOptions; action?: PosBasicActionType | 'transfer' }
): Promise<string> {
return availableAmount(account, token, chainId, options.feeOptions, value);
}
}
16 changes: 14 additions & 2 deletions src/core/blockchain/near/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountType, IAccountState } from '../../../redux/wallets/state';
import { Blockchain, ChainIdType, IBlockchainAccountUtils } from '../types';
import { AccountType, IAccountState, ITokenState } from '../../../redux/wallets/state';
import { Blockchain, ChainIdType, IBlockchainAccountUtils, IFeeOptions } from '../types';
import { BigNumber } from 'bignumber.js';
import { config } from './config';
import { convert } from '../common/account';
Expand All @@ -9,6 +9,8 @@ import { HDKeyEd25519 } from '../../wallet/hd-wallet/hd-key/hd-key-ed25519';
import { generateTokensConfig } from '../../../redux/tokens/static-selectors';
import { sha256 } from 'js-sha256';
import { NEAR_LOCKUP_SUFFIX } from '../../constants/app';
import { PosBasicActionType } from '../types/token';
import { availableAmount } from '../../utils/available-funds';

export class NearAccountUtils implements IBlockchainAccountUtils {
public getAccountDerivationPath(accountIndex: number): string {
Expand Down Expand Up @@ -74,4 +76,14 @@ export class NearAccountUtils implements IBlockchainAccountUtils {
public getLockupContract(accountId: string, chainId: ChainIdType): string {
return sha256(Buffer.from(accountId)).substring(0, 40) + NEAR_LOCKUP_SUFFIX[chainId];
}

public availableAmount(
account: IAccountState,
value: string,
token: ITokenState,
chainId: ChainIdType,
options: { feeOptions?: IFeeOptions; action?: PosBasicActionType | 'transfer' }
): Promise<string> {
return availableAmount(account, token, chainId, options.feeOptions, value);
}
}
16 changes: 14 additions & 2 deletions src/core/blockchain/solana/account.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { AccountType, IAccountState } from '../../../redux/wallets/state';
import { AccountType, IAccountState, ITokenState } from '../../../redux/wallets/state';

import { Blockchain, IBlockchainAccountUtils } from '../types';
import { Blockchain, ChainIdType, IBlockchainAccountUtils, IFeeOptions } from '../types';
import { BigNumber } from 'bignumber.js';
import { config } from './config';
import { convert } from '../common/account';
import { generateTokensConfig } from '../../../redux/tokens/static-selectors';
import { encode as bs58Encode, decode as bs58Decode } from 'bs58';
import * as nacl from 'tweetnacl';
import { HDKeyEd25519 } from '../../wallet/hd-wallet/hd-key/hd-key-ed25519';
import { PosBasicActionType } from '../types/token';
import { availableAmount } from '../../utils/available-funds';

export class SolanaAccountUtils implements IBlockchainAccountUtils {
public getAccountDerivationPath(accountIndex): string {
Expand Down Expand Up @@ -69,4 +71,14 @@ export class SolanaAccountUtils implements IBlockchainAccountUtils {
convertUnit(value: BigNumber, from: string, to: string): BigNumber {
return convert(value, from, to, config);
}

public availableAmount(
account: IAccountState,
value: string,
token: ITokenState,
chainId: ChainIdType,
options: { feeOptions?: IFeeOptions; action?: PosBasicActionType | 'transfer' }
): Promise<string> {
return availableAmount(account, token, chainId, options.feeOptions, value);
}
}
12 changes: 11 additions & 1 deletion src/core/blockchain/types/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IAccountState } from '../../../redux/wallets/state';
import { IAccountState, ITokenState } from '../../../redux/wallets/state';
import { BigNumber } from 'bignumber.js';
import { ChainIdType, IFeeOptions } from '.';
import { PosBasicActionType } from './token';

export interface IBlockchainAccountUtils {
getAccountDerivationPath(accountIndex: number): string;
Expand All @@ -16,4 +18,12 @@ export interface IBlockchainAccountUtils {
amountToStd(value: BigNumber | number | string, decimals: number): BigNumber;
amountFromStd(value: BigNumber, decimals: number): BigNumber;
convertUnit(value: BigNumber, from: string, to: string): BigNumber;

availableAmount(
account: IAccountState,
value: string,
token: ITokenState,
chainId: ChainIdType,
options: { feeOptions?: IFeeOptions; action?: PosBasicActionType | 'transfer' }
): Promise<string>;
}
16 changes: 14 additions & 2 deletions src/core/blockchain/zilliqa/account.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { AccountType, IAccountState } from '../../../redux/wallets/state';
import { AccountType, IAccountState, ITokenState } from '../../../redux/wallets/state';
import {
getPubKeyFromPrivateKey,
getAddressFromPrivateKey,
getAddressFromPublicKey
} from '@zilliqa-js/crypto/dist/util'; // import like this to optimize imports
import { toBech32Address, fromBech32Address } from '@zilliqa-js/crypto/dist/bech32';
import { isBech32 } from '@zilliqa-js/util/dist/validation';
import { Blockchain, IBlockchainAccountUtils } from '../types';
import { Blockchain, ChainIdType, IBlockchainAccountUtils, IFeeOptions } from '../types';
import { BigNumber } from 'bignumber.js';
import { config } from './config';
import { convert } from '../common/account';
import HDNode from 'hdkey';
import { generateTokensConfig } from '../../../redux/tokens/static-selectors';
import { PosBasicActionType } from '../types/token';
import { availableAmount } from '../../utils/available-funds';

export class ZilliqaAccountUtils implements IBlockchainAccountUtils {
public getAccountDerivationPath(accountIndex: number): string {
Expand Down Expand Up @@ -65,4 +67,14 @@ export class ZilliqaAccountUtils implements IBlockchainAccountUtils {
public convertUnit(value: BigNumber, from: string, to: string): BigNumber {
return convert(value, from, to, config);
}

public availableAmount(
account: IAccountState,
value: string,
token: ITokenState,
chainId: ChainIdType,
options: { feeOptions?: IFeeOptions; action?: PosBasicActionType | 'transfer' }
): Promise<string> {
return availableAmount(account, token, chainId, options.feeOptions, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
} from '../../../redux/wallets/actions';
import { HeaderLeft } from '../../../components/header-left/header-left';
import { Dialog } from '../../../components/dialog/dialog';
import { availableAmount } from '../../../core/utils/available-funds';

interface IReduxProps {
isVisible: boolean;
Expand Down Expand Up @@ -134,15 +133,15 @@ export class ProcessTransactionsComponent extends React.Component<
this.props.transactions[0].token.symbol
];

const amount = await availableAmount(
const blockchainInstance = getBlockchain(this.props.selectedAccount.blockchain);
const amount = await blockchainInstance.account.availableAmount(
this.props.selectedAccount,
undefined,
token,
this.props.chainId,
undefined,
undefined
{}
);

const blockchainInstance = getBlockchain(this.props.selectedAccount.blockchain);
const tokenConfig = getTokenConfig(
this.props.selectedAccount.blockchain,
token.symbol
Expand Down