Re-set address state when wallet changes (#1107)

This commit is contained in:
William O'Beirne 2018-02-16 15:34:58 -05:00 committed by Daniel Ternyak
parent 31912c0f83
commit c5f32a9ce2

View File

@ -13,19 +13,24 @@ interface ReduxProps {
wallet: AppState['wallet']['inst'];
}
type Props = ReduxProps;
interface State {
walletAddress: string | null;
}
class CurrentCustomMessageClass extends PureComponent<ReduxProps, State> {
class CurrentCustomMessageClass extends PureComponent<Props, State> {
public state: State = {
walletAddress: null
};
public async componentDidMount() {
if (this.props.wallet) {
const walletAddress = await this.props.wallet.getAddressString();
this.setState({ walletAddress });
this.setAddressState(this.props);
}
public componentWillReceiveProps(nextProps: Props) {
if (this.props.wallet !== nextProps.wallet) {
this.setAddressState(nextProps);
}
}
@ -42,6 +47,15 @@ class CurrentCustomMessageClass extends PureComponent<ReduxProps, State> {
}
}
private async setAddressState(props: Props) {
if (props.wallet) {
const walletAddress = await props.wallet.getAddressString();
this.setState({ walletAddress });
} else {
this.setState({ walletAddress: '' });
}
}
private getMessage() {
const { currentTo, tokens } = this.props;
const { walletAddress } = this.state;