From e3c20a2901e1ce66699cf08b60daf6c22e7c5cd4 Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Wed, 21 Apr 2021 18:37:13 -0700 Subject: [PATCH] btc: improved transitions and error handling for startup modals --- .../src/js/components/lib/providerModal.js | 99 +++++++++++++------ .../src/js/components/lib/walletModal.js | 67 ++++++++----- 2 files changed, 112 insertions(+), 54 deletions(-) diff --git a/pkg/btc-wallet/src/js/components/lib/providerModal.js b/pkg/btc-wallet/src/js/components/lib/providerModal.js index 51a6f17d1d..3006017cbe 100644 --- a/pkg/btc-wallet/src/js/components/lib/providerModal.js +++ b/pkg/btc-wallet/src/js/components/lib/providerModal.js @@ -7,6 +7,7 @@ import { Icon, Row, Input, + LoadingSpinner, } from '@tlon/indigo-react'; import { isValidPatp } from 'urbit-ob'; @@ -16,8 +17,12 @@ export default class ProviderModal extends Component { super(props); this.state = { + potentialProvider: null, + checkingProvider: false, + providerFailed: false, ready: false, provider: null, + connecting: false, } this.checkProvider = this.checkProvider.bind(this); @@ -28,20 +33,27 @@ export default class ProviderModal extends Component { // TODO: loading states let provider = e.target.value; let ready = false; + let checkingProvider = false; + let potentialProvider = this.state.potentialProvider; if (isValidPatp(provider)) { let command = { "check-provider": provider } + potentialProvider = provider; + checkingProvider = true; this.props.api.btcWalletCommand(command); + setTimeout(() => { + this.setState({providerFailed: true, checkingProvider: false}); + }, 5000); } - this.setState({provider, ready}); + this.setState({provider, ready, checkingProvider, potentialProvider}); } componentDidUpdate(prevProps, prevState){ if (!this.state.ready){ if (this.props.providerPerms[this.state.provider]) { - this.setState({ready: true}); + this.setState({ready: true, checkingProvider: false, providerFailed: false}); } } } @@ -52,16 +64,35 @@ export default class ProviderModal extends Component { "set-provider": this.state.provider } this.props.api.btcWalletCommand(command); + this.setState({connecting: true}); } } render() { - let workingNode = (!this.state.ready) ? null : - - - {this.state.provider} is a working provider node - - + + let workingNode = null; + let workingColor = null; + let workingBg = null; + if (this.state.ready) { + workingColor = "green"; + workingBg = "veryLightGreen" + workingNode = + + + {this.state.provider} is a working provider node + + + } else if (this.state.providerFailed) { + workingColor = "red"; + workingBg = "veryLightRed" + workingNode = + + + {this.state.potentialProvider} is not a working provider node + + + } + return ( - + + + {(this.state.checkingProvider) ? : null} + {workingNode} -