From 949d909d8499eccdde44b53f2616eeb666333a4e Mon Sep 17 00:00:00 2001 From: David Schwartz Date: Thu, 18 Jan 2018 00:32:02 -0800 Subject: [PATCH] Num fixes 1 (#560) * fix send tokens issue * number format change and add decimals --- app/core/nep5.js | 5 ----- app/modules/transactions.js | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 14 deletions(-) delete mode 100644 app/core/nep5.js diff --git a/app/core/nep5.js b/app/core/nep5.js deleted file mode 100644 index 16d290669..000000000 --- a/app/core/nep5.js +++ /dev/null @@ -1,5 +0,0 @@ -// @flow -import { toBigNumber } from './math' - -export const adjustDecimalAmountForTokenTransfer = (value: string, decimals: number): string => - toBigNumber(value).times(10 ** decimals).round().toNumber() diff --git a/app/modules/transactions.js b/app/modules/transactions.js index f1bcc8c4e..999fd5e6b 100644 --- a/app/modules/transactions.js +++ b/app/modules/transactions.js @@ -3,11 +3,7 @@ import { api, sc, u, wallet } from 'neon-js' import { flatMap, keyBy } from 'lodash' -import { - setTransactionHistory, - getBalances, - getTokenBalances -} from './wallet' +import { setTransactionHistory, getBalances, getTokenBalances } from './wallet' import { showErrorNotification, showInfoNotification, @@ -25,7 +21,6 @@ import { getNetwork } from './metadata' import { isToken, validateTransactionsBeforeSending } from '../core/wallet' import { ASSETS } from '../core/constants' -import { adjustDecimalAmountForTokenTransfer } from '../core/nep5' import asyncWrap from '../core/asyncHelper' import { toNumber, toBigNumber } from '../core/math' import { toFixedDecimals, COIN_DECIMAL_LENGTH } from '../core/formatters' @@ -55,7 +50,9 @@ export const syncTransactionHistory = ( ({ NEO, GAS, txid, block_index }: TransactionHistoryType) => ({ txid, [ASSETS.NEO]: toFixedDecimals(NEO, 0), - [ASSETS.GAS]: toBigNumber(GAS).round(COIN_DECIMAL_LENGTH).toString() + [ASSETS.GAS]: toBigNumber(GAS) + .round(COIN_DECIMAL_LENGTH) + .toString() }) ) dispatch(setIsLoadingTransaction(false)) @@ -123,7 +120,7 @@ const buildTransferScript = ( const args = [ u.reverseHex(fromAcct.scriptHash), u.reverseHex(toAcct.scriptHash), - adjustDecimalAmountForTokenTransfer(amount, decimals) + sc.ContractParam.byteArray(toNumber(amount), 'fixed8', decimals) ] scriptBuilder.emitAppCall(scriptHash, 'transfer', args) @@ -133,7 +130,12 @@ const buildTransferScript = ( } const makeRequest = (sendEntries: Array, config: Object) => { - const script = buildTransferScript(config.net, sendEntries, config.address, config.tokensBalanceMap) + const script = buildTransferScript( + config.net, + sendEntries, + config.address, + config.tokensBalanceMap + ) if (script === '') { return api.sendAsset({ ...config, intents: buildIntents(sendEntries) })