Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudahtt committed Jan 28, 2020
1 parent 1746170 commit 4f7d381
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ui/app/pages/confirm-approve/confirm-approve.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getCustomTxParamsData (data, { customPermissionAmount, decimals
const tokenData = getTokenData(data)

if (!tokenData) {
throw new Error(`Invalid data`)
throw new Error('Invalid data')
} else if (tokenData.name !== 'approve') {
throw new Error(`Invalid data; should be 'approve' method, but instead is '${tokenData.name}'`)
}
Expand All @@ -16,12 +16,18 @@ export function getCustomTxParamsData (data, { customPermissionAmount, decimals
}
const [signature, tokenValue] = data.split(spender)

if (!signature || !tokenValue) {
throw new Error('Invalid data')
} else if (tokenValue.length !== 64) {
throw new Error('Invalid token value; should be exactly 64 hex digits long (u256)')
}

let customPermissionValue = decimalToHex(calcTokenValue(customPermissionAmount, decimals))
if (customPermissionValue.length > tokenValue.length) {
throw new Error('Custom value too large')
if (customPermissionValue.length > 64) {
throw new Error('Custom value is larger than u256')
}

customPermissionValue = customPermissionValue.padStart(tokenValue.length, '0')
const customTxParamsData = signature + spender + customPermissionValue
const customTxParamsData = `${signature}${spender}${customPermissionValue}`
return customTxParamsData
}

0 comments on commit 4f7d381

Please sign in to comment.