Support Safello redirect URLs

When the user buys bitcoin through Safello, they will be redirected to
the Yoti app to verify their identity.

Previously, when the process was done, they
would be redirected to a browser window to continue their purchase, but
since bluewallet has a `bluewallet://` redirect URI associated to its
app ID, we can redirect them back to the app with a
`safello-state-token` query parameter appended to the URI instead.

Bluewallet then simply needs to check if that query parameter is
present, and if so, open a new WebView with the same Safello URL +
`stateToken=xxx` in order to resume the user's session. This way, the
whole buying process can take place inside Bluewallet's app, which
is a clear improvement in terms of user experience.
This commit is contained in:
Tristan Edwards 2019-05-09 12:17:01 +02:00
parent f44f86828e
commit 298aba26f4
2 changed files with 44 additions and 1 deletions

21
App.js
View File

@ -95,6 +95,12 @@ export default class App extends React.Component {
return isValidLightningInvoice;
}
isSafelloRedirect(event) {
let urlObject = url.parse(event.url, true) // eslint-disable-line
return !!urlObject.query["safello-state-token"]
}
handleOpenURL = event => {
if (event.url === null) {
return;
@ -122,6 +128,21 @@ export default class App extends React.Component {
},
}),
);
} else if (this.isSafelloRedirect(event)) {
let urlObject = url.parse(event.url, true) // eslint-disable-line
const safelloStateToken = urlObject.query["safello-state-token"]
this.navigator &&
this.navigator.dispatch(
NavigationActions.navigate({
routeName: "BuyBitcoin",
params: {
uri: event.url,
safelloStateToken,
},
}),
)
} else {
let urlObject = url.parse(event.url, true); // eslint-disable-line
console.log('parsed', urlObject);

View File

@ -63,7 +63,29 @@ export default class BuyBitcoin extends Component {
return <BlueLoading />;
}
return <WebView source={{ uri: 'https://bluewallet.io/buy-bitcoin-redirect.html?address=' + this.state.address }} />;
const { safelloStateToken } = this.props.navigation.state.params
if (safelloStateToken) {
return (
<WebView
source={{
uri:
"https://app.safello.com/sdk/quickbuy.html?appId=1234-5678&stateToken=" +
safelloStateToken,
}}
/>
)
}
return (
<WebView
source={{
uri:
"https://bluewallet.io/buy-bitcoin-redirect.html?address=" +
this.state.address,
}}
/>
)
}
}