From c2ee2e0c9a8ff839d47345ee9ce4b92652de078a Mon Sep 17 00:00:00 2001 From: kata Date: Wed, 4 Sep 2019 14:20:21 +0800 Subject: [PATCH 01/11] Skip 429 error from tx API for connection status --- src/containers/ConnectionStatus/saga.js | 6 +++++- src/containers/ConnectionStatus/tests/saga.test.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/containers/ConnectionStatus/saga.js b/src/containers/ConnectionStatus/saga.js index 1bb09e85..5ccbdaaa 100644 --- a/src/containers/ConnectionStatus/saga.js +++ b/src/containers/ConnectionStatus/saga.js @@ -43,7 +43,11 @@ export const errorSuccessPairs = { [LOAD_PRICES_ERROR]: LOAD_PRICES_SUCCESS, }; -export function* handleError({ type }) { +export function* handleError({ type, error }) { + if (type === LOAD_TRANSACTIONS_ERROR && error.message.match(/too many request/i)) { + return; + } + const successType = errorSuccessPairs[type]; const { timeout } = yield race({ timeout: call(delay, 5000), diff --git a/src/containers/ConnectionStatus/tests/saga.test.js b/src/containers/ConnectionStatus/tests/saga.test.js index c2d82550..6b6cb166 100644 --- a/src/containers/ConnectionStatus/tests/saga.test.js +++ b/src/containers/ConnectionStatus/tests/saga.test.js @@ -12,6 +12,8 @@ import { LOAD_NAHMII_BALANCES_SUCCESS, } from 'containers/NahmiiHoc/constants'; +import { LOAD_TRANSACTIONS_ERROR } from 'containers/HubiiApiHoc/constants'; + import root, { handleError, errorSuccessPairs } from '../saga'; import { networkFailure, networkReconnected } from '../actions'; @@ -38,6 +40,17 @@ describe('handleError saga', () => { .not.put(networkReconnected(LOAD_NAHMII_BALANCES_ERROR)) .run() ); + + it('skip 429 error for transaction API', () => + expectSaga(handleError, { type: LOAD_TRANSACTIONS_ERROR, error: new Error('Too Many Request') }) + .provide({ + race: () => ({ timeout: true }), + take: () => {}, + }) + .not.put(networkFailure(LOAD_TRANSACTIONS_ERROR)) + .not.put(networkReconnected(LOAD_TRANSACTIONS_ERROR)) + .run() + ); }); describe('root Saga', () => { From 1bbb2ffca6c99ba75453f7132dd157c85bb27e9d Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 5 Sep 2019 12:17:48 +0800 Subject: [PATCH 02/11] Pop up gas price warning modal when its value is lower than average. --- src/containers/NahmiiWithdraw/index.js | 64 +++- src/containers/NahmiiWithdraw/style.js | 30 ++ .../tests/__snapshots__/index.test.js.snap | 290 ++++++++++++++++++ src/translations/en.json | 4 + src/translations/zh.json | 4 + 5 files changed, 389 insertions(+), 3 deletions(-) diff --git a/src/containers/NahmiiWithdraw/index.js b/src/containers/NahmiiWithdraw/index.js index 6701cded..7a21209d 100644 --- a/src/containers/NahmiiWithdraw/index.js +++ b/src/containers/NahmiiWithdraw/index.js @@ -31,6 +31,7 @@ import SelectableText from 'components/ui/SelectableText'; import TooltipText from 'components/ui/TooltipText'; import Input from 'components/ui/Input'; import Select, { Option } from 'components/ui/Select'; +import { Modal } from 'components/ui/Modal'; import TransferDescriptionItem from 'components/TransferDescriptionItem'; import GasOptions from 'components/GasOptions'; import AgreementButton from 'components/AgreementButton'; @@ -74,6 +75,9 @@ import { SettlementWarning, ScrollableContentWrapper, StyledSteps, + ModalTitleWrapper, + ModalButtonWrapper, + ModalContainer, } from './style'; const Step = Steps.Step; @@ -111,6 +115,7 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea gasLimit: 2000000, gasLimitInput: '2000000', addContactModalVisibility: false, + showGasPriceConfirmModal: false, }; this.onFocusNumberInput = this.onFocusNumberInput.bind(this); this.onBlurNumberInput = this.onBlurNumberInput.bind(this); @@ -119,7 +124,8 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea this.handleAssetChange = this.handleAssetChange.bind(this); this.generateTxStatus = this.generateTxStatus.bind(this); this.getRequiredSettlementAmount = this.getRequiredSettlementAmount.bind(this); - this.startChallenge = this.startChallenge.bind(this); + this.handleStartSettlement = this.handleStartSettlement.bind(this); + this.startSettlement = this.startSettlement.bind(this); this.settle = this.settle.bind(this); this.withdraw = this.withdraw.bind(this); @@ -190,15 +196,35 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea this.props.settle(currentWalletWithInfo.get('address'), currency, options); } - startChallenge(stageAmount, assetToWithdraw) { + getSuggestedGasPrice = () => { + const { gasStatistics } = this.props; + const estimate = gasStatistics.get('estimate'); + const suggestedGasPrice = estimate ? parseFloat(estimate.average / 10) : 10; + return suggestedGasPrice; + } + + startSettlement(stageAmount, assetToWithdraw) { const { currentWalletWithInfo } = this.props; const { assetToWithdrawMaxDecimals, gasLimit, gasPriceGwei } = this.state; + const currency = this.getCurrencyAddress(assetToWithdraw.currency); const stageAmountBN = stageAmount.times(new BigNumber(10).pow(assetToWithdrawMaxDecimals)); const options = { gasLimit, gasPrice: gweiToWei(gasPriceGwei).toNumber() || null }; this.props.startChallenge(currentWalletWithInfo.get('address'), currency, stageAmountBN, options); } + handleStartSettlement(stageAmount, assetToWithdraw) { + const { gasPriceGwei } = this.state; + const suggestedGasPrice = this.getSuggestedGasPrice(); + + if (gasPriceGwei.toNumber() < suggestedGasPrice) { + this.setState({ showGasPriceConfirmModal: true }); + return; + } + + this.startSettlement(stageAmount, assetToWithdraw); + } + withdraw(amountToWithdraw, assetToWithdraw) { const { currentWalletWithInfo } = this.props; const { assetToWithdrawMaxDecimals, gasLimit, gasPriceGwei } = this.state; @@ -784,7 +810,7 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea {TxStatus} ) : ( - this.startChallenge(requiredSettlementAmount, assetToWithdraw)} disabled={disableSettleButton}> + this.handleStartSettlement(requiredSettlementAmount, assetToWithdraw)} disabled={disableSettleButton}> {formatMessage({ id: 'settle_balance' })} ) @@ -950,6 +976,38 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea {this.renderSteppers()} + this.setState({ showGasPriceConfirmModal: false })} + destroyOnClose + > + + {formatMessage({ id: 'low_gas_price_warning_title' })} + + + {formatMessage({ id: 'low_gas_price_warning_content' }, { + gas_price: gasPriceGwei.toNumber(), + average: this.getSuggestedGasPrice(), + })} + + + { + this.setState({ showGasPriceConfirmModal: false }); + this.startSettlement(requiredSettlementAmount, assetToWithdraw); + }} + > + {formatMessage({ id: 'continue' })} + + this.setState({ showGasPriceConfirmModal: false })}> + {formatMessage({ id: 'update_gas_price' })} + + + ); } diff --git a/src/containers/NahmiiWithdraw/style.js b/src/containers/NahmiiWithdraw/style.js index 522265c6..3b5ea1a3 100644 --- a/src/containers/NahmiiWithdraw/style.js +++ b/src/containers/NahmiiWithdraw/style.js @@ -125,3 +125,33 @@ export const StyledSteps = styled(Steps)` color: ${({ theme }) => theme.palette.info1}; } `; + +export const ModalTitleWrapper = styled.div` + font-size: 1.6rem; + margin: 0 2rem; + text-align: center; + color: ${({ theme }) => theme.palette.light}; + font-weight: 400; +`; + +export const ModalContainer = styled.div` + overflow-x: hidden; + max-height: 400px; + padding: 2rem 0; + h1 { + color: ${({ theme }) => theme.palette.light}; + } + h2 { + color: ${({ theme }) => theme.palette.light}; + } + h3 { + color: ${({ theme }) => theme.palette.light}; + } +`; + +export const ModalButtonWrapper = styled.div` + display: flex; + justify-content: center; + margin-top: ${(props) => props.loading ? '1.79rem' : '3.57rem'}; + margin-bottom: 1.86rem; +`; diff --git a/src/containers/NahmiiWithdraw/tests/__snapshots__/index.test.js.snap b/src/containers/NahmiiWithdraw/tests/__snapshots__/index.test.js.snap index 6ad23c76..ff30d90e 100644 --- a/src/containers/NahmiiWithdraw/tests/__snapshots__/index.test.js.snap +++ b/src/containers/NahmiiWithdraw/tests/__snapshots__/index.test.js.snap @@ -996,6 +996,39 @@ ShallowWrapper { } /> , + + + low_gas_price_warning_title + + + low_gas_price_warning_content {"gas_price":10,"average":10} + + + + continue + + + update_gas_price + + +, ], }, "ref": null, @@ -3277,6 +3310,118 @@ ShallowWrapper { }, "type": [Function], }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": Array [ + + low_gas_price_warning_title +, + + low_gas_price_warning_content {"gas_price":10,"average":10} +, + + + continue + + + update_gas_price + +, + ], + "destroyOnClose": true, + "footer": null, + "maskClosable": true, + "onCancel": [Function], + "style": Object { + "marginTop": "1.43rem", + }, + "visible": false, + "width": "41.79rem", + }, + "ref": null, + "rendered": Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "low_gas_price_warning_title", + }, + "ref": null, + "rendered": "low_gas_price_warning_title", + "type": [Function], + }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "low_gas_price_warning_content {\\"gas_price\\":10,\\"average\\":10}", + }, + "ref": null, + "rendered": "low_gas_price_warning_content {\\"gas_price\\":10,\\"average\\":10}", + "type": [Function], + }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": Array [ + + continue +, + + update_gas_price +, + ], + }, + "ref": null, + "rendered": Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "continue", + "onClick": [Function], + }, + "ref": null, + "rendered": "continue", + "type": [Function], + }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "update_gas_price", + "onClick": [Function], + "type": "primary", + }, + "ref": null, + "rendered": "update_gas_price", + "type": [Function], + }, + ], + "type": [Function], + }, + ], + "type": [Function], + }, ], "type": [Function], }, @@ -3644,6 +3789,39 @@ ShallowWrapper { } /> , + + + low_gas_price_warning_title + + + low_gas_price_warning_content {"gas_price":10,"average":10} + + + + continue + + + update_gas_price + + +, ], }, "ref": null, @@ -5925,6 +6103,118 @@ ShallowWrapper { }, "type": [Function], }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": Array [ + + low_gas_price_warning_title +, + + low_gas_price_warning_content {"gas_price":10,"average":10} +, + + + continue + + + update_gas_price + +, + ], + "destroyOnClose": true, + "footer": null, + "maskClosable": true, + "onCancel": [Function], + "style": Object { + "marginTop": "1.43rem", + }, + "visible": false, + "width": "41.79rem", + }, + "ref": null, + "rendered": Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "low_gas_price_warning_title", + }, + "ref": null, + "rendered": "low_gas_price_warning_title", + "type": [Function], + }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "low_gas_price_warning_content {\\"gas_price\\":10,\\"average\\":10}", + }, + "ref": null, + "rendered": "low_gas_price_warning_content {\\"gas_price\\":10,\\"average\\":10}", + "type": [Function], + }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": Array [ + + continue +, + + update_gas_price +, + ], + }, + "ref": null, + "rendered": Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "continue", + "onClick": [Function], + }, + "ref": null, + "rendered": "continue", + "type": [Function], + }, + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": "update_gas_price", + "onClick": [Function], + "type": "primary", + }, + "ref": null, + "rendered": "update_gas_price", + "type": [Function], + }, + ], + "type": [Function], + }, + ], + "type": [Function], + }, ], "type": [Function], }, diff --git a/src/translations/en.json b/src/translations/en.json index 18e42379..ddc2f596 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -135,6 +135,8 @@ "delete_confirm": "Are you sure you want to delete this {type}?", "delete": "Delete", "cancel": "Cancel", + "continue": "Continue", + "update_gas_price": "Update gas price", "name": "Name", "back": "Back", "next": "Next", @@ -276,6 +278,8 @@ "settle_payment_type": "Settlement", "settlement_history": "Settlement History", "gas_limit_too_low": "Gas limit is too low, please try increase the gas limit.", + "low_gas_price_warning_title": "Continue with a low gas price?", + "low_gas_price_warning_content": "The gas price ({gas_price} GWei) for this transaction is lower than the average ({average} GWei). Setting a gas price too low could lead the transaction to never be mined or be mined after a very long time. During its mining period, the wallet's payment function for this currency will be disabled. We highly recommend setting the gas price to a greater value than the average.", "checks_before_settling": "Preparing settlement...", "checks_before_confirming_settle": "Confirming settlement...", "requesting_settle": "Requesting settlement...", diff --git a/src/translations/zh.json b/src/translations/zh.json index 60edea41..887edb5a 100644 --- a/src/translations/zh.json +++ b/src/translations/zh.json @@ -135,6 +135,8 @@ "delete_confirm": "请确认是否删除此 {type}?", "delete": "删除", "cancel": "取消", + "continue": "继续", + "update_gas_price": "修改 Gas 价格", "name": "名称", "back": "返回", "next": "下一步", @@ -276,6 +278,8 @@ "settle_payment_type": "结算", "settlement_history": "结算历史", "gas_limit_too_low": "Gas 阈值太低,请提高阈值.", + "low_gas_price_warning_title": "继续使用这个低价 Gas?", + "low_gas_price_warning_content": "目前这个事务请求的设定 Gas 价格 ({gas_price} GWei) 低于均值 ({average} GWei)。使用低价 Gas 会导致事务请求没法被网络确认,或是需要很长一段时间才能得到确认。在这事务确认期间,该钱包下的此货币资产的付款功能会被禁止。我们强烈建议把 Gas 价格设置高于目前的均值。", "checks_before_settling": "准备结算...", "checks_before_confirming_settle": "确认结算...", "requesting_settle": "请求结算...", From 1cfed7c46914c7aa8312e3df27a1515910eb6d1a Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 5 Sep 2019 16:38:50 +0800 Subject: [PATCH 03/11] Make it able to recognise the nahmii deposit transactions in the wallet details view. --- src/components/Transaction/index.js | 3 ++- src/containers/WalletTransactions/index.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/Transaction/index.js b/src/components/Transaction/index.js index bca36e59..d526c476 100644 --- a/src/components/Transaction/index.js +++ b/src/components/Transaction/index.js @@ -61,7 +61,8 @@ const Transaction = (props) => { type={type === 'received' ? 'download' : 'upload'} /> - {type === 'received' ? formatMessage({ id: 'received' }) : formatMessage({ id: 'sent' })} + {type === 'deposit' && } + {formatMessage({ id: type })} {symbol} diff --git a/src/containers/WalletTransactions/index.js b/src/containers/WalletTransactions/index.js index e24588ed..019b08a1 100644 --- a/src/containers/WalletTransactions/index.js +++ b/src/containers/WalletTransactions/index.js @@ -7,6 +7,8 @@ import { compose } from 'redux'; import { injectIntl } from 'react-intl'; import { createStructuredSelector } from 'reselect'; import BigNumber from 'bignumber.js'; +import { NahmiiContract } from 'nahmii-sdk'; +import { isAddressMatch } from 'utils/wallet'; import Breakdown from 'components/BreakdownPie'; import SectionHeading from 'components/ui/SectionHeading'; @@ -91,6 +93,9 @@ export class WalletsTransactions extends React.Component { const { formatMessage } = intl; const start = (currentPage - 1) * 10; const end = start + 10; + + const clientFundContract = new NahmiiContract('ClientFund', currentNetwork.provider); + let filtered = currentWalletWithInfo.getIn(['transactions', 'transactions']); if (filter !== 'all') { filtered = currentWalletWithInfo @@ -105,9 +110,16 @@ export class WalletsTransactions extends React.Component { .find((a) => a.get('currency') === tx.get('currency')); const txFiatValue = assetPrices ? new BigNumber(tx.get('decimalAmount')).times(assetPrices.get('usd')).toString() : 0; const confirmations = ((blockHeight.get('height') - tx.getIn(['block', 'number'])) + 1).toString(); + + let type = tx.get('type'); + if (type === 'sent' && isAddressMatch(tx.get('counterpartyAddress'), clientFundContract.address)) { + type = 'deposit'; + } + return tx .set('fiatValue', txFiatValue) - .set('confirmations', confirmations); + .set('confirmations', confirmations) + .set('type', type); }) .toJS(); From be84d178939731467c91445987fc7534ddd9f57a Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 5 Sep 2019 16:43:14 +0800 Subject: [PATCH 04/11] Update snapshot --- .../tests/__snapshots__/index.test.js.snap | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/Transaction/tests/__snapshots__/index.test.js.snap b/src/components/Transaction/tests/__snapshots__/index.test.js.snap index b7a6d440..c81195d5 100644 --- a/src/components/Transaction/tests/__snapshots__/index.test.js.snap +++ b/src/components/Transaction/tests/__snapshots__/index.test.js.snap @@ -987,7 +987,7 @@ ShallowWrapper { type="upload" /> - sent + recieved - sent + recieved - sent + recieved - sent + recieved - sent + recieved - sent + recieved - sent + nahmii - sent + nahmii - sent + nahmii - sent + nahmii - sent + nahmii - sent + nahmii Date: Mon, 9 Sep 2019 13:04:58 +0800 Subject: [PATCH 05/11] Wording for low_gas_price_warning_content --- src/translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/translations/en.json b/src/translations/en.json index ddc2f596..ae4f7e80 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -279,7 +279,7 @@ "settlement_history": "Settlement History", "gas_limit_too_low": "Gas limit is too low, please try increase the gas limit.", "low_gas_price_warning_title": "Continue with a low gas price?", - "low_gas_price_warning_content": "The gas price ({gas_price} GWei) for this transaction is lower than the average ({average} GWei). Setting a gas price too low could lead the transaction to never be mined or be mined after a very long time. During its mining period, the wallet's payment function for this currency will be disabled. We highly recommend setting the gas price to a greater value than the average.", + "low_gas_price_warning_content": "The gas price ({gas_price} GWei) for this transaction is lower than the average ({average} GWei). Setting a gas price too low can lead a transaction never being mined or a very long delay. During its mining period, the wallet's payment function for this currency will be disabled. We therefore recommend setting the gas price to a greater value than the average.", "checks_before_settling": "Preparing settlement...", "checks_before_confirming_settle": "Confirming settlement...", "requesting_settle": "Requesting settlement...", From 365d1767281140f06ae3f400c18d913f8ec52a28 Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 12 Sep 2019 09:06:51 +0800 Subject: [PATCH 06/11] Upgrade SDK --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79f34abc..bb8d2dd2 100644 --- a/package.json +++ b/package.json @@ -318,7 +318,7 @@ "minimist": "1.2.0", "moment": "2.22.2", "nahmii-ethereum-address": "^2.0.1", - "nahmii-sdk": "3.0.5", + "nahmii-sdk": "3.0.6", "prop-types": "15.6.1", "qrcode.react": "0.8.0", "react": "16.6.3", From 582ab51cc1d9a7dbe713ea1f99670fe7fe2c828f Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 12 Sep 2019 09:07:07 +0800 Subject: [PATCH 07/11] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb8d2dd2..4ef740fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hubii-core", - "version": "1.2.2", + "version": "1.2.3", "author": { "name": "hubii", "email": "info@hubii.com", From 3a2e4e973e52d7b75ce6496e5ffd55f4a4ad1e4b Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 12 Sep 2019 09:25:38 +0800 Subject: [PATCH 08/11] Update yarn.lock --- yarn.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/yarn.lock b/yarn.lock index bd92ca21..09c5cd6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9688,15 +9688,15 @@ mute-stream@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" -nahmii-contract-abstractions-ropsten@3.1.3: - version "3.1.3" - resolved "https://registry.yarnpkg.com/nahmii-contract-abstractions-ropsten/-/nahmii-contract-abstractions-ropsten-3.1.3.tgz#ee0f605923df8d1c301f2644ead78d21c5308db0" +nahmii-contract-abstractions-ropsten@3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/nahmii-contract-abstractions-ropsten/-/nahmii-contract-abstractions-ropsten-3.1.4.tgz#26b0749a350879627c940edfb2445fb42da85319" dependencies: glob "^7.1.4" -nahmii-contract-abstractions@2.1.3: - version "2.1.3" - resolved "https://registry.yarnpkg.com/nahmii-contract-abstractions/-/nahmii-contract-abstractions-2.1.3.tgz#3c48c5e4f55b8ba975fe8b959f57e4375073f4e5" +nahmii-contract-abstractions@2.1.4: + version "2.1.4" + resolved "https://registry.yarnpkg.com/nahmii-contract-abstractions/-/nahmii-contract-abstractions-2.1.4.tgz#0ebc57e139065dceb175351a60bd286ddda1826e" dependencies: glob "^7.1.4" @@ -9704,14 +9704,14 @@ nahmii-ethereum-address@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/nahmii-ethereum-address/-/nahmii-ethereum-address-2.0.1.tgz#7b31f04d5748cb58c63312b96d7a51bb4ceab6f2" -nahmii-sdk@3.0.5: - version "3.0.5" - resolved "https://registry.yarnpkg.com/nahmii-sdk/-/nahmii-sdk-3.0.5.tgz#aba70caf8625780575228ea7d7a965778caf3368" +nahmii-sdk@3.0.6: + version "3.0.6" + resolved "https://registry.yarnpkg.com/nahmii-sdk/-/nahmii-sdk-3.0.6.tgz#4e906daf7c9cf5bfc2cd6dd17f23f7bdf3ce1c88" dependencies: ethereumjs-util "^6.1.0" lodash.get "^4.4.2" - nahmii-contract-abstractions "2.1.3" - nahmii-contract-abstractions-ropsten "3.1.3" + nahmii-contract-abstractions "2.1.4" + nahmii-contract-abstractions-ropsten "3.1.4" socket.io-client "^2.2.0" superagent "^5.1.0" uuid "^3.3.2" From bb2657a780e22528ffbddb66fcc4b9e7605469c4 Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 12 Sep 2019 09:54:31 +0800 Subject: [PATCH 09/11] Fix snapshot test --- .../tests/__snapshots__/index.test.js.snap | 378 +++++++----------- .../Transaction/tests/index.test.js | 4 +- 2 files changed, 145 insertions(+), 237 deletions(-) diff --git a/src/components/Transaction/tests/__snapshots__/index.test.js.snap b/src/components/Transaction/tests/__snapshots__/index.test.js.snap index c81195d5..4d9c6755 100644 --- a/src/components/Transaction/tests/__snapshots__/index.test.js.snap +++ b/src/components/Transaction/tests/__snapshots__/index.test.js.snap @@ -956,7 +956,7 @@ ShallowWrapper { onChange={[Function]} symbol="UKG" time={1995-01-09T04:19:09.000Z} - type="recieved" + type="received" viewOnBlockExplorerClick={[Function]} />, Symbol(enzyme.__renderer__): Object { @@ -984,10 +984,10 @@ ShallowWrapper { src="/public/images/assets/UKG.svg" /> - recieved + received - to: + from: 0x00 @@ -1073,10 +1073,10 @@ ShallowWrapper { src="/public/images/assets/UKG.svg" /> - recieved + received - to: + from: 0x00 @@ -1162,7 +1162,7 @@ ShallowWrapper { } > - to: + from: 0x00 @@ -1197,10 +1197,10 @@ ShallowWrapper { src="/public/images/assets/UKG.svg" /> - recieved + received - to: + from: 0x00 @@ -1283,7 +1283,7 @@ ShallowWrapper { "props": Object { "children": Array [ - to: + from: , 0x00 @@ -1302,13 +1302,13 @@ ShallowWrapper { "props": Object { "children": Array [ false, - "to:", + "from:", ], }, "ref": null, "rendered": Array [ false, - "to:", + "from:", ], "type": [Function], }, @@ -1442,10 +1442,10 @@ ShallowWrapper { src="/public/images/assets/UKG.svg" /> - recieved + received - to: + from: 0x00 @@ -1531,10 +1531,10 @@ ShallowWrapper { src="/public/images/assets/UKG.svg" /> - recieved + received - to: + from: 0x00 @@ -1620,7 +1620,7 @@ ShallowWrapper { } > - to: + from: 0x00 @@ -1655,10 +1655,10 @@ ShallowWrapper { src="/public/images/assets/UKG.svg" /> - recieved + received - to: + from: 0x00 @@ -1741,7 +1741,7 @@ ShallowWrapper { "props": Object { "children": Array [ - to: + from: , 0x00 @@ -1760,13 +1760,13 @@ ShallowWrapper { "props": Object { "children": Array [ false, - "to:", + "from:", ], }, "ref": null, "rendered": Array [ false, - "to:", + "from:", ], "type": [Function], }, @@ -2864,11 +2864,11 @@ ShallowWrapper { "formatNumber": [Function], } } - layer="baseLayer" + layer="nahmii" onChange={[Function]} symbol="UKG" time={1995-01-09T04:19:09.000Z} - type="nahmii" + type="sent" viewOnBlockExplorerClick={[Function]} />, Symbol(enzyme.__renderer__): Object { @@ -2899,7 +2899,7 @@ ShallowWrapper { type="upload" /> - nahmii + sent + 01/09/1995 @@ -2950,20 +2957,14 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + - view_etherscan + view_nahmii_explorer @@ -2988,7 +2989,7 @@ ShallowWrapper { type="upload" /> - nahmii + sent + 01/09/1995 @@ -3039,20 +3047,14 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + - view_etherscan + view_nahmii_explorer , @@ -3087,20 +3089,14 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + - view_etherscan + view_nahmii_explorer , "header": @@ -3112,7 +3108,7 @@ ShallowWrapper { type="upload" /> - nahmii + sent + 01/09/1995 @@ -3168,22 +3171,16 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + , + false, - view_etherscan + view_nahmii_explorer , - false, ], }, "ref": null, @@ -3244,16 +3241,10 @@ ShallowWrapper { "nodeType": "host", "props": Object { "children": Array [ -
- - confirmations - : - - - 204 - -
, false, + + confirmed +, ], "style": Object { "display": "flex", @@ -3261,71 +3252,34 @@ ShallowWrapper { }, "ref": null, "rendered": Array [ + false, Object { "instance": null, "key": undefined, - "nodeType": "host", + "nodeType": "class", "props": Object { - "children": Array [ - - confirmations - : -, - - 204 -, - ], + "children": "confirmed", }, "ref": null, - "rendered": Array [ - Object { - "instance": null, - "key": undefined, - "nodeType": "class", - "props": Object { - "children": Array [ - "confirmations", - ":", - ], - }, - "ref": null, - "rendered": Array [ - "confirmations", - ":", - ], - "type": [Function], - }, - Object { - "instance": null, - "key": undefined, - "nodeType": "class", - "props": Object { - "children": "204", - }, - "ref": null, - "rendered": "204", - "type": [Function], - }, - ], - "type": "div", + "rendered": "confirmed", + "type": [Function], }, - false, ], "type": "div", }, + false, Object { "instance": null, "key": undefined, "nodeType": "class", "props": Object { - "children": "view_etherscan", - "onClick": [Function], + "children": "view_nahmii_explorer", + "disabled": true, }, "ref": null, - "rendered": "view_etherscan", + "rendered": "view_nahmii_explorer", "type": [Function], }, - false, ], "type": [Function], }, @@ -3357,7 +3311,7 @@ ShallowWrapper { type="upload" /> - nahmii + sent + 01/09/1995 @@ -3408,20 +3369,14 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + - view_etherscan + view_nahmii_explorer @@ -3446,7 +3401,7 @@ ShallowWrapper { type="upload" /> - nahmii + sent + 01/09/1995 @@ -3497,20 +3459,14 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + - view_etherscan + view_nahmii_explorer , @@ -3545,20 +3501,14 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + - view_etherscan + view_nahmii_explorer , "header": @@ -3570,7 +3520,7 @@ ShallowWrapper { type="upload" /> - nahmii + sent + 01/09/1995 @@ -3626,22 +3583,16 @@ ShallowWrapper { } } > -
- - confirmations - : - - - 204 - -
+ + confirmed + , + false, - view_etherscan + view_nahmii_explorer , - false, ], }, "ref": null, @@ -3702,16 +3653,10 @@ ShallowWrapper { "nodeType": "host", "props": Object { "children": Array [ -
- - confirmations - : - - - 204 - -
, false, + + confirmed +, ], "style": Object { "display": "flex", @@ -3719,71 +3664,34 @@ ShallowWrapper { }, "ref": null, "rendered": Array [ + false, Object { "instance": null, "key": undefined, - "nodeType": "host", + "nodeType": "class", "props": Object { - "children": Array [ - - confirmations - : -, - - 204 -, - ], + "children": "confirmed", }, "ref": null, - "rendered": Array [ - Object { - "instance": null, - "key": undefined, - "nodeType": "class", - "props": Object { - "children": Array [ - "confirmations", - ":", - ], - }, - "ref": null, - "rendered": Array [ - "confirmations", - ":", - ], - "type": [Function], - }, - Object { - "instance": null, - "key": undefined, - "nodeType": "class", - "props": Object { - "children": "204", - }, - "ref": null, - "rendered": "204", - "type": [Function], - }, - ], - "type": "div", + "rendered": "confirmed", + "type": [Function], }, - false, ], "type": "div", }, + false, Object { "instance": null, "key": undefined, "nodeType": "class", "props": Object { - "children": "view_etherscan", - "onClick": [Function], + "children": "view_nahmii_explorer", + "disabled": true, }, "ref": null, - "rendered": "view_etherscan", + "rendered": "view_nahmii_explorer", "type": [Function], }, - false, ], "type": [Function], }, diff --git a/src/components/Transaction/tests/index.test.js b/src/components/Transaction/tests/index.test.js index 15a66484..fa80445b 100644 --- a/src/components/Transaction/tests/index.test.js +++ b/src/components/Transaction/tests/index.test.js @@ -31,7 +31,7 @@ describe('', () => { const wrapper = shallow( ); expect(wrapper).toMatchSnapshot(); }); @@ -49,7 +49,7 @@ describe('', () => { const wrapper = shallow( ); expect(wrapper).toMatchSnapshot(); }); From f8609633921e4e307bc443442e255056e7b1f379 Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 12 Sep 2019 11:01:46 +0800 Subject: [PATCH 10/11] Increase the limit of the receipt API request, trying to fetch all the receipts in one request. --- src/containers/NahmiiHoc/saga.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/containers/NahmiiHoc/saga.js b/src/containers/NahmiiHoc/saga.js index b66ad244..5023ee75 100644 --- a/src/containers/NahmiiHoc/saga.js +++ b/src/containers/NahmiiHoc/saga.js @@ -5,7 +5,7 @@ import { utils } from 'ethers'; import { all, fork, takeEvery, takeLatest, select, put, call, take, cancel, race } from 'redux-saga/effects'; import { delay } from 'redux-saga'; import BigNumber from 'bignumber.js'; -import { requestWalletAPI, requestHardwareWalletAPI } from 'utils/request'; +import { requestHardwareWalletAPI } from 'utils/request'; import rpcRequest from 'utils/rpcRequest'; import { isAddressMatch } from 'utils/wallet'; import { logErrorMsg } from 'utils/friendlyErrors'; @@ -707,26 +707,10 @@ export function* loadSettleableChallenges({ address, currency }, network, noPoll } } -export function* loadReceipts({ address }, network) { - while (true) { // eslint-disable-line no-constant-condition - try { - const path = `trading/wallets/${address}/receipts?`; - let receipts = yield call((...args) => requestWalletAPI(...args), path, network); - receipts = receipts.map((r) => ({ ...r, operatorId: 0 })); - yield put(actions.loadReceiptsSuccess(address, receipts)); - } catch (err) { - yield put(actions.loadReceiptsError(address)); - } finally { - const TWENTY_SEC_IN_MS = 1000 * 20; - yield delay(TWENTY_SEC_IN_MS); - } - } -} - export function* loadWalletReceipts({ address }, network) { while (true) { // eslint-disable-line no-constant-condition try { - const receipts = yield call(network.nahmiiProvider.getWalletReceipts.bind(network.nahmiiProvider), address); + const receipts = yield call(network.nahmiiProvider.getWalletReceipts.bind(network.nahmiiProvider), address, null, 1000); yield put(actions.loadReceiptsSuccess(address, receipts)); } catch (e) { yield put(actions.loadReceiptsError(address, e)); From 4d4427dc5cc204d8ed2882239c83dc2c649718f5 Mon Sep 17 00:00:00 2001 From: kata Date: Thu, 12 Sep 2019 12:03:53 +0800 Subject: [PATCH 11/11] Improve selector caching for receipt data --- src/containers/NahmiiHoc/selectors.js | 14 +++++--------- .../NahmiiHoc/tests/selectors.test.js | 18 +++++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/containers/NahmiiHoc/selectors.js b/src/containers/NahmiiHoc/selectors.js index 64951a0f..a66a62c1 100644 --- a/src/containers/NahmiiHoc/selectors.js +++ b/src/containers/NahmiiHoc/selectors.js @@ -23,17 +23,13 @@ export const createReceiptsSelector = createSelectorCreator( (previousArray, currentArray) => { let changed = false; currentArray.keySeq().forEach((address) => { - const previousReceipts = previousArray.getIn([address, 'receipts']); - const currentReceipts = currentArray.getIn([address, 'receipts']); + const previousReceipts = previousArray.getIn([address, 'receipts']) || fromJS([]); + const currentReceipts = currentArray.getIn([address, 'receipts']) || fromJS([]); - if (!currentReceipts && !previousReceipts) { - return; - } + const previousLastCreated = previousReceipts.getIn([previousReceipts.size - 1, 'created']); + const currentLastCreated = currentReceipts.getIn([currentReceipts.size - 1, 'created']); - if ( - (!previousReceipts && currentReceipts) || - (previousReceipts.size !== currentReceipts.size) - ) { + if (previousLastCreated !== currentLastCreated) { changed = true; } }); diff --git a/src/containers/NahmiiHoc/tests/selectors.test.js b/src/containers/NahmiiHoc/tests/selectors.test.js index c3b70002..985dea6b 100644 --- a/src/containers/NahmiiHoc/tests/selectors.test.js +++ b/src/containers/NahmiiHoc/tests/selectors.test.js @@ -80,16 +80,11 @@ describe('makeSelectReceipts', () => { receiptsSelector(storeMock.setIn(['nahmiiHoc', 'receipts', address, 'receipts'], null)) ).toEqual(receiptsLoaded.setIn([address, 'receipts'], null)); }); - it('should update the cache when the current receipts state has initialised array value', () => { - expect( - receiptsSelector(storeMock.setIn(['nahmiiHoc', 'receipts', address, 'receipts'], [])) - ).toEqual(receiptsLoaded.setIn([address, 'receipts'], [])); - }); }); describe('when previous receipts state has initialised', () => { - const store = storeMock.setIn(['nahmiiHoc', 'receipts', address, 'receipts'], fromJS([{}])); - const txs = receiptsLoaded.setIn([address, 'receipts'], fromJS([{}])); + const store = storeMock.setIn(['nahmiiHoc', 'receipts', address, 'receipts'], fromJS([{ created: '2018' }])); + const txs = receiptsLoaded.setIn([address, 'receipts'], fromJS([{ created: '2018' }])); beforeEach(() => { expect( receiptsSelector(store) @@ -98,11 +93,16 @@ describe('makeSelectReceipts', () => { describe('should update the cache', () => { it('when the size of receipts array is different from previous state', () => { expect(receiptsSelector( - store.updateIn(['nahmiiHoc', 'receipts', address, 'receipts'], (arr) => arr.push({})) - )).toEqual(txs.updateIn([address, 'receipts'], (arr) => arr.push({}))); + store.updateIn(['nahmiiHoc', 'receipts', address, 'receipts'], (arr) => arr.push(fromJS({ created: '2019' }))) + )).toEqual(txs.updateIn([address, 'receipts'], (arr) => arr.push(fromJS({ created: '2019' })))); }); }); describe('should not update the cache', () => { + it('when the last created property is the same', () => { + expect(receiptsSelector( + store.updateIn(['nahmiiHoc', 'receipts', address, 'receipts'], (arr) => arr.push(fromJS({ created: '2018' }))) + )).toEqual(txs); + }); it('even when the loading state is changed', () => { expect(txs.getIn([address, 'loading'])).toEqual(false); expect(receiptsSelector(