Browse Source

FIX: Deeplink would fail sometimes on cold start (#382)

icloud
Marcos Rodriguez Vélez 6 years ago
committed by Igor Korsakov
parent
commit
c1a03cb1cb
  1. 18
      App.js

18
App.js

@ -25,12 +25,14 @@ export default class App extends React.Component {
componentDidMount() {
Linking.getInitialURL()
.then(url => this.handleOpenURL({ url }))
.then(url => {
if (this.hasSchema(url)) {
this.handleOpenURL({ url });
}
})
.catch(console.error);
Linking.addEventListener('url', this.handleOpenURL);
AppState.addEventListener('change', this._handleAppStateChange);
this._handleAppStateChange(this.state.appState, true);
}
componentWillUnmount() {
@ -38,9 +40,9 @@ export default class App extends React.Component {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = async (nextAppState, force = false) => {
_handleAppStateChange = async nextAppState => {
if (BlueApp.getWallets().length > 0) {
if ((this.state.appState.match(/inactive|background/) && nextAppState === 'active') || force) {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
const clipboard = await Clipboard.getString();
if (this.state.clipboardContent !== clipboard && (this.isBitcoinAddress(clipboard) || this.isLightningInvoice(clipboard))) {
this.setState({ isClipboardContentModalVisible: true });
@ -51,6 +53,12 @@ export default class App extends React.Component {
}
};
hasSchema(schemaString) {
if (typeof schemaString !== 'string' || schemaString.length <= 0) return false;
const lowercaseString = schemaString.trim().toLowerCase();
return lowercaseString.startsWith('bitcoin:') || lowercaseString.startsWith('lightning:');
}
isBitcoinAddress(address) {
let isValidBitcoinAddress = false;
try {

Loading…
Cancel
Save