Skip to content

Commit

Permalink
ERC20 tokens balances (#1015)
Browse files Browse the repository at this point in the history
* problem: incorrect coin ticker on tx details page
* solution: MultiCreateTransaction refactoring
* solution: fixed @emeraldwallet/erc20 build
* solution: store package build fix
* solution: devDependecies lookup added to tslint
* solution: show known tokens balances
* solution: fixed deposit button in accounts lint
* solution: workflow -> core/workflow
  • Loading branch information
gagarin55 committed Sep 21, 2019
1 parent 49ef388 commit d15e554
Show file tree
Hide file tree
Showing 372 changed files with 6,197 additions and 5,178 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Expand Up @@ -25,7 +25,6 @@ jobs:
command: |
yarn build
yarn test
yarn lint
- run:
name: Build distributive
Expand All @@ -42,4 +41,4 @@ jobs:
export PATH=$PATH:$PWD/janusbin
if [ "${CIRCLE_BRANCH}" == "master" ]; then
.circleci/deploy.sh
fi
fi
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -43,7 +43,7 @@ script:
- if [[ $(license-checker --production --exclude '(GPL-2.0 OR MIT)' | grep GPL) ]]; then license-checker --production | grep -C 1 GPL && false; fi
- yarn build
- yarn test:coverage
- yarn lint
# - yarn lint:ts
- travis_wait env CSC_IDENTITY_AUTO_DISCOVERY=false yarn build:dist
after_success:
# Show dist directory contents after a successful build.
Expand Down
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -6,11 +6,15 @@
"build": "lerna run build --stream",
"test": "lerna run test --stream",
"lint": "lerna run lint --stream",
"lint:ts": "tslint 'packages/**/*.ts{,x}' -c tslint.json",
"build:dist": "lerna run build:dist --stream",
"test:coverage": "lerna run test:coverage --stream"
},
"devDependencies": {
"lerna": "^3.13.0"
"lerna": "^3.13.0",
"tslint": "^5.20.0",
"tslint-config-standard": "^8.0.1",
"tslint-react": "^4.1.0"
},
"workspaces": [
"packages/*"
Expand Down
4 changes: 3 additions & 1 deletion packages/core/package.json
Expand Up @@ -14,7 +14,9 @@
},
"dependencies": {
"@emeraldplatform/core": "0.5.1",
"bignumber.js": "^8.1.1",
"@emeraldplatform/eth": "^0.5.1",
"@emeraldplatform/eth-rpc": "^0.5.3",
"bignumber.js": "8.0.2",
"ethereumjs-tx": "^1.3.7"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Currency.spec.ts
@@ -1,7 +1,7 @@
import {Currency, CurrencyCode} from "./Currency";
import { Currency, CurrencyCode } from './Currency';

describe('Currency', () => {
it('should format', () => {
expect(Currency.format(5, CurrencyCode.USD)).toEqual('$5.00');
})
});
});
22 changes: 11 additions & 11 deletions packages/core/src/Currency.ts
Expand Up @@ -2,27 +2,27 @@
import BigNumber from 'bignumber.js';

export const enum CurrencyCode {
RUB = "RUB",
USD = "USD",
EUR = "EUR",
AUD = "AUD",
CNY = "CNY",
KRW = "KRW",
MONOPOLY = "MONOPOLY",
RUB = 'RUB',
USD = 'USD',
EUR = 'EUR',
AUD = 'AUD',
CNY = 'CNY',
KRW = 'KRW',
MONOPOLY = 'MONOPOLY'
}

export class Currency {
static format(value: number, currency: CurrencyCode): string {
public static format (value: number, currency: CurrencyCode): string {
const formatter = new Intl.NumberFormat(Currency.locale(currency), {
style: 'currency',
currency,
minimumFractionDigits: 2,
currencyDisplay: "symbol"
currencyDisplay: 'symbol'
});
return formatter.format(value);
}

static locale(currencySymbol: string): string {
public static locale (currencySymbol: string): string {
switch (currencySymbol.toUpperCase()) {
case CurrencyCode.RUB: return 'ru-RU';
case CurrencyCode.USD: return 'en-US';
Expand All @@ -34,7 +34,7 @@ export class Currency {
}
}

static convert(value: string, rate: number, decimals: number = 2): string {
public static convert (value: string, rate: number, decimals: number = 2): string {
const v = new BigNumber(value, 10);
const r = ((rate === null) || (typeof rate === 'undefined'))
? new BigNumber(0)
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/DefaultLogger.ts
@@ -1,16 +1,16 @@
import ILogger from './ILogger';

export default class DefaultLogger implements ILogger {
debug(...params: any[]) {
public debug (...params: any[]) {

};
error(...params: any[]) {
}
public error (...params: any[]) {

};
warn(...params: any[]) {
}
public warn (...params: any[]) {

};
info(...params: any[]) {
}
public info (...params: any[]) {

};
}
}
10 changes: 8 additions & 2 deletions packages/core/src/IAccount.ts
@@ -1,4 +1,10 @@
export interface IAccount {
id: string;
blockchain: any;
readonly id: string;
readonly blockchain: any;
hdpath?: string;
hardware?: boolean;
hidden?: boolean;
balance?: any;
name?: string;
description?: string;
}
8 changes: 4 additions & 4 deletions packages/core/src/IApi.ts
@@ -1,11 +1,11 @@
import {Vault} from "@emeraldplatform/vault";
import {BlockchainCode} from './blockchains/blockchains';
import {EthRpc} from "@emeraldplatform/eth-rpc";
import { EthRpc } from '@emeraldplatform/eth-rpc';
import { Vault } from '@emeraldplatform/vault';
import { BlockchainCode } from './blockchains';

/**
* Backend API - Emerald vault and Ethereum-like RPC
*/
export interface IApi {
emerald: Vault;
chain(name: BlockchainCode | string): EthRpc;
chain (name: BlockchainCode | string): EthRpc;
}
10 changes: 5 additions & 5 deletions packages/core/src/IServerConnect.ts
@@ -1,8 +1,8 @@
import {Vault} from "@emeraldplatform/vault";
import {BlockchainCode} from './blockchains/blockchains';
import {EthRpc} from "@emeraldplatform/eth-rpc";
import { EthRpc } from '@emeraldplatform/eth-rpc';
import { Vault } from '@emeraldplatform/vault';
import { BlockchainCode } from './blockchains/blockchains';

export interface IServerConnect {
connectEmerald(): Vault;
connectEthChain(name: BlockchainCode): null | EthRpc;
connectEmerald (): Vault;
connectEthChain (name: BlockchainCode): null | EthRpc;
}
2 changes: 1 addition & 1 deletion packages/core/src/Units.spec.ts
Expand Up @@ -11,4 +11,4 @@ describe('Units', () => {
const u = new Units('qwqwerwe', 2);
}).toThrow();
});
});
});
6 changes: 3 additions & 3 deletions packages/core/src/Units.ts
Expand Up @@ -11,10 +11,10 @@ export interface IUnits {
* Bitcoin - satoshi
*/
class Units implements IUnits {
amount: string;
decimals: number;
public amount: string;
public decimals: number;

constructor(amount: string, decimals: number) {
constructor (amount: string, decimals: number) {
const bAmount = new BigNumber(amount);
if (bAmount.isNaN()) {
throw new Error('Invalid value of amount: ' + amount);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/blockchains/Blockchain.ts
@@ -1,8 +1,8 @@
import BlockchainParams from "./BlockchainParams";
import BlockchainParams from './BlockchainParams';

export interface Blockchain {
params: BlockchainParams;

isValidAddress(address: string): boolean;
getTitle(): string;
isValidAddress (address: string): boolean;
getTitle (): string;
}
2 changes: 1 addition & 1 deletion packages/core/src/blockchains/BlockchainParams.ts
@@ -1,7 +1,7 @@
/**
* Parameters of particular blockchain
*/
import {BlockchainCode} from "./blockchains";
import { BlockchainCode } from './blockchains';

export default interface BlockchainParams {
decimals: number;
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/blockchains/CoinTicker.ts
@@ -1,7 +1,7 @@
export enum CoinTicker {
ETC = "ETC",
ETH = "ETH",
BTC = "BTC",
MORDEN = "MORDEN",
KOVAN = "KOVAN"
ETC = 'ETC',
ETH = 'ETH',
BTC = 'BTC',
MORDEN = 'MORDEN',
KOVAN = 'KOVAN'
}
9 changes: 7 additions & 2 deletions packages/core/src/blockchains/blockchains.spec.ts
@@ -1,7 +1,12 @@
import { BlockchainCode } from "./blockchains";
import { BlockchainCode, isValidChain } from './blockchains';

describe('BlockchainCode', () => {
it('should contain codes', () => {
expect(BlockchainCode.ETC).toEqual('etc');
})
});

it('should be able to validate chain code', () => {
expect(isValidChain('etc')).toBeTruthy();
expect(isValidChain('ETC')).toBeFalsy();
});
});
36 changes: 20 additions & 16 deletions packages/core/src/blockchains/blockchains.ts
@@ -1,43 +1,47 @@
import Ethereum from "./ethereum/Ethereum";
import EthereumParams from "./ethereum/EthereumParams";
import {CoinTicker} from "./CoinTicker";
import {Blockchain} from "./Blockchain";
import { Blockchain } from './Blockchain';
import { CoinTicker } from './CoinTicker';
import Ethereum from './ethereum/Ethereum';
import EthereumParams from './ethereum/EthereumParams';

export enum BlockchainCode {
ETC = "etc",
ETH = "eth",
Morden = "morden",
Kovan = "kovan",
Unknown = "unknown"
ETC = 'etc',
ETH = 'eth',
Morden = 'morden',
Kovan = 'kovan',
Unknown = 'unknown'
}

export const Blockchains: {[key: string]: Blockchain} = {
[BlockchainCode.ETH]: new Ethereum(new EthereumParams(BlockchainCode.ETH, CoinTicker.ETH, 1,"m/44'/60'/0'/0'"), "Ethereum"),
[BlockchainCode.ETC]: new Ethereum(new EthereumParams(BlockchainCode.ETC, CoinTicker.ETC, 61, "m/44'/61'/0'/0'"), "Ethereum Classic"),
[BlockchainCode.Morden]: new Ethereum(new EthereumParams(BlockchainCode.Morden, CoinTicker.MORDEN, 62, "m/44'/60'/160720'/0'"), "Ethereum Morden Testnet"),
[BlockchainCode.Kovan]: new Ethereum(new EthereumParams(BlockchainCode.Kovan, CoinTicker.KOVAN, 42, "m/44'/60'/160720'/0'"), "Ethereum Kovan Testnet"),
[BlockchainCode.ETH]: new Ethereum(new EthereumParams(BlockchainCode.ETH, CoinTicker.ETH, 1,"m/44'/60'/0'/0'"), 'Ethereum'),
[BlockchainCode.ETC]: new Ethereum(new EthereumParams(BlockchainCode.ETC, CoinTicker.ETC, 61, "m/44'/61'/0'/0'"), 'Ethereum Classic'),
[BlockchainCode.Morden]: new Ethereum(new EthereumParams(BlockchainCode.Morden, CoinTicker.MORDEN, 62, "m/44'/60'/160720'/0'"), 'Ethereum Morden Testnet'),
[BlockchainCode.Kovan]: new Ethereum(new EthereumParams(BlockchainCode.Kovan, CoinTicker.KOVAN, 42, "m/44'/60'/160720'/0'"), 'Ethereum Kovan Testnet')
};

const allCodes = [BlockchainCode.ETC, BlockchainCode.ETH, BlockchainCode.Morden, BlockchainCode.Kovan];
const allChains = allCodes.map((code) => Blockchains[code]);

export function blockchainCodeByName(name: string): string {
export function isValidChain (code: any): boolean {
return Blockchains[code] ? true : false;
}

export function blockchainCodeByName (name: string): string {
if (!name) {
throw new Error('Empty chain name passed');
}
const cleanName = name.toLowerCase();
return allCodes.find((code) => code == cleanName) || BlockchainCode.Unknown;
}

export function blockchainByName(name: string): Blockchain {
export function blockchainByName (name: string): Blockchain {
const code = blockchainCodeByName(name);
if (!Blockchains[code]) {
throw new Error(`Unsupported chain: ${code}`);
}
return Blockchains[code];
}

export function blockchainById(id?: number): Blockchain | undefined {
export function blockchainById (id?: number): Blockchain | undefined {
if (typeof id === 'undefined') {
return undefined;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/blockchains/ethereum/Ethereum.spec.ts
@@ -1,10 +1,10 @@
import { BlockchainCode } from '../blockchains';
import { CoinTicker } from '../CoinTicker';
import Ethereum from './Ethereum';
import EthereumParams from "./EthereumParams";
import {BlockchainCode} from "../blockchains";
import {CoinTicker} from "../CoinTicker";
import EthereumParams from './EthereumParams';

describe('Ethereum', () => {
it('should have coin ticker ETH', () => {
expect(new Ethereum(new EthereumParams(BlockchainCode.ETH, CoinTicker.ETH, 1, "m/44'/60'/160720'/0'"), "Ethereum").params.coinTicker).toEqual('ETH');
})
expect(new Ethereum(new EthereumParams(BlockchainCode.ETH, CoinTicker.ETH, 1, "m/44'/60'/160720'/0'"), 'Ethereum').params.coinTicker).toEqual('ETH');
});
});
16 changes: 8 additions & 8 deletions packages/core/src/blockchains/ethereum/Ethereum.ts
@@ -1,21 +1,21 @@
import {EthAddress} from '@emeraldplatform/core';
import {Blockchain} from "../Blockchain";
import BlockchainParams from "../BlockchainParams";
import { EthAddress } from '@emeraldplatform/core';
import { Blockchain } from '../Blockchain';
import BlockchainParams from '../BlockchainParams';

export default class Ethereum implements Blockchain {
params: BlockchainParams;
title: string;
public params: BlockchainParams;
public title: string;

constructor(params: BlockchainParams, title: string) {
constructor (params: BlockchainParams, title: string) {
this.params = params;
this.title = title;
}

isValidAddress(address: string): boolean {
public isValidAddress (address: string): boolean {
return EthAddress.fromHexString(address).isValid();
}

getTitle(): string {
public getTitle (): string {
return this.title;
}
}
14 changes: 7 additions & 7 deletions packages/core/src/blockchains/ethereum/EthereumParams.ts
@@ -1,14 +1,14 @@
import BlockchainParams from '../BlockchainParams';
import {BlockchainCode} from "../blockchains";
import { BlockchainCode } from '../blockchains';

class EthereumParams implements BlockchainParams {
decimals: number = 18;
coinTicker: string;
chainId: number;
hdPath: string;
code: BlockchainCode;
public decimals: number = 18;
public coinTicker: string;
public chainId: number;
public hdPath: string;
public code: BlockchainCode;

constructor(code: BlockchainCode, coinTicker: string, chainId: number, hdPaths: string) {
constructor (code: BlockchainCode, coinTicker: string, chainId: number, hdPaths: string) {
this.code = code;
this.coinTicker = coinTicker;
this.chainId = chainId;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blockchains/ethereum/EthereumTx.spec.ts
Expand Up @@ -4,5 +4,5 @@ describe('EthereumTx', () => {
it('should decode from raw hex rlp', () => {
const tx = EthereumTx.fromRaw('0xf889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f');
expect(tx.getSenderAddress()).toEqual('be862AD9AbFe6f22BCb087716c7D89a26051f74C'.toLowerCase());
})
});
});
});

0 comments on commit d15e554

Please sign in to comment.