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-766: Redeem winnings didn't work #487

Merged
merged 4 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion config/mainnet/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"title": "Gnosis Trading Interface"
},
"whitelist": {
"0x9eab578556de5782445ec036f25a41902ba19eeb": "Gnosis"
"0x9eab578556de5782445ec036f25a41902ba19eeb": "Gnosis",
"0xe7e3272a84cf3fe180345b9f7234ba705eb5e2ca": "Mikhail"
},
"thirdparty": {
"googleAnalytics": {
Expand Down
79 changes: 70 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"@storybook/addon-links": "^3.4.8",
"@storybook/react": "^3.4.8",
"autodll-webpack-plugin": "^0.4.2",
"autoprefixer": "^9.1.1",
"autoprefixer": "^9.1.4",
"babel-core": "^7.0.0-0",
"babel-eslint": "^9.0.0",
"babel-jest": "^23.2.0",
Expand Down Expand Up @@ -166,7 +166,7 @@
"truffle-hdwallet-provider": "0.0.6",
"uglifyjs-webpack-plugin": "^1.3.0",
"url-loader": "^1.1.1",
"webpack": "^4.16.4",
"webpack": "^4.17.2",
"webpack-cli": "^3.0.4",
"webpack-dev-server": "^3.1.4"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import className from 'classnames/bind'
import OutcomeColorBox from 'components/Outcome/OutcomeColorBox'
import DecimalValue from 'components/DecimalValue'
import CurrencyName from 'components/CurrencyName'
import { LOWEST_VALUE } from 'utils/constants'
import { weiToEth } from 'utils/helpers'
import { OutcomeRecord } from 'store/models/market'

Expand All @@ -13,11 +14,20 @@ import style from './style.scss'
const cx = className.bind(style)

const Share = ({
id, marketTitle, marketType, market, outcomeToken, collateralTokenAddress, balance, marginalPrice,
id,
marketTitle,
marketType,
market,
outcomeToken,
collateralTokenAddress,
balance,
marginalPrice,
redeemWinnings,
winnings,
}) => {
const showSellLink = !market.closed && !market.resolved
const showRedeemLink = market.resolved
const showRedeemLink = market.resolved && winnings >= LOWEST_VALUE

const handleRedeemWinnings = () => redeemWinnings(market)

return (
Expand All @@ -29,19 +39,25 @@ const Share = ({
</div>
<div className={cx('outcome')}>
<div className={cx('outcomeBox')}>
<OutcomeColorBox scheme={marketType} outcomeIndex={outcomeToken.index} />&nbsp;
<OutcomeColorBox scheme={marketType} outcomeIndex={outcomeToken.index} />
&nbsp;
<span className={cx('outcomeText')}>{outcomeToken.name}</span>
</div>
<div className={cx('shareAmount')}>
<DecimalValue value={weiToEth(balance)} />
</div>
<div className={cx('sharePrice')}>
<DecimalValue value={marginalPrice} />&nbsp;
{collateralTokenAddress ? <CurrencyName tokenAddress={collateralTokenAddress} /> : <span>ETH</span> }
<DecimalValue value={marginalPrice} />
&nbsp;
{collateralTokenAddress ? <CurrencyName tokenAddress={collateralTokenAddress} /> : <span>ETH</span>}
</div>
<div className={cx('shareAction')}>
{showSellLink && <Link to={`/markets/${market.address}/my-shares/${id}`}>SELL</Link>}
{showRedeemLink && <button className={cx('redeemWinnings', 'btn', 'btn-link')} type="button" onClick={handleRedeemWinnings}>REDEEM WINNINGS</button>}
{showRedeemLink && (
<button className={cx('redeemWinnings', 'btn', 'btn-link')} type="button" onClick={handleRedeemWinnings}>
REDEEM WINNINGS
</button>
)}
</div>
</div>
</div>
Expand All @@ -58,6 +74,7 @@ Share.propTypes = {
outcomeToken: PropTypes.shape(OutcomeRecord).isRequired,
collateralTokenAddress: PropTypes.string.isRequired,
redeemWinnings: PropTypes.func.isRequired,
winnings: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}

export default Share
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { OUTCOME_TYPES } from 'utils/constants'

const SCALAR_OUTCOME_RANGE = 1000000

const calcShareWinningsCategorical = (share, market) => {
const { winningOutcome } = market
const calcShareWinningsCategorical = (share, { winningOutcome }) => {
const shareOutcome = share.outcomeToken.index
if (shareOutcome !== winningOutcome) {
if (shareOutcome !== winningOutcome.index) {
return '0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const Details = ({
winningsAmount={winningsTotal}
handleRedeemWinnings={handleRedeemWinnings}
transactionGas={redeemWinningsTransactionGas}
collateralToken={market.event.collateralToken}
collateralToken={market.collateralToken}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const mapDispatchToProps = dispatch => ({
buyShares: (market, outcomeIndex, outcomeTokenCount, cost) => dispatch(buyMarketShares(market, outcomeIndex, outcomeTokenCount, cost)),
sellShares: (market, outcomeIndex, outcomeTokenCount, earnings) => dispatch(sellMarketShares(market, outcomeIndex, outcomeTokenCount, earnings)),
changeUrl: url => dispatch(replace(url)),
redeemWinnings: market => redeemMarket(market),
redeemWinnings: market => dispatch(redeemMarket(market)),
requestGasCost: (contractType, opts) => dispatch(requestGasCost(contractType, opts)),
requestGasPrice: () => dispatch(requestGasPrice()),
requestTokenSymbol: tokenAddress => dispatch(requestTokenSymbol(tokenAddress)),
Expand Down
10 changes: 10 additions & 0 deletions src/store/selectors/account/shares.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createSelector } from 'reselect'
import Decimal from 'decimal.js'
import { getCollateralToken } from 'store/selectors/blockchain'
import { normalizeHex } from 'utils/helpers'
import { calcShareWinnings } from 'routes/Dashboard/containers/Dashboard/utils'

export const sharesWithMarketsSelector = createSelector(
state => state.marketList,
Expand All @@ -22,6 +23,15 @@ const shareSelector = createSelector(sharesWithMarketsSelector, getCollateralTok
&& typeof share.market !== 'undefined'
&& normalizeHex(share.collateralTokenAddress) === normalizeHex(collateralToken.address),
)
.map((share) => {
let shareWinnings = '0'

if (share.market.resolved) {
shareWinnings = calcShareWinnings(share, share.market)
}

return share.set('winnings', shareWinnings)
})
.sortBy(share => share.marketResolution, (dateA, dateB) => (dateA.isBefore(dateB) ? -1 : 1))
.values(),
))
Expand Down
8 changes: 4 additions & 4 deletions src/store/selectors/market/shares.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export const sharesForMarketSelector = (state, marketAddress) => {
const market = state.marketList.get(marketAddress)

if (market) {
const marketShares = state.marketShares.filter(marketShare => (
marketShare.eventAddress === market.eventAddress &&
marketShare.collateralTokenAddress === collateralToken.address
))
const marketShares = state.accountShares.filter(
marketShare => marketShare.eventAddress === market.eventAddress
&& marketShare.collateralTokenAddress === collateralToken.address,
)

return List(marketShares.values())
}
Expand Down