Skip to content

Commit

Permalink
fix sequence tx, gasPrice
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsource147 committed Jul 11, 2019
1 parent 555b3a3 commit 11edc91
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"empty_order": "There is no order here yet. You can place one",
"you_will_receive": "You will receive",
"submit_successfully": "Your order have been submitted sucessfully to server. You can check the order in your order list.",
"weth_not_supported_tooltip": "Limit orders are supported only for token listed on Kyber. ETH is not supported, Please use WETH instead.",
"weth_not_supported_tooltip": "Limit Order only supports ERC20, you have to convert ETH to WETH (ERC20 form of ETH) to use this functionality.",
"wrap_eth_modal_title": "Convert ETH to WETH",
"login_to_submit": "Login to Submit Order",
"submit": "Submit",
Expand Down
2 changes: 1 addition & 1 deletion lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
"empty_order": "There is no order here yet. You can place one",
"you_will_receive": "You will receive",
"submit_successfully": "Your order have been submitted sucessfully to server. You can check the order in your order list.",
"weth_not_supported_tooltip": "Limit orders are supported only for token listed on Kyber. ETH is not supported, Please use WETH instead.",
"weth_not_supported_tooltip": "Limit Order only supports ERC20, you have to convert ETH to WETH (ERC20 form of ETH) to use this functionality.",
"wrap_eth_modal_title": "Convert ETH to WETH",
"login_to_submit": "Login to Submit Order",
"submit": "Submit",
Expand Down
3 changes: 2 additions & 1 deletion src/js/containers/Exchange/ExchangeModals/ApproveMaxModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export default class ApproveMaxModal extends React.Component {
var password = ""

try {
var txHash = await wallet.broadCastTx("getAppoveToken", this.props.ethereum, this.props.exchange.sourceToken, 0, this.props.account.nonce, this.state.gasLimit,
var nonce = this.props.account.getUsableNonce()
var txHash = await wallet.broadCastTx("getAppoveToken", this.props.ethereum, this.props.exchange.sourceToken, 0, nonce, this.state.gasLimit,
converter.toHex(converter.gweiToWei(this.props.exchange.gasPrice)), this.props.account.keystring, password, this.props.account.type, this.props.account.address, BLOCKCHAIN_INFO.network)

this.props.dispatch(exchangeActions.saveApproveMaxTx(this.props.exchange.sourceTokenSymbol, txHash));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default class ApproveZeroModal extends React.Component {
var wallet = getWallet(this.props.account.type)
var password = ""
try {
var txHash = await wallet.broadCastTx("getAppoveTokenZero", this.props.ethereum, this.props.exchange.sourceToken, 0, this.props.account.nonce, this.state.gasLimit,
var nonce = this.props.account.getUsableNonce()
var txHash = await wallet.broadCastTx("getAppoveTokenZero", this.props.ethereum, this.props.exchange.sourceToken, 0, nonce, this.state.gasLimit,
converter.toHex(converter.gweiToWei(this.props.exchange.gasPrice)), this.props.account.keystring, password, this.props.account.type, this.props.account.address, BLOCKCHAIN_INFO.network)

this.props.dispatch(exchangeActions.saveApproveZeroTx(this.props.exchange.sourceTokenSymbol, txHash));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export default class ApproveMaxModal extends React.Component {
var wallet = getWallet(this.props.account.type)
var password = ""
try {
var txHash = await wallet.broadCastTx("getAppoveToken", this.props.ethereum, this.props.limitOrder.sourceToken, 0, this.props.account.nonce, this.state.gasLimit,
var nonce = this.props.account.getUsableNonce()
var txHash = await wallet.broadCastTx("getAppoveToken", this.props.ethereum, this.props.limitOrder.sourceToken, 0, nonce, this.state.gasLimit,
converter.toHex(converter.gweiToWei(this.props.limitOrder.gasPrice)), this.props.account.keystring, password, this.props.account.type, this.props.account.address, BLOCKCHAIN_INFO.kyberswapAddress)

this.props.dispatch(limitOrderActions.saveApproveMaxTx(this.props.limitOrder.sourceTokenSymbol, txHash));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export default class ApproveZeroModal extends React.Component {
var wallet = getWallet(this.props.account.type)
var password = ""
try {
var txHash = await wallet.broadCastTx("getAppoveTokenZero", this.props.ethereum, this.props.limitOrder.sourceToken, 0, this.props.account.nonce, this.state.gasLimit,
var nonce = this.props.account.getUsableNonce()
var txHash = await wallet.broadCastTx("getAppoveTokenZero", this.props.ethereum, this.props.limitOrder.sourceToken, 0, nonce, this.state.gasLimit,
converter.toHex(converter.gweiToWei(this.props.limitOrder.gasPrice)), this.props.account.keystring, password, this.props.account.type, this.props.account.address, BLOCKCHAIN_INFO.kyberswapAddress)

this.props.dispatch(limitOrderActions.saveApproveZeroTx(this.props.limitOrder.sourceTokenSymbol, txHash));
Expand Down
6 changes: 4 additions & 2 deletions src/js/containers/LimitOrder/LimitOrderModals/WrapETHModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export default class WrapETHModal extends React.Component {

var minConversionRate = converters.toHex(Math.pow(10, 18))
var blockNo = constants.EXCHANGE_CONFIG.COMMISSION_ADDR
var nonce = this.props.account.nonce
// var nonce = this.props.account.nonce
var nonce = this.props.account.getUsableNonce()

var gas = this.props.limitOrder.max_gas
var gasPrice = converters.toHex(converters.gweiToWei(this.props.limitOrder.gasPrice))
var keystring = this.props.account.keystring
Expand Down Expand Up @@ -222,7 +224,7 @@ export default class WrapETHModal extends React.Component {

<div className="message">
<span>{this.props.translate("limit_order.wrap_eth_notify") || "Your order can not be submited because your WETH is not enough, please convert ETH to WETH."}</span>
<span className="weth-modal-tooltip-icon" data-tip={this.props.translate("limit_order.weth_not_supported_tooltip") || 'Limit orders are supported only for token listed on Kyber. ETH is not supported, Please use WETH instead.'} data-for="weth-tooltip" currentitem="false">
<span className="weth-modal-tooltip-icon" data-tip={this.props.translate("limit_order.weth_not_supported_tooltip") || 'Limit Order only supports ERC20, you have to convert ETH to WETH (ERC20 form of ETH) to use this functionality.'} data-for="weth-tooltip" currentitem="false">
<img src={require("../../../../assets/img/v3/info_grey.svg")} />
</span>
<ReactTooltip class={"weth-modal-tooltip"} id="weth-tooltip" effect="solid" type="dark" place="left" />
Expand Down
9 changes: 4 additions & 5 deletions src/js/reducers/accountReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ const account = (state= JSON.parse(JSON.stringify(initState)), action) => {
return {...newState};
}
case "ACCOUNT.INC_MANUAL_NONCE_ACCOUNT":{
var oldState = {...state}
var newState = {...state}
var address = action.payload
if ((oldState.account) && (oldState.account.address === address)){
var account = oldState.account.incManualNonce()
return {...state,
account: account}
if ((newState.account) && (newState.account.address.toLowerCase() === address.toLowerCase())){
newState.account = newState.account.incManualNonce()
}
return newState
}
case "ACCOUNT.PKEY_CHANGE": {
let newState = {...state}
Expand Down
23 changes: 14 additions & 9 deletions src/js/sagas/globalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,30 @@ export function* setGasPrice(action) {
try {
const gasPrice = yield call([ethereum, ethereum.call], "getGasPrice")

safeLowGas = gasPrice.low
standardGas = gasPrice.standard
defaultGas = gasPrice.default
fastGas = gasPrice.fast
superFastGas = 2 * fastGas;
safeLowGas = converter.stringToNumber(gasPrice.low)
standardGas = converter.stringToNumber(gasPrice.standard)
defaultGas = converter.stringToNumber(gasPrice.default)
fastGas = converter.stringToNumber(gasPrice.fast)


var selectedGas = 's'
var fastGasFloat = parseFloat(fastGas)

if (fastGasFloat <= 20){
defaultGas = gasPrice.fast
superFastGas = 2 * fastGas;

if (fastGas <= 20){
defaultGas = fastGas
selectedGas = 'f'
}

if (fastGasFloat <= 10) {
if (fastGas <= 10) {
superFastGas = 20;
}

if (superFastGas > maxGasPrice) superFastGas = maxGasPrice;
if (safeLowGas > maxGasPrice) safeLowGas = maxGasPrice;
if (standardGas > maxGasPrice) standardGas = maxGasPrice;
if (defaultGas > maxGasPrice) defaultGas = maxGasPrice;
if (fastGas > maxGasPrice) fastGas = maxGasPrice;

yield put(actions.setGasPriceComplete(safeLowGas, standardGas, fastGas, superFastGas, defaultGas, selectedGas));
}catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/sagas/limitOrderActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function* fetchPendingBalances(action) {

function validatePendingBalances(currentPendingTxs, newPendingBalances, newPendingTxs) {
let pendingTxs = [];

console.log(currentPendingTxs)
newPendingTxs.forEach(newPendingTx => {
const existingTx = currentPendingTxs.find((currentPendingTx) => {
return currentPendingTx.tx_hash === newPendingTx.tx_hash;
Expand Down
8 changes: 8 additions & 0 deletions src/js/utils/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ export function stringToBigNumber(number) {
return bigNumber
}

export function stringToNumber(str) {
var bigNumber = new BigNumber(str)
if (bigNumber == 'NaN' || bigNumber == 'Infinity') {
return 0
}
return bigNumber.toNumber()
}



export function getBigNumberValueByPercentage(number, percentage) {
Expand Down

0 comments on commit 11edc91

Please sign in to comment.