mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-11 19:44:21 +00:00
bf4171dfbd
* Add a little arrow icon. * Replaced toEther function with toUnit to reduce the number of conversion functions wed need. Add tests for conversion functions. * First pass at a styled confirm transaction modal. * More data about data * Hook up generated transaction with modal * Fix modal position * Add from address. Restyle a bit. * Only show textareas and button if transaction has been generated. * Remove need for param. * Copy. * Use non-relative path. * Initial crack at transaction token support. * Fix flow type * Unit tests for contracts and erc20 * Convert contract class to ethereumjs-abi, caught a bug * Add decodeArgs for contracts, decodeTransfer for erc20 * Show token value in modal * Show value from transaction data in confirmation. * Show address of receiver, not token contract * Flow type * Only accept bigs * Unlog * Use ethereumjs-abis method ID function * Get transaction stuff out of state. Leave todo notes. * Intuit token from transaction to address. * Move generate transaction out of node and into libs/transaction. * timeout -> interval * Promise.reject -> throw * Get default currency from network. * Add more unit tests for decoding. Adopt the $ prefix for decoding calls. * Use signed transaction in confirmation modal.
78 lines
1.4 KiB
JavaScript
78 lines
1.4 KiB
JavaScript
// @flow
|
|
import Contract from 'libs/contract';
|
|
import type { ABI } from 'libs/contract';
|
|
import Big from 'bignumber.js';
|
|
import { toChecksumAddress } from 'ethereumjs-util';
|
|
|
|
type Transfer = {
|
|
to: string,
|
|
value: string
|
|
};
|
|
|
|
const erc20Abi: ABI = [
|
|
{
|
|
constant: true,
|
|
inputs: [
|
|
{
|
|
name: '_owner',
|
|
type: 'address'
|
|
}
|
|
],
|
|
name: 'balanceOf',
|
|
outputs: [
|
|
{
|
|
name: 'balance',
|
|
type: 'uint256'
|
|
}
|
|
],
|
|
payable: false,
|
|
type: 'function'
|
|
},
|
|
{
|
|
constant: false,
|
|
inputs: [
|
|
{
|
|
name: '_to',
|
|
type: 'address'
|
|
},
|
|
{
|
|
name: '_value',
|
|
type: 'uint256'
|
|
}
|
|
],
|
|
name: 'transfer',
|
|
outputs: [
|
|
{
|
|
name: 'success',
|
|
type: 'bool'
|
|
}
|
|
],
|
|
payable: false,
|
|
type: 'function'
|
|
}
|
|
];
|
|
|
|
class ERC20 extends Contract {
|
|
constructor() {
|
|
super(erc20Abi);
|
|
}
|
|
|
|
balanceOf(address: string): string {
|
|
return this.call('balanceOf', [address]);
|
|
}
|
|
|
|
transfer(to: string, value: Big): string {
|
|
return this.call('transfer', [to, value.toString()]);
|
|
}
|
|
|
|
$transfer(data: string): Transfer {
|
|
const decodedArgs = this.decodeArgs(this.getMethodAbi('transfer'), data);
|
|
return {
|
|
to: toChecksumAddress(`0x${decodedArgs[0].toString(16)}`),
|
|
value: decodedArgs[1].toString(10)
|
|
};
|
|
}
|
|
}
|
|
|
|
export default new ERC20();
|