Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ShowStatus: React.SFC {} }> = ({
// timeLeft,
sellAmount,
buyAmount,
buyToken,
status,
claimTokens,
isClaiming,
}) => {
switch (status) {
case Status.ENDED:
if (sellAmount.eq(0) || buyAmount.eq(0)) {
return (
<span>
<big>No funds to claim</big>
</span>
)
}
return (
<span>
<button disabled="{isClaiming" id="claimToken">
<i>CLAIM</i>
<strong>{(buyAmount.div(10 ** buyToken.decimals)).toFixed()} {buyToken.symbol || buyToken.name || buyToken.address}</strong>
<span><img src="{claim}"></span>
</button>
</span>
(await getUnclaimedSellerFunds(pair, index, account)) : toBigNumber(0)
// if theoretically closed, then calculate differently as fraction of current volume
if (theoretically) userCanClaim = buyVolume.div(sellVolume).mul(sellerBalance)
const timeToCompletion = status === AuctionStatus.ACTIVE ? auctionStart.plus(86400 - now).mul(1000).toNumber() : 0
const progress = getProgressStep({
status,
sellerBalance,
})
if (this.interval === null) return true
this.setState({
completed: status === AuctionStatus.ENDED,
theoreticallyCompleted: theoretically,
status,
sell: pair.sell,
buy: pair.buy,
price: price.map(n => n.toNumber()),
closingPrice: closingPrice.map(n => n.toNumber()),
auctionStart,
timeToCompletion,
userSelling: sellerBalance,
userGetting,
userCanClaim,
sellVolume,
buyVolume,
outstandingVolume,
progress,
index,
const outstandingVolumeInverse = await getOutstandingVolume(pair, {
price: priceInverse,
sellVolume: sellVolumesCurrentOpp,
buyVolume: buyVolumesOpp,
auctionIndex: lastIndex,
})
const statusDir: StatusOppDir = { status: AuctionStatus.ACTIVE }
const statusOpp: StatusOppDir = { status: AuctionStatus.ACTIVE }
if (auctionStart.eq(1)) statusDir.status = statusOpp.status = AuctionStatus.INIT
else {
// outstandingVolume <= 0 === THEORETICALLY CLOSED
// TODO: ask why num here and not den
if (closingPriceDir[0].equals(0) && outstandingVolumeNormal.eq(0)) {
statusDir.status = AuctionStatus.ENDED
statusDir.theoreticallyClosed = true
}
if (closingPriceOpp[0].equals(0) && outstandingVolumeInverse.eq(0)) {
statusOpp.status = AuctionStatus.ENDED
statusOpp.theoreticallyClosed = true
}
}
return {
lastIndex,
closingPrices: {
closingPriceDir,
closingPriceOpp,
},
balanceNext: { normal, inverse },
balanceNormal, balanceInverse,
import { connect } from 'react-redux'
import AuctionProgress from 'components/AuctionProgress'
// import { State } from 'types'
import { AuctionStatus as Status } from 'globals'
const status2progress = {
[Status.INIT]: 1,
[Status.PLANNED]: 2,
[Status.ACTIVE]: 3,
[Status.ENDED]: 4,
}
const getAuctionProgress = (status: Status) => status2progress[status] || 0
const mapStateToProps = () => ({
// TODO: populate AuctionStatus in store by querying DutchX regularly or listening for Events
progress: getAuctionProgress(Status.INIT),
})
export default connect(mapStateToProps)(AuctionProgress)
const {
lastIndex,
closingPrices: { closingPriceDir, closingPriceOpp },
balanceNext,
balanceNormal,
balanceInverse,
statusDir,
statusOpp,
auctionStart,
} = lastAuctionsData[index]
const currAuctionNeverRanDir = statusDir.theoreticallyClosed || (balanceNormal.eq(0) && closingPriceDir[1].eq(0))
const currAuctionNeverRanOpp = statusOpp.theoreticallyClosed || (balanceInverse.eq(0) && closingPriceOpp[1].eq(0))
const currAuctionEndedDir = closingPriceDir[1].gt(0) && statusDir.status === AuctionStatus.ENDED
const currAuctionEndedOpp = closingPriceOpp[1].gt(0) && statusOpp.status === AuctionStatus.ENDED
const committedToNextNormal = balanceNext.normal.gt(0)
const committedToNextInverse = balanceNext.inverse.gt(0)
console.log(`
${auction.sell.symbol}->${auction.buy.symbol}-${lastIndex}
closingPriceDir: ${closingPriceDir}
closingPriceOpp: ${closingPriceOpp}
balanceNormal: ${balanceNormal}
balanceInverse: ${balanceInverse}
currAuctionNeverRanDir: ${currAuctionNeverRanDir}
currAuctionNeverRanOpp: ${currAuctionNeverRanOpp}
indicesWithSellerBalance: ${indicesWithSellerBalance}
indicesWithSellerBalanceInverse: ${indicesWithSellerBalanceInverse}
const { decimals: decimalsBuy } = buy
const {
lastIndex,
closingPrices: { closingPriceDir, closingPriceOpp },
balanceNext,
balanceNormal,
balanceInverse,
statusDir,
statusOpp,
auctionStart,
} = lastAuctionsData[index]
const currAuctionNeverRanDir = statusDir.theoreticallyClosed || (balanceNormal.eq(0) && closingPriceDir[1].eq(0))
const currAuctionNeverRanOpp = statusOpp.theoreticallyClosed || (balanceInverse.eq(0) && closingPriceOpp[1].eq(0))
const currAuctionEndedDir = closingPriceDir[1].gt(0) && statusDir.status === AuctionStatus.ENDED
const currAuctionEndedOpp = closingPriceOpp[1].gt(0) && statusOpp.status === AuctionStatus.ENDED
const committedToNextNormal = balanceNext.normal.gt(0)
const committedToNextInverse = balanceNext.inverse.gt(0)
console.log(`
${auction.sell.symbol}->${auction.buy.symbol}-${lastIndex}
closingPriceDir: ${closingPriceDir}
closingPriceOpp: ${closingPriceOpp}
balanceNormal: ${balanceNormal}
balanceInverse: ${balanceInverse}
currAuctionNeverRanDir: ${currAuctionNeverRanDir}
currAuctionNeverRanOpp: ${currAuctionNeverRanOpp}
indicesWithSellerBalance: ${indicesWithSellerBalance}
)
}
return (
<div>
<span>
<small>
{status === Status.ACTIVE ? 'You are not taking part in this auction' : 'You have no deposit in this auction'}
</small>
<big>Take part in the {status === Status.ACTIVE ? 'next' : ''} auction</big>
</span>
</div>
)
}
if (status === Status.ENDED && sellAmount.gt(0)) { return (
<div>
<span>
<small>AMOUNT SOLD</small>
<big>{sellAmount.div(10 ** sellDecimal).toString()} {sellTokenSymbol}</big>
</span>
</div>
)
}
return <div></div>
}
step: 5,
})}
completed={boolean('comleted', true)}
theoreticallyCompleted={boolean('comleted', true)}
claimSellerFunds={() => {}}
/>
,
)
const getProgressStep = ({ status, sellerBalance }: ProgressStepArgs) => {
if (sellerBalance.lte(0) || status === AuctionStatus.INACTIVE) return 0
if (status === AuctionStatus.INIT || status === AuctionStatus.PLANNED) return 1
if (status === AuctionStatus.ACTIVE) return 2
if (status === AuctionStatus.ENDED) return 3
return 0
}