better handling of approvals

This commit is contained in:
Barry Gitarts 2019-12-19 10:38:25 -05:00
parent ebf03d0495
commit 7d3cd5ce52
2 changed files with 5 additions and 3 deletions

View File

@ -67,10 +67,12 @@ async function stepperProgress(values, projectData, submissionState, currencies)
if (submissionState === CONFIRMED) return IS_CONFIRMED
if (submissionState === AUTHORIZATION_SUBMITTED) return NOT_APPROVED
if (submissionState === SUBMITTED) return IS_SUBMITTED
if (submissionState === APPROVED || fundToken === IS_ETH) return IS_APPROVED
if (fundToken === IS_ETH) return IS_APPROVED
if (!projectData.account) return NOT_CONNECTED
const { chainReadibleFn, getAllowance } = getTokenByAddress(fundToken, currencies)
const authorization = await getAllowance()
const { manifest: { goalToken } } = projectData
const spender = fundToken.toLowerCase() === goalToken.toLowerCase() ? LiquidPledging._address : SwapProxy._address
const authorization = await getAllowance(spender)
const sanitizedAmount = amount.replace(/\D/g,'')
const weiAmount = sanitizedAmount ? chainReadibleFn(sanitizedAmount) : '0'
const isAuthorized = Number(authorization) >= Number(weiAmount)

View File

@ -28,7 +28,7 @@ function mapToCurrencyFormat(currency) {
contract,
humanReadibleFn: generateHumanReadibleFn(decimals),
chainReadibleFn: generateChainReadibleFn(decimals),
getAllowance: () => getLpAllowance(contract),
getAllowance: spender => getLpAllowance(contract, spender),
setAllowance: generateSetApprovalFn(contract)
}
}