|
|
@ -29,7 +29,7 @@ import Modal from 'react-native-modal'; |
|
|
|
import NetworkTransactionFees, { NetworkTransactionFee } from '../../models/networkTransactionFees'; |
|
|
|
import BitcoinBIP70TransactionDecode from '../../bip70/bip70'; |
|
|
|
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits'; |
|
|
|
import { HDLegacyP2PKHWallet, HDSegwitP2SHWallet, LightningCustodianWallet } from '../../class'; |
|
|
|
import { HDLegacyP2PKHWallet, HDSegwitBech32Wallet, HDSegwitP2SHWallet, LightningCustodianWallet } from '../../class'; |
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; |
|
|
|
const bip21 = require('bip21'); |
|
|
|
let BigNumber = require('bignumber.js'); |
|
|
@ -50,7 +50,6 @@ export default class SendDetails extends Component { |
|
|
|
|
|
|
|
constructor(props) { |
|
|
|
super(props); |
|
|
|
console.log('props.navigation.state.params=', props.navigation.state.params); |
|
|
|
let address; |
|
|
|
let memo; |
|
|
|
if (props.navigation.state.params) address = props.navigation.state.params.address; |
|
|
@ -223,6 +222,7 @@ export default class SendDetails extends Component { |
|
|
|
let availableBalance; |
|
|
|
try { |
|
|
|
availableBalance = new BigNumber(balance); |
|
|
|
availableBalance = availableBalance.div(100000000); // sat2btc
|
|
|
|
availableBalance = availableBalance.minus(amount); |
|
|
|
availableBalance = availableBalance.minus(fee); |
|
|
|
availableBalance = availableBalance.toString(10); |
|
|
@ -307,8 +307,6 @@ export default class SendDetails extends Component { |
|
|
|
let error = false; |
|
|
|
let requestedSatPerByte = this.state.fee.toString().replace(/\D/g, ''); |
|
|
|
|
|
|
|
console.log({ requestedSatPerByte }); |
|
|
|
|
|
|
|
if (!this.state.amount || this.state.amount === '0' || parseFloat(this.state.amount) === 0) { |
|
|
|
error = loc.send.details.amount_field_is_not_valid; |
|
|
|
console.log('validation error'); |
|
|
@ -351,6 +349,20 @@ export default class SendDetails extends Component { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.state.fromWallet.type === HDSegwitBech32Wallet.type) { |
|
|
|
try { |
|
|
|
await this.createHDBech32Transaction(); |
|
|
|
} catch (Err) { |
|
|
|
this.setState({ isLoading: false }, () => { |
|
|
|
alert(Err.message); |
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false }); |
|
|
|
}); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// legacy send below
|
|
|
|
|
|
|
|
this.setState({ isLoading: true }, async () => { |
|
|
|
let utxo; |
|
|
|
let actualSatoshiPerByte; |
|
|
@ -436,6 +448,40 @@ export default class SendDetails extends Component { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
async createHDBech32Transaction() { |
|
|
|
/** @type {HDSegwitBech32Wallet} */ |
|
|
|
const wallet = this.state.fromWallet; |
|
|
|
await wallet.fetchUtxo(); |
|
|
|
const changeAddress = await wallet.getChangeAddressAsync(); |
|
|
|
let satoshis = new BigNumber(this.state.amount).multipliedBy(100000000).toNumber(); |
|
|
|
const requestedSatPerByte = +this.state.fee.toString().replace(/\D/g, ''); |
|
|
|
console.log({ satoshis, requestedSatPerByte, utxo: wallet.getUtxo() }); |
|
|
|
|
|
|
|
let targets = []; |
|
|
|
targets.push({ address: this.state.address, value: satoshis }); |
|
|
|
|
|
|
|
let { tx, fee } = wallet.createTransaction(wallet.getUtxo(), targets, requestedSatPerByte, changeAddress); |
|
|
|
|
|
|
|
BlueApp.tx_metadata = BlueApp.tx_metadata || {}; |
|
|
|
BlueApp.tx_metadata[tx.getId()] = { |
|
|
|
txhex: tx.toHex(), |
|
|
|
memo: this.state.memo, |
|
|
|
}; |
|
|
|
await BlueApp.saveToDisk(); |
|
|
|
|
|
|
|
this.setState({ isLoading: false }, () => |
|
|
|
this.props.navigation.navigate('Confirm', { |
|
|
|
amount: this.state.amount, |
|
|
|
fee: new BigNumber(fee).dividedBy(100000000).toNumber(), |
|
|
|
address: this.state.address, |
|
|
|
memo: this.state.memo, |
|
|
|
fromWallet: wallet, |
|
|
|
tx: tx.toHex(), |
|
|
|
satoshiPerByte: requestedSatPerByte, |
|
|
|
}), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
onWalletSelect = wallet => { |
|
|
|
this.setState({ fromAddress: wallet.getAddress(), fromSecret: wallet.getSecret(), fromWallet: wallet }, () => { |
|
|
|
this.props.navigation.pop(); |
|
|
|