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
|
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 });
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: '' });
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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 });
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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> {
|
||||||
|
|
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue