Adjust Wallet Interface (#1154)

* Adjust Base Wallet Interface to not return promises' for getAdderssString; adjust callers to not await

* remove async for saveWalletConfig
This commit is contained in:
Daniel Ternyak 2018-02-21 12:23:04 -06:00 committed by GitHub
parent f2bf7529b3
commit a50dc2ebb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 23 deletions

View File

@ -39,8 +39,8 @@ class AccountInfo extends React.Component<Props, State> {
confirmAddr: false confirmAddr: false
}; };
public async setAddressFromWallet() { public setAddressFromWallet() {
const address = await this.props.wallet.getAddressString(); const address = this.props.wallet.getAddressString();
if (address !== this.state.address) { if (address !== this.state.address) {
this.setState({ address }); this.setState({ address });
} }

View File

@ -47,9 +47,9 @@ class CurrentCustomMessageClass extends PureComponent<Props, State> {
} }
} }
private async setAddressState(props: Props) { private setAddressState(props: Props) {
if (props.wallet) { if (props.wallet) {
const walletAddress = await props.wallet.getAddressString(); const walletAddress = props.wallet.getAddressString();
this.setState({ walletAddress }); this.setState({ walletAddress });
} else { } else {
this.setState({ walletAddress: '' }); this.setState({ walletAddress: '' });

View File

@ -141,8 +141,8 @@ class RequestPayment extends React.Component<Props, {}> {
); );
} }
private async setWalletAsyncState(wallet: IWallet) { private setWalletAsyncState(wallet: IWallet) {
this.props.setCurrentTo(await wallet.getAddressString()); this.props.setCurrentTo(wallet.getAddressString());
} }
private generateEIP681String( private generateEIP681String(

View File

@ -115,7 +115,7 @@ export default class WalletInfo extends React.PureComponent<Props, State> {
} }
private async setWalletAsyncState(wallet: IWallet) { private async setWalletAsyncState(wallet: IWallet) {
const address = await wallet.getAddressString(); const address = wallet.getAddressString();
const privateKey = wallet.getPrivateKeyString ? await wallet.getPrivateKeyString() : ''; const privateKey = wallet.getPrivateKeyString ? await wallet.getPrivateKeyString() : '';
this.setState({ address, privateKey }); this.setState({ address, privateKey });
} }

View File

@ -25,7 +25,7 @@ export default class SignMessageButton extends React.Component<Props, {}> {
try { try {
const signedMessage: ISignedMessage = { const signedMessage: ISignedMessage = {
address: await wallet.getAddressString(), address: wallet.getAddressString(),
msg: message, msg: message,
sig: await wallet.signMessage(message), sig: await wallet.signMessage(message),
version: '2' version: '2'

View File

@ -2,7 +2,7 @@ import Tx from 'ethereumjs-tx';
interface IBaseWallet { interface IBaseWallet {
isReadOnly?: boolean; isReadOnly?: boolean;
getAddressString(): Promise<string> | string; getAddressString(): string;
getPrivateKeyString?(): string; getPrivateKeyString?(): string;
} }

View File

@ -9,8 +9,8 @@ export class DeterministicWallet {
this.index = index; this.index = index;
} }
public getAddressString(): Promise<string> { public getAddressString(): string {
return Promise.resolve(this.address); return this.address;
} }
public getPath(): string { public getPath(): string {

View File

@ -15,8 +15,8 @@ export default class Web3Wallet implements IFullWallet {
this.network = network; this.network = network;
} }
public getAddressString(): Promise<string> { public getAddressString(): string {
return Promise.resolve(this.address); return this.address;
} }
public signRawTransaction(): Promise<Buffer> { public signRawTransaction(): Promise<Buffer> {

View File

@ -36,20 +36,17 @@ export function loadStatePropertyOrEmptyObject<T>(key: string): T | undefined {
return undefined; return undefined;
} }
export async function saveWalletConfig( export function saveWalletConfig(wallet: IWallet, state: Partial<WalletConfig>): WalletConfig {
wallet: IWallet, const oldState = loadWalletConfig(wallet);
state: Partial<WalletConfig>
): Promise<WalletConfig> {
const oldState = await loadWalletConfig(wallet);
const newState = { ...oldState, ...state }; const newState = { ...oldState, ...state };
const key = await getWalletConfigKey(wallet); const key = getWalletConfigKey(wallet);
localStorage.setItem(key, JSON.stringify(newState)); localStorage.setItem(key, JSON.stringify(newState));
return newState; return newState;
} }
export async function loadWalletConfig(wallet: IWallet): Promise<WalletConfig> { export function loadWalletConfig(wallet: IWallet): WalletConfig {
try { try {
const key = await getWalletConfigKey(wallet); const key = getWalletConfigKey(wallet);
const state = localStorage.getItem(key); const state = localStorage.getItem(key);
return state ? JSON.parse(state) : {}; return state ? JSON.parse(state) : {};
} catch (err) { } catch (err) {
@ -58,7 +55,7 @@ export async function loadWalletConfig(wallet: IWallet): Promise<WalletConfig> {
} }
} }
async function getWalletConfigKey(wallet: IWallet): Promise<string> { function getWalletConfigKey(wallet: IWallet): string {
const address = await wallet.getAddressString(); const address = wallet.getAddressString();
return sha256(`${address}-mycrypto`).toString('hex'); return sha256(`${address}-mycrypto`).toString('hex');
} }