Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG PM-628: Selling the min amount of tokens (0.000000000000000001) makes a transaction error in some markets #394

Merged
merged 17 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/components/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ const useUport = defaultProvider === WALLET_PROVIDER.UPORT

class Header extends Component {
componentDidMount() {
if (requireRegistration && this.props.currentAccount) {
const { currentAccount } = this.props

if (requireRegistration && currentAccount) {
this.props.requestMainnetAddress()
}

if (this.props.currentAccount) {
this.props.requestTokenBalance(this.props.currentAccount)
if (currentAccount) {
this.props.requestTokenBalance(currentAccount)

if (tournamentEnabled) {
this.props.fetchTournamentUserData(currentAccount)
}
}
}

componentDidUpdate(prevProps) {
// If user unlocks metamask, changes his account, we need to check if the account was registered
const shouldRequestMainnetAddress =
requireRegistration && this.props.currentAccount !== prevProps.currentAccount
const shouldRequestMainnetAddress = requireRegistration && this.props.currentAccount !== prevProps.currentAccount
if (shouldRequestMainnetAddress) {
this.props.requestMainnetAddress()
}
Expand Down Expand Up @@ -102,7 +107,6 @@ class Header extends Component {
walletConnected = hasWallet && !!mainnetAddress
}


const logoVars = {}
if (tournamentEnabled) {
logoVars['--logoAnnotation'] = "'Powered by Gnosis'"
Expand Down Expand Up @@ -160,7 +164,8 @@ class Header extends Component {
<div className={cx('group', 'right')}>
{canInteract ? (
<div className={cx('account')}>
{currentNetwork && currentNetwork !== 'MAIN' && (
{currentNetwork &&
currentNetwork !== 'MAIN' && (
<span className={cx('network', 'text')}>Network: {upperFirst(currentNetwork.toLowerCase())}</span>
)}
<DecimalValue value={tokenBalance} className={cx('text')} />&nbsp;
Expand Down Expand Up @@ -204,6 +209,7 @@ Header.propTypes = {
initUport: PropTypes.func.isRequired,
openModal: PropTypes.func.isRequired,
acceptedTOS: PropTypes.bool,
fetchTournamentUserData: PropTypes.func.isRequired,
}

Header.defaultProps = {
Expand Down
2 changes: 2 additions & 0 deletions src/containers/HeaderContainer/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { initProviders } from 'integrations/store/actions'
import { WALLET_PROVIDER } from 'integrations/constants'

import { getCollateralToken } from 'store/selectors/blockchain'
import { fetchTournamentUserData } from 'routes/Scoreboard/store'

/**
* Requests the configured tournaments collateralToken balance. If none is set, does nothing
Expand Down Expand Up @@ -33,6 +34,7 @@ const requestCollateralTokenBalance = account => (dispatch, getState) => {

export default {
requestMainnetAddress,
fetchTournamentUserData: accountAddress => dispatch => dispatch(fetchTournamentUserData(accountAddress)),
requestTokenBalance: requestCollateralTokenBalance,
openModal: modalName => dispatch => dispatch(openModal({ modalName })),
initUport: () => dispatch => dispatch(initProviders({ providers: [WALLET_PROVIDER.UPORT] })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import style from './ShareSellView.mod.scss'

const cx = cn.bind(style)

const inputErrorStyle = {
whiteSpace: 'nowrap',
}

class ShareSellView extends Component {
componentDidUpdate() {
const { selectedSellAmount, share, initialize } = this.props
Expand All @@ -40,12 +44,14 @@ class ShareSellView extends Component {

@autobind
validateTokenCount(val) {
const { share } = this.props
if (!val || !NUMBER_REGEXP.test(val)) {
const { share, market } = this.props
if (!val || !NUMBER_REGEXP.test(val) || Decimal(val).lt(1e-18)) {
return 'Invalid amount'
}

const decimalValue = Decimal(val)
const earnings = calculateEarnings(market, share, web3.utils.toWei(val))

if (decimalValue.lt(0)) {
return "Number can't be negative."
}
Expand All @@ -54,6 +60,10 @@ class ShareSellView extends Component {
return "You're trying to sell more than you invested."
}

if (Decimal(0).eq(earnings)) {
return 'You are trying to sell an invalid amount. This transaction would result in a loss of an outcome token, due to costs of this transaction.'
}

return undefined
}

Expand Down Expand Up @@ -141,6 +151,7 @@ class ShareSellView extends Component {
placeholder="Enter Token Amount"
className={cx('sharesSellAmount')}
validate={this.validateTokenCount}
errorStyle={inputErrorStyle}
/>
</div>

Expand Down