You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.0 KiB
97 lines
2.0 KiB
4 years ago
|
import ethAbi from 'ethereumjs-abi';
|
||
|
import { TOKEN_TRANSFER_FUNCTION_SIGNATURE } from '../send.constants';
|
||
4 years ago
|
import { addHexPrefix } from '../../../../app/scripts/lib/util';
|
||
4 years ago
|
import { addHexPrefixToObjectValues } from '../../../helpers/utils/util';
|
||
7 years ago
|
|
||
4 years ago
|
export function constructTxParams({
|
||
|
sendToken,
|
||
|
data,
|
||
|
to,
|
||
|
amount,
|
||
|
from,
|
||
|
gas,
|
||
|
gasPrice,
|
||
|
}) {
|
||
7 years ago
|
const txParams = {
|
||
6 years ago
|
data,
|
||
7 years ago
|
from,
|
||
|
value: '0',
|
||
|
gas,
|
||
|
gasPrice,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
5 years ago
|
if (!sendToken) {
|
||
4 years ago
|
txParams.value = amount;
|
||
|
txParams.to = to;
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
return addHexPrefixToObjectValues(txParams);
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
export function constructUpdatedTx({
|
||
7 years ago
|
amount,
|
||
6 years ago
|
data,
|
||
7 years ago
|
editingTransactionId,
|
||
|
from,
|
||
|
gas,
|
||
|
gasPrice,
|
||
5 years ago
|
sendToken,
|
||
7 years ago
|
to,
|
||
|
unapprovedTxs,
|
||
|
}) {
|
||
4 years ago
|
const unapprovedTx = unapprovedTxs[editingTransactionId];
|
||
4 years ago
|
const txParamsData = unapprovedTx.txParams.data
|
||
|
? unapprovedTx.txParams.data
|
||
4 years ago
|
: data;
|
||
6 years ago
|
|
||
7 years ago
|
const editingTx = {
|
||
6 years ago
|
...unapprovedTx,
|
||
|
txParams: Object.assign(
|
||
|
unapprovedTx.txParams,
|
||
|
addHexPrefixToObjectValues({
|
||
|
data: txParamsData,
|
||
|
to,
|
||
|
from,
|
||
|
gas,
|
||
|
gasPrice,
|
||
|
value: amount,
|
||
4 years ago
|
}),
|
||
6 years ago
|
),
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
5 years ago
|
if (sendToken) {
|
||
4 years ago
|
Object.assign(
|
||
|
editingTx.txParams,
|
||
|
addHexPrefixToObjectValues({
|
||
|
value: '0',
|
||
|
to: sendToken.address,
|
||
|
data:
|
||
|
TOKEN_TRANSFER_FUNCTION_SIGNATURE +
|
||
|
Array.prototype.map
|
||
|
.call(
|
||
|
ethAbi.rawEncode(
|
||
|
['address', 'uint256'],
|
||
4 years ago
|
[to, addHexPrefix(amount)],
|
||
4 years ago
|
),
|
||
|
(x) => `00${x.toString(16)}`.slice(-2),
|
||
|
)
|
||
|
.join(''),
|
||
|
}),
|
||
4 years ago
|
);
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
6 years ago
|
if (typeof editingTx.txParams.data === 'undefined') {
|
||
4 years ago
|
delete editingTx.txParams.data;
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
4 years ago
|
return editingTx;
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
export function addressIsNew(toAccounts, newAddress) {
|
||
4 years ago
|
const newAddressNormalized = newAddress.toLowerCase();
|
||
4 years ago
|
const foundMatching = toAccounts.some(
|
||
|
({ address }) => address.toLowerCase() === newAddressNormalized,
|
||
4 years ago
|
);
|
||
|
return !foundMatching;
|
||
7 years ago
|
}
|