1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 21:00:13 +01:00
metamask-extension/ui/app/pages/confirm-approve/confirm-approve.util.js
Dan J Miller 2673eef3c4
Redesign approve screen (#7271)
* Redesign approve screen

* Add translations to approve screen components

* Show account in header of approve screen

* Use state prop bool for unlimited vs custom check in edit-approval-permission

* Set option to custom on input change in edit-approval-permission

* Allow setting of approval amount to unlimited in edit-approval-permission

* Fix height of confirm-approval popup

* Ensure decimals prop passted to confirm-approve.component is correct type

* Ensure first param passed to calcTokenValue in confirm-approve.util is the correct type

* Fix e2e test of permission editing

* Remove unused code from edit-approval-permission.container
2019-11-05 11:43:48 -03:30

29 lines
1.1 KiB
JavaScript

import { decimalToHex } from '../../helpers/utils/conversions.util'
import { calcTokenValue } from '../../helpers/utils/token-util.js'
export function getCustomTxParamsData (data, { customPermissionAmount, tokenAmount, decimals }) {
if (customPermissionAmount) {
const tokenValue = decimalToHex(calcTokenValue(tokenAmount, decimals))
const re = new RegExp('(^.+)' + tokenValue + '$')
const matches = re.exec(data)
if (!matches || !matches[1]) {
return data
}
let dataWithoutCurrentAmount = matches[1]
const customPermissionValue = decimalToHex(calcTokenValue(Number(customPermissionAmount), decimals))
const differenceInLengths = customPermissionValue.length - tokenValue.length
const zeroModifier = dataWithoutCurrentAmount.length - differenceInLengths
if (differenceInLengths > 0) {
dataWithoutCurrentAmount = dataWithoutCurrentAmount.slice(0, zeroModifier)
} else if (differenceInLengths < 0) {
dataWithoutCurrentAmount = dataWithoutCurrentAmount.padEnd(zeroModifier, 0)
}
const customTxParamsData = dataWithoutCurrentAmount + customPermissionValue
return customTxParamsData
}
}