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:
parent
f2bf7529b3
commit
a50dc2ebb0
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -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: '' });
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -2,7 +2,7 @@ import Tx from 'ethereumjs-tx';
|
|||
|
||||
interface IBaseWallet {
|
||||
isReadOnly?: boolean;
|
||||
getAddressString(): Promise<string> | string;
|
||||
getAddressString(): string;
|
||||
getPrivateKeyString?(): string;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue