2018-10-28 11:13:28 +01:00
|
|
|
import React, { Component } from 'react';
|
2019-04-21 20:50:28 +02:00
|
|
|
import { BlueNavigationStyle, BlueLoading } from '../../BlueComponents';
|
2018-10-28 11:13:28 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-04-21 20:50:28 +02:00
|
|
|
import { WebView } from 'react-native-webview';
|
2018-10-28 11:13:28 +01:00
|
|
|
/** @type {AppStorage} */
|
|
|
|
let BlueApp = require('../../BlueApp');
|
|
|
|
let loc = require('../../loc');
|
|
|
|
|
|
|
|
export default class BuyBitcoin extends Component {
|
2018-12-11 23:52:46 +01:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
|
|
|
title: loc.buyBitcoin.header,
|
|
|
|
headerLeft: null,
|
|
|
|
});
|
2018-10-28 11:13:28 +01:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
let address = props.navigation.state.params.address;
|
|
|
|
let secret = props.navigation.state.params.secret;
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isLoading: true,
|
|
|
|
address: address,
|
|
|
|
secret: secret,
|
|
|
|
addressText: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
console.log('buyBitcoin/details - componentDidMount');
|
|
|
|
|
|
|
|
/** @type {AbstractWallet} */
|
|
|
|
let wallet;
|
|
|
|
let address = this.state.address;
|
|
|
|
for (let w of BlueApp.getWallets()) {
|
|
|
|
if ((address && w.getAddress() === this.state.address) || w.getSecret() === this.state.secret) {
|
|
|
|
// found our wallet
|
|
|
|
wallet = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wallet && wallet.getAddressAsync) {
|
|
|
|
setTimeout(async () => {
|
|
|
|
address = await wallet.getAddressAsync();
|
|
|
|
BlueApp.saveToDisk(); // caching whatever getAddressAsync() generated internally
|
|
|
|
this.setState({
|
|
|
|
address: address,
|
|
|
|
addressText: address,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
address,
|
|
|
|
addressText: address,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.state.isLoading) {
|
|
|
|
return <BlueLoading />;
|
|
|
|
}
|
|
|
|
|
2019-05-12 22:50:08 +02:00
|
|
|
const { safelloStateToken } = this.props.navigation.state.params;
|
2019-05-09 12:17:01 +02:00
|
|
|
|
2019-05-12 22:50:08 +02:00
|
|
|
let uri = 'https://bluewallet.io/buy-bitcoin-redirect.html?address=' + this.state.address;
|
2019-05-10 13:52:08 +02:00
|
|
|
|
|
|
|
if (safelloStateToken) {
|
2019-05-12 22:50:08 +02:00
|
|
|
uri += '&safelloStateToken=' + safelloStateToken;
|
2019-05-09 12:17:01 +02:00
|
|
|
}
|
|
|
|
|
2019-05-12 22:50:08 +02:00
|
|
|
return (
|
2019-05-09 12:17:01 +02:00
|
|
|
<WebView
|
|
|
|
source={{
|
2019-05-10 13:52:08 +02:00
|
|
|
uri,
|
2019-05-09 12:17:01 +02:00
|
|
|
}}
|
|
|
|
/>
|
2019-05-12 22:50:08 +02:00
|
|
|
);
|
2018-10-28 11:13:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BuyBitcoin.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 16:28:43 +01:00
|
|
|
goBack: PropTypes.func,
|
2018-10-28 11:13:28 +01:00
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
address: PropTypes.string,
|
|
|
|
secret: PropTypes.string,
|
2019-05-09 14:06:44 +02:00
|
|
|
safelloStateToken: PropTypes.string,
|
2018-10-28 11:13:28 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|