William O'Beirne e7633c6d2f MyEtherWallet -> MyCrypto (#977)
* Replace all mentions of MyEtherWallet in translations with MyCrypto

* Replace all translation mentions of kvhnuke/etherwallet repo with MyCryptoHQ/MyCrypto repo.

* Replace all instances of MEW with MyCrypto in translations.

* Replace all instances of myetherwallet.com with mycrypto.com

* First pass of myetherwallet -> mycrypto in codebase.

* Replace most MEWs and mews with MyCrypto or MyC or myc

* Update all assets, clean out unused old assets.

* Adjust v3 url

* Convert all links to help articles to a help link component to make future changes easier.

* Rework onboarding images

* Adjust logo colors due to CMY issue.

* Update donation address, remove mentions of mewtopia.eth

* Update license

* Update sosh meed and referral links.

* Fix more translations strings.

* Tscheck fix.

* Update shapeshift api key.
2018-02-06 22:28:28 -06:00

80 lines
2.3 KiB
TypeScript

import { getTransactionFields, makeTransaction } from 'libs/transaction';
import { IFullWallet } from '../IWallet';
import { networkIdToName } from 'libs/values';
import { bufferToHex } from 'ethereumjs-util';
import { configuredStore } from 'store';
import { getNodeLib } from 'selectors/config';
import Web3Node, { isWeb3Node } from 'libs/nodes/web3';
import { INode } from 'libs/nodes/INode';
export default class Web3Wallet implements IFullWallet {
private address: string;
private network: string;
constructor(address: string, network: string) {
this.address = address;
this.network = network;
}
public getAddressString(): Promise<string> {
return Promise.resolve(this.address);
}
public signRawTransaction(): Promise<Buffer> {
return Promise.reject(new Error('Web3 wallets cannot sign raw transactions.'));
}
public async signMessage(msg: string): Promise<string> {
const msgHex = bufferToHex(Buffer.from(msg));
const state = configuredStore.getState();
const nodeLib: Web3Node | INode = getNodeLib(state);
if (!isWeb3Node(nodeLib)) {
throw new Error('Web3 wallets can only be used with a Web3 node.');
}
return nodeLib.signMessage(msgHex, this.address);
}
public async sendTransaction(serializedTransaction: string): Promise<string> {
const transactionInstance = makeTransaction(serializedTransaction);
const { to, value, gasLimit: gas, gasPrice, data, nonce, chainId } = getTransactionFields(
transactionInstance
);
const from = this.address;
const web3Tx = {
from,
to,
value,
gas,
gasPrice,
data,
nonce,
chainId
};
const state = configuredStore.getState();
const nodeLib: Web3Node | INode = getNodeLib(state);
if (!isWeb3Node(nodeLib)) {
throw new Error('Web3 wallets can only be used with a Web3 node.');
}
await this.networkCheck(nodeLib);
return nodeLib.sendTransaction(web3Tx);
}
private async networkCheck(lib: Web3Node) {
const netId = await lib.getNetVersion();
const netName = networkIdToName(netId);
if (this.network !== netName) {
throw new Error(
`Expected MetaMask / Mist network to be ${
this.network
}, but got ${netName}. Please change the network or refresh the page.`
);
}
}
}