Fix working with big numbers in Staking DApp

pull/3479/head
POA 4 years ago
parent 52563b5a1c
commit f0b32529b7
  1. 1
      CHANGELOG.md
  2. 4
      apps/block_scout_web/assets/js/pages/stakes/become_candidate.js
  3. 2
      apps/block_scout_web/assets/js/pages/stakes/make_stake.js
  4. 2
      apps/block_scout_web/assets/js/pages/stakes/move_stake.js
  5. 4
      apps/block_scout_web/assets/js/pages/stakes/withdraw_stake.js
  6. 17
      apps/block_scout_web/lib/block_scout_web/views/stakes_helpers.ex

@ -5,6 +5,7 @@
- [#3462](https://github.com/poanetwork/blockscout/pull/3462) - Display price for bridged tokens
### Fixes
- [#3479](https://github.com/poanetwork/blockscout/pull/3479) - Fix working with big numbers in Staking DApp
- [#3477](https://github.com/poanetwork/blockscout/pull/3477) - Contracts interaction: fix broken call of GnosisProxy contract methods with parameters
- [#3477](https://github.com/poanetwork/blockscout/pull/3477) - Contracts interaction: fix broken call of fallback function
- [#3476](https://github.com/poanetwork/blockscout/pull/3476) - Fix contract verification of precompiled contracts

@ -95,8 +95,8 @@ async function becomeCandidate ($modal, store, msg) {
lockModal($modal)
console.log(`Call addPool(${stake.toString()}, ${miningAddress})`)
makeContractCall(stakingContract.methods.addPool(stake.toString(), miningAddress), store)
console.log(`Call addPool(${stake.toFixed()}, ${miningAddress})`)
makeContractCall(stakingContract.methods.addPool(stake.toFixed(), miningAddress), store)
} catch (err) {
openErrorModal('Error', err.message)
}

@ -73,7 +73,7 @@ async function makeStake ($modal, address, store, msg) {
return
}
makeContractCall(stakingContract.methods.stake(address, stake.toString()), store)
makeContractCall(stakingContract.methods.stake(address, stake.toFixed()), store)
}
function isDelegatorStakeValid (value, store, msg, address) {

@ -66,7 +66,7 @@ function moveStake ($modal, fromAddress, store, msg) {
const stake = new BigNumber($modal.find('[move-amount]').val().replace(',', '.').trim()).shiftedBy(decimals).integerValue()
const toAddress = $modal.find('[pool-select]').val()
makeContractCall(stakingContract.methods.moveStake(fromAddress, toAddress, stake.toString()), store)
makeContractCall(stakingContract.methods.moveStake(fromAddress, toAddress, stake.toFixed()), store)
}
function isMoveAmountValid (value, store, msg) {

@ -69,7 +69,7 @@ function withdrawStake ($modal, address, store, msg) {
const decimals = store.getState().tokenDecimals
const amount = new BigNumber($modal.find('[amount]').val().replace(',', '.').trim()).shiftedBy(decimals).integerValue()
makeContractCall(stakingContract.methods.withdraw(address, amount.toString()), store)
makeContractCall(stakingContract.methods.withdraw(address, amount.toFixed()), store)
}
function orderWithdraw ($modal, address, store, msg) {
@ -85,7 +85,7 @@ function orderWithdraw ($modal, address, store, msg) {
return false
}
makeContractCall(stakingContract.methods.orderWithdraw(address, amount.toString()), store)
makeContractCall(stakingContract.methods.orderWithdraw(address, amount.toFixed()), store)
}
function isAmountValid (value, store, msg) {

@ -41,12 +41,19 @@ defmodule BlockScoutWeb.StakesHelpers do
def list_title(:active), do: Gettext.dgettext(BlockScoutWeb.Gettext, "default", "Active Pools")
def list_title(:inactive), do: Gettext.dgettext(BlockScoutWeb.Gettext, "default", "Inactive Pools")
def from_wei(%Decimal{} = amount, %Token{} = token) do
def from_wei(%Decimal{} = amount, %Token{} = token, to_string \\ true) do
decimals = if token.decimals, do: Decimal.to_integer(token.decimals), else: 0
amount.sign
|> Decimal.new(amount.coef, amount.exp - decimals)
|> Decimal.normalize()
result =
amount.sign
|> Decimal.new(amount.coef, amount.exp - decimals)
|> Decimal.normalize()
if to_string do
Decimal.to_string(result, :normal)
else
result
end
end
def format_token_amount(amount, token, options \\ [])
@ -65,7 +72,7 @@ defmodule BlockScoutWeb.StakesHelpers do
ellipsize = Keyword.get(options, :ellipsize, true)
no_tooltip = Keyword.get(options, :no_tooltip, false)
reduced = from_wei(amount, token)
reduced = from_wei(amount, token, false)
if digits >= -reduced.exp or not ellipsize do
"#{Number.to_string!(reduced, fractional_digits: min(digits, -reduced.exp))}#{symbol}"

Loading…
Cancel
Save