Skip to content

Commit

Permalink
Merge branch 'develop' into feature/MINT-1511-Import-methods-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ex1st0r committed Jun 25, 2018
2 parents f48e241 + 8f46eba commit 04f2f1d
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 1,204 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chronobank/mint",
"version": "0.9.0",
"version": "0.9.2",
"description": "Control panel for ChronoBank",
"private": true,
"author": "chronobank",
Expand Down Expand Up @@ -155,7 +155,7 @@
"lint:report": "bash -c \"node ./node_modules/eslint/bin/eslint --format node_modules/eslint-html-reporter/reporter-team-city.js --output-file ./report/eslint-report-`date +%F`.html --debug --ext .js,.jsx .\"",
"lint:sort": "bash -c \"node ./scripts/importSort.js `git diff --name-status $(git merge-base origin/develop HEAD)..HEAD | grep -E '^[AM]' | awk ' {print $2} ' | grep -E 'jsx?$'`\"",
"lint:test": "node ./node_modules/eslint/bin/eslint.js --ext .js,.jsx .",
"start": "node ./scripts/start.js",
"start": "node --max-old-space-size=4096 ./scripts/start.js",
"start:eval": "SOURCE_MAP=eval node ./scripts/start.js",
"start:http": "BASE_SCHEMA=http node ./scripts/start.js",
"stats": "node ./scripts/start.js --stats",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the AGPL Version 3 license.
*/

import ledgerProvider from '@chronobank/login/network/LedgerProvider'
import { fetchAccount, startLedgerSync, stopLedgerSync } from '@chronobank/login/redux/ledger/actions'
import { CircularProgress, RaisedButton } from 'material-ui'
import networkService from '@chronobank/login/network/NetworkService'
Expand Down Expand Up @@ -84,6 +85,7 @@ class LoginLedger extends PureComponent {
if (!ledger.isFetched && !ledger.isFetching && ledger.isHttps && ledger.isU2F && ledger.isETHAppOpened) {
this.props.fetchAccount()
}
ledgerProvider.setWallet(this.props.account[0]); networkService.selectAccount(this.props.account[0]); networkService.setAccounts(this.props.account)
}

componentWillUnmount () {
Expand Down Expand Up @@ -119,8 +121,8 @@ class LoginLedger extends PureComponent {
_buildItem(item, index) {
return <MenuItem value={index} key={index} primaryText={item}/>
}

handleChange = (event, index, value) => {this.setState({value}); networkService.selectAccount(this.props.account[value])}
handleChange = (event, index, value) => {this.setState({value}); ledgerProvider.setWallet(this.props.account[index]); networkService.selectAccount(this.props.account[index]);}

render () {
const { isLoading, ledger, account } = this.props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class LoginTrezor extends PureComponent {
if (!trezor.isFetched && !trezor.isFetching && trezor.isHttps && trezor.isU2F) {
this.props.fetchAccount()
}
trezorProvider.setWallet(this.props.account[0]); networkService.selectAccount(this.props.account[0]); networkService.setAccounts(this.props.account)
}

componentWillUnmount () {
Expand Down
Binary file added packages/login/network/.WavesWallet.js.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/login/network/HardwareWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export default class HardwareWallet {
constructor (address) {
this._address = address[0]
this._address = address
}

getAddressString () {
Expand Down
1 change: 0 additions & 1 deletion packages/login/network/NetworkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class NetworkService extends EventEmitter {
const web3 = new Web3()
web3Provider.reinit(web3, ethereum.getProvider())
networkProvider.setNetworkCode(networkCode)
await this.loadAccounts()
ethereumProvider.setEngine(ethereum, nem, waves)
bcc && bccProvider.setEngine(bcc)
btc && btcProvider.setEngine(btc)
Expand Down
2 changes: 1 addition & 1 deletion packages/login/network/WavesEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class WavesEngine {
amount: amount,

// The same rules for these two fields
feeAssetId: 'WAVES',
feeAssetId: this._Waves.constants.WAVES,
fee: 100000,

// 140 bytes of data (it's allowed to use Uint8Array here)
Expand Down
7 changes: 1 addition & 6 deletions packages/login/network/WavesMiddlewareNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import BigNumber from 'bignumber.js'
import WavesAbstractNode, { WavesBalance, WavesTx } from './WavesAbstractNode'

export default class WavesMiddlewareNode extends WavesAbstractNode {
constructor ({ assets, ...args }) {
constructor ({ ...args }) {
super(args)
this._assets = assets
// TODO @dkchv: still can't combine async + arrow on class
this.addListener('subscribe', (address) => this._handleSubscribe(address))
this.addListener('unsubscribe', (address) => this._handleUnsubscribe(address))
Expand Down Expand Up @@ -67,10 +66,6 @@ export default class WavesMiddlewareNode extends WavesAbstractNode {
}
}

getAssets () {
return this._assets
}

async getAddressInfo (address) {
try {
const { data } = await this._api.get(`addr/${address}/balance`)
Expand Down
2 changes: 0 additions & 2 deletions packages/login/network/WavesNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import WavesMiddlewareNode from './WavesMiddlewareNode'
import * as WavesApi from '@waves/waves-api'

export const WAVES_MAINNET_NODE = new WavesMiddlewareNode({
assets: ['MINUTES'],
api: axios.create({
baseURL: 'https://middleware-waves-mainnet-rest.chronobank.io',
timeout: 30000,
Expand All @@ -26,7 +25,6 @@ export const WAVES_MAINNET_NODE = new WavesMiddlewareNode({
})

export const WAVES_TESTNET_NODE = new WavesMiddlewareNode({
assets: ['MINUTES'],
api: axios.create({
baseURL: 'https://middleware-waves-testnet-rest.chronobank.io',
timeout: 30000,
Expand Down
11 changes: 6 additions & 5 deletions packages/login/network/WavesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ export class WavesProvider extends AbstractProvider {
return node.getTransactionInfo(txid)
}

getAssets () {
async getAssets () {
const node = this._selectNode(this._engine)
return node.getAssets() || []
const { balance, assets } = await node.getAddressInfo(this._engine.getAddress())
return assets || []
}

getPrivateKey () {
Expand All @@ -45,9 +46,9 @@ export class WavesProvider extends AbstractProvider {
async getAccountBalances (asset) {
const node = this._selectNode(this._engine)
const { balance, assets } = await node.getAddressInfo(this._engine.getAddress())
//if (assets) {
// return assets[asset]
//}
if (Object.keys(assets).length && assets[asset]) {
return assets[asset]['balance']
}
return balance
}

Expand Down
2 changes: 1 addition & 1 deletion packages/login/network/WavesWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class WavesWallet {

static fromMnemonic (mnemonic, network) {
const Waves = WavesAPI.create(network)
const seed = Waves.Seed.fromExistingPhrase(bip39.mnemonicToSeed(mnemonic).toString('hex'))
const seed = Waves.Seed.fromExistingPhrase(mnemonic)
return new WavesWallet(seed, seed.keyPair, network)
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/dao/WavesDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ const EVENT_BALANCE = 'balance'

export default class WavesDAO extends EventEmitter {

constructor (name, symbol, wavesProvider, decimals, asset) {
constructor (name, symbol, wavesProvider, decimals, asset, wavesToken) {
super()
this._name = name
this._symbol = symbol
this._decimals = decimals
this._asset = asset
this._wavesProvider = wavesProvider
this._wavesToken = wavesToken
}

getAddressValidator () {
Expand Down Expand Up @@ -72,7 +73,7 @@ export default class WavesDAO extends EventEmitter {
}

async getAccountBalances () {
return await this._wavesProvider.getAccountBalances(this._asset)
return await this._wavesProvider.getAccountBalances(this._name)
}

async getAccountBalance () {
Expand All @@ -99,13 +100,13 @@ export default class WavesDAO extends EventEmitter {
submit (from: string, to: string, amount: BigNumber, token: TokenModel, feeMultiplier: Number = 1) {
setImmediate(async () => {
this.emit('submit', new TransferExecModel({
title: `tx.Waves.${this._asset ? this._asset : 'WAVES'}.transfer.title`,
title: `tx.Waves.${this._name ? 'Asset': 'WAVES'}.transfer.title`,
from,
to,
amount: new Amount(amount, token.symbol()),
amountToken: token,
feeToken: token,
fee: new Amount(10000, token.symbol()),
feeToken: this._wavesToken,
fee: new Amount(10000, this._wavesToken.symbol()),
feeMultiplier,
}))
})
Expand Down
17 changes: 17 additions & 0 deletions src/i18n/en-tx-waves.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright 2017–2018, LaborX PTY
* Licensed under the AGPL Version 3 license.
*/

export default {
Waves: {
transfer: {
title: 'Waves Transfer',
},
},
Asset: {
transfer: {
title: 'Asset Transfer',
},
},
}
1 change: 1 addition & 0 deletions src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export default {
General: require('./en-tx-general'),
Bitcoin: require('./en-tx-bitcoin'),
Nem: require('./en-tx-nem'),
Waves: require('./en-tx-waves'),
/* eslint-enable global-require */
ContractsManager: {},
ChronoBankAssetProxy: {
Expand Down
9 changes: 4 additions & 5 deletions src/redux/tokens/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,20 @@ export const initWavesTokens = () => async (dispatch, getState) => {
tokenService.registerDAO(waves, dao)
dispatch({ type: TOKENS_FETCHED, token: waves })
dispatch(alternateTxHandlingFlow(dao))
//dispatch(initWavesAssetTokens(waves))
dispatch(initWavesAssetTokens(waves))
} catch (e) {
dispatch({ type: TOKENS_FAILED })
}
}

export const initWavesAssetTokens = (waves: TokenModel) => async (dispatch, getState) => {

const assets = wavesProvider.getAssets()
const assets = await wavesProvider.getAssets()
const currentCount = getState().get(DUCK_TOKENS).leftToFetch()
dispatch({ type: TOKENS_FETCHING, count: currentCount + assets.length })
// do not wait until initialized, it is ok to lazy load all the tokens
return Promise.all(
assets
.map((m) => new WavesDAO(m.name, m.symbol, wavesProvider, m.decimals, assets))
Object.keys(assets)
.map((m) => new WavesDAO(m, m, wavesProvider, assets[m]['decimals'], assets[m]['id'], waves))
.map(async (dao) => {
try {
const token = await dao.fetchToken()
Expand Down
Loading

0 comments on commit 04f2f1d

Please sign in to comment.