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
};
public async setAddressFromWallet() {
const address = await this.props.wallet.getAddressString();
public setAddressFromWallet() {
const address = this.props.wallet.getAddressString();
if (address !== this.state.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) {
const walletAddress = await props.wallet.getAddressString();
const walletAddress = props.wallet.getAddressString();
this.setState({ walletAddress });
} else {
this.setState({ walletAddress: '' });

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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