diff --git a/app/components/Views/Settings/ExperimentalSettings/__snapshots__/index.test.js.snap b/app/components/Views/Settings/ExperimentalSettings/__snapshots__/index.test.js.snap index 622500d8f7d..4c64550cec9 100644 --- a/app/components/Views/Settings/ExperimentalSettings/__snapshots__/index.test.js.snap +++ b/app/components/Views/Settings/ExperimentalSettings/__snapshots__/index.test.js.snap @@ -14,111 +14,11 @@ exports[`ExperimentalSettings should render correctly 1`] = ` - - - Payment Channels - - - This option will run the Connext Payment Channels client in the app - - - - - - View your payment channels wallet - - - VIEW WALLET - - - + getNavigationOptionsTitle(strings('app_settings.experimental_title'), navigation); + componentDidMount = async () => { + const paymentChannelHasBalance = await PaymentChannelsClient.addressHasTransactions(this.props.selectedAddress); + this.setState({ paymentChannelHasBalance }); + }; + goToWalletConnectSessions = () => { this.props.navigation.navigate('WalletConnectSessionsView'); }; @@ -103,11 +111,25 @@ class ExperimentalSettings extends PureComponent { render = () => { const { paymentChannelsEnabled } = this.props; + const { paymentChannelHasBalance } = this.state; return ( - - + + + {strings('experimental_settings.wallet_connect_dapps')} + {strings('experimental_settings.wallet_connect_dapps_desc')} + + {strings('experimental_settings.wallet_connect_dapps_cta')} + + + + {paymentChannelHasBalance && ( + {strings('experimental_settings.payment_channels')} {strings('experimental_settings.enable_payment_channels_desc')} @@ -125,29 +147,18 @@ class ExperimentalSettings extends PureComponent { containerStyle={styles.clearHistoryConfirm} disabled={!paymentChannelsEnabled} > - {strings('experimental_settings.payment_channels_cta').toUpperCase()} + {strings('experimental_settings.payment_channels_cta')} - - - {strings('experimental_settings.wallet_connect_dapps')} - {strings('experimental_settings.wallet_connect_dapps_desc')} - - {strings('experimental_settings.wallet_connect_dapps_cta').toUpperCase()} - - - + )} ); }; } const mapStateToProps = state => ({ - paymentChannelsEnabled: state.settings.paymentChannelsEnabled + paymentChannelsEnabled: state.settings.paymentChannelsEnabled, + selectedAddress: state.engine.backgroundState.PreferencesController.selectedAddress }); const mapDispatchToProps = dispatch => ({ diff --git a/app/components/Views/Settings/__snapshots__/index.test.js.snap b/app/components/Views/Settings/__snapshots__/index.test.js.snap index 4e4a8a3dd5a..36949d4b78e 100644 --- a/app/components/Views/Settings/__snapshots__/index.test.js.snap +++ b/app/components/Views/Settings/__snapshots__/index.test.js.snap @@ -37,7 +37,7 @@ exports[`Settings should render correctly 1`] = ` title="Networks" /> diff --git a/app/core/PaymentChannelsClient.js b/app/core/PaymentChannelsClient.js index 2321add83bc..4de38d1c14c 100644 --- a/app/core/PaymentChannelsClient.js +++ b/app/core/PaymentChannelsClient.js @@ -193,6 +193,16 @@ class PaymentChannelsClient { return ret.toFixed(2).toString(); }; + async startConnext() { + const { connext } = this.state; + try { + await connext.start(); + } catch (e) { + this.logCurrentState('PC::start'); + Logger.error(e, 'PC::start'); + } + } + async pollConnextState() { Logger.log('PC::createClient success'); const { connext } = this.state; @@ -453,6 +463,7 @@ class PaymentChannelsClient { } logCurrentState = prefix => { + if (!__DEV__) return; Logger.log(`${prefix}:error - channelState:`, this.state.channelState); Logger.log(`${prefix}:error - connextState:`, this.state.connextState); Logger.log(`${prefix}:error - runtime:`, this.state.runtime); @@ -556,6 +567,26 @@ const instance = { * Returns the current exchange rate for SAI / ETH */ getExchangeRate: () => (client && client.state && client.state.exchangeRate) || 0, + /** + * Returns whether the address has transactions in channel + */ + addressHasTransactions: async address => { + if (client) return true; + let hasBalance; + const { provider } = Engine.context.NetworkController.state; + if (SUPPORTED_NETWORKS.indexOf(provider.type) === -1) return false; + const tempClient = new PaymentChannelsClient(address); + try { + await tempClient.setConnext(provider); + await tempClient.startConnext(); + const paymentHistory = await tempClient.state.connext.getPaymentHistory(); + hasBalance = paymentHistory.length > 0; + } catch (e) { + hasBalance = false; + } + tempClient.stop(); + return hasBalance; + }, /** * Minimum deposit amount in ETH */ diff --git a/locales/en.json b/locales/en.json index 836290f4648..f2c8f9d5d60 100644 --- a/locales/en.json +++ b/locales/en.json @@ -380,7 +380,7 @@ "cancel_remove_network": "Cancel", "info_title": "About MetaMask", "experimental_title": "Experimental", - "experimental_desc": "Payment Channels, WalletConnect & more...", + "experimental_desc": "WalletConnect & more...", "legal_title": "Legal", "conversion_title": "Currency conversion", "conversion_desc": "Display fiat values in using a specific currency throughout the application.", diff --git a/locales/es.json b/locales/es.json index 8888f971609..e15c199b232 100644 --- a/locales/es.json +++ b/locales/es.json @@ -353,7 +353,7 @@ "cancel_remove_network": "Cancelar", "info_title": "Acerca de MetaMask", "experimental_title": "Experimental", - "experimental_desc": "Canales de Pago, WalletConnect & más...", + "experimental_desc": "WalletConnect & más...", "legal_title": "Legal", "conversion_title": "Conversión de moneda", "conversion_desc": "Mostrar valores en fiat usando una moneda específica en toda la aplicación.",