mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-04 12:18:10 +01:00
WIP
This commit is contained in:
parent
9d0e135c58
commit
fc772657e4
3 changed files with 28 additions and 53 deletions
|
@ -647,7 +647,7 @@ export default class SendDetails extends Component {
|
||||||
this.props.navigation.navigate('PsbtMultisig', {
|
this.props.navigation.navigate('PsbtMultisig', {
|
||||||
memo: this.state.memo,
|
memo: this.state.memo,
|
||||||
psbtBase64: psbt.toBase64(),
|
psbtBase64: psbt.toBase64(),
|
||||||
walletId: wallet.getID(),
|
walletID: wallet.getID(),
|
||||||
});
|
});
|
||||||
this.setState({ isLoading: false });
|
this.setState({ isLoading: false });
|
||||||
return;
|
return;
|
||||||
|
@ -976,7 +976,7 @@ export default class SendDetails extends Component {
|
||||||
this.props.navigation.navigate('PsbtMultisig', {
|
this.props.navigation.navigate('PsbtMultisig', {
|
||||||
memo: this.state.memo,
|
memo: this.state.memo,
|
||||||
psbtBase64: psbt.toBase64(),
|
psbtBase64: psbt.toBase64(),
|
||||||
walletId: fromWallet.getID(),
|
walletID: fromWallet.getID(),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(loc.send.problem_with_psbt + ': ' + error.message);
|
alert(loc.send.problem_with_psbt + ': ' + error.message);
|
||||||
|
|
|
@ -17,17 +17,14 @@ const shortenAddress = addr => {
|
||||||
|
|
||||||
const PsbtMultisig = () => {
|
const PsbtMultisig = () => {
|
||||||
const { wallets } = useContext(BlueStorageContext);
|
const { wallets } = useContext(BlueStorageContext);
|
||||||
const navigation = useNavigation();
|
const { navigate, setParams } = useNavigation();
|
||||||
const route = useRoute();
|
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const [flatListHeight, setFlatListHeight] = useState(0);
|
const [flatListHeight, setFlatListHeight] = useState(0);
|
||||||
|
const { walletID, psbtBase64, memo, receivedPSBTBase64 } = useRoute().params;
|
||||||
const walletID = route.params.walletId;
|
/** @type MultisigHDWallet */
|
||||||
const psbtBase64 = route.params.psbtBase64;
|
const wallet = wallets.find(w => w.getID() === walletID);
|
||||||
const memo = route.params.memo;
|
|
||||||
const receivedPSBTBase64 = route.params.receivedPSBTBase64;
|
|
||||||
|
|
||||||
const [psbt, setPsbt] = useState(bitcoin.Psbt.fromBase64(psbtBase64));
|
const [psbt, setPsbt] = useState(bitcoin.Psbt.fromBase64(psbtBase64));
|
||||||
|
const data = new Array(wallet.getM());
|
||||||
const stylesHook = StyleSheet.create({
|
const stylesHook = StyleSheet.create({
|
||||||
root: {
|
root: {
|
||||||
backgroundColor: colors.elevated,
|
backgroundColor: colors.elevated,
|
||||||
|
@ -69,8 +66,7 @@ const PsbtMultisig = () => {
|
||||||
color: colors.msSuccessBG,
|
color: colors.msSuccessBG,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
/** @type MultisigHDWallet */
|
|
||||||
const wallet = wallets.find(w => w.getID() === walletID);
|
|
||||||
let destination = [];
|
let destination = [];
|
||||||
let totalSat = 0;
|
let totalSat = 0;
|
||||||
const targets = [];
|
const targets = [];
|
||||||
|
@ -85,25 +81,21 @@ const PsbtMultisig = () => {
|
||||||
const totalBtc = new BigNumber(totalSat).dividedBy(100000000).toNumber();
|
const totalBtc = new BigNumber(totalSat).dividedBy(100000000).toNumber();
|
||||||
const totalFiat = currency.satoshiToLocalCurrency(totalSat);
|
const totalFiat = currency.satoshiToLocalCurrency(totalSat);
|
||||||
|
|
||||||
const howManySignaturesWeHave = () => {
|
|
||||||
return wallet.calculateHowManySignaturesWeHaveFromPsbt(psbt);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getFee = () => {
|
const getFee = () => {
|
||||||
return wallet.calculateFeeFromPsbt(psbt);
|
return wallet.calculateFeeFromPsbt(psbt);
|
||||||
};
|
};
|
||||||
|
|
||||||
const _renderItem = el => {
|
const _renderItem = el => {
|
||||||
if (el.index >= howManySignaturesWeHave()) return _renderItemUnsigned(el);
|
if (el.index >= howManySignaturesWeHave) return _renderItemUnsigned(el);
|
||||||
else return _renderItemSigned(el);
|
else return _renderItemSigned(el);
|
||||||
};
|
};
|
||||||
|
|
||||||
const navigateToPSBTMultisigQRCode = () => {
|
const navigateToPSBTMultisigQRCode = () => {
|
||||||
navigation.navigate('PsbtMultisigQRCode', { walletID, psbtBase64 });
|
navigate('PsbtMultisigQRCode', { walletID, psbtBase64, isShowOpenScanner: isConfirmEnabled() });
|
||||||
};
|
};
|
||||||
|
|
||||||
const _renderItemUnsigned = el => {
|
const _renderItemUnsigned = el => {
|
||||||
const renderProvideSignature = el.index === howManySignaturesWeHave();
|
const renderProvideSignature = el.index === howManySignaturesWeHave;
|
||||||
return (
|
return (
|
||||||
<View testID="ItemUnsigned">
|
<View testID="ItemUnsigned">
|
||||||
<View style={styles.itemUnsignedWrapper}>
|
<View style={styles.itemUnsignedWrapper}>
|
||||||
|
@ -150,9 +142,16 @@ const PsbtMultisig = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
useEffect(() => _combinePSBT, [receivedPSBTBase64]);
|
useEffect(() => {
|
||||||
|
if (receivedPSBTBase64) {
|
||||||
|
_combinePSBT();
|
||||||
|
setParams({ receivedPSBTBase64: undefined });
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [receivedPSBTBase64]);
|
||||||
|
|
||||||
const _combinePSBT = () => {
|
const _combinePSBT = () => {
|
||||||
|
console.warn(receivedPSBTBase64);
|
||||||
const receivedPSBT = bitcoin.Psbt.fromBase64(receivedPSBTBase64);
|
const receivedPSBT = bitcoin.Psbt.fromBase64(receivedPSBTBase64);
|
||||||
try {
|
try {
|
||||||
const newPsbt = psbt.combine(receivedPSBT);
|
const newPsbt = psbt.combine(receivedPSBT);
|
||||||
|
@ -170,7 +169,7 @@ const PsbtMultisig = () => {
|
||||||
try {
|
try {
|
||||||
const tx = psbt.extractTransaction().toHex();
|
const tx = psbt.extractTransaction().toHex();
|
||||||
const satoshiPerByte = Math.round(getFee() / (tx.length / 2));
|
const satoshiPerByte = Math.round(getFee() / (tx.length / 2));
|
||||||
navigation.navigate('Confirm', {
|
navigate('Confirm', {
|
||||||
fee: new BigNumber(getFee()).dividedBy(100000000).toNumber(),
|
fee: new BigNumber(getFee()).dividedBy(100000000).toNumber(),
|
||||||
memo: memo,
|
memo: memo,
|
||||||
fromWallet: wallet,
|
fromWallet: wallet,
|
||||||
|
@ -183,8 +182,9 @@ const PsbtMultisig = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const howManySignaturesWeHave = wallet.calculateHowManySignaturesWeHaveFromPsbt(psbt);
|
||||||
const isConfirmEnabled = () => {
|
const isConfirmEnabled = () => {
|
||||||
return howManySignaturesWeHave() >= wallet.getM();
|
return howManySignaturesWeHave >= wallet.getM();
|
||||||
};
|
};
|
||||||
|
|
||||||
const destinationAddress = () => {
|
const destinationAddress = () => {
|
||||||
|
@ -252,7 +252,6 @@ const PsbtMultisig = () => {
|
||||||
setFlatListHeight(e.nativeEvent.layout.height);
|
setFlatListHeight(e.nativeEvent.layout.height);
|
||||||
};
|
};
|
||||||
|
|
||||||
const data = new Array(wallet.getM());
|
|
||||||
return (
|
return (
|
||||||
<SafeBlueArea style={[styles.root, stylesHook.root]}>
|
<SafeBlueArea style={[styles.root, stylesHook.root]}>
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* global alert */
|
/* global alert */
|
||||||
import React, { useContext, useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { ActivityIndicator, Platform, ScrollView, StyleSheet, View } from 'react-native';
|
import { ActivityIndicator, Platform, ScrollView, StyleSheet, View } from 'react-native';
|
||||||
import { BlueButtonLink, BlueNavigationStyle, BlueSpacing20, SafeBlueArea } from '../../BlueComponents';
|
import { BlueNavigationStyle, BlueSpacing20, SafeBlueArea } from '../../BlueComponents';
|
||||||
import { DynamicQRCode } from '../../components/DynamicQRCode';
|
import { DynamicQRCode } from '../../components/DynamicQRCode';
|
||||||
import { SquareButton } from '../../components/SquareButton';
|
import { SquareButton } from '../../components/SquareButton';
|
||||||
import { getSystemName } from 'react-native-device-info';
|
import { getSystemName } from 'react-native-device-info';
|
||||||
|
@ -9,17 +9,15 @@ import loc from '../../loc';
|
||||||
import ImagePicker from 'react-native-image-picker';
|
import ImagePicker from 'react-native-image-picker';
|
||||||
import ScanQRCode from './ScanQRCode';
|
import ScanQRCode from './ScanQRCode';
|
||||||
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
|
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
|
||||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
|
||||||
const bitcoin = require('bitcoinjs-lib');
|
const bitcoin = require('bitcoinjs-lib');
|
||||||
const fs = require('../../blue_modules/fs');
|
const fs = require('../../blue_modules/fs');
|
||||||
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
|
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
|
||||||
const isDesktop = getSystemName() === 'Mac OS X';
|
const isDesktop = getSystemName() === 'Mac OS X';
|
||||||
|
|
||||||
const PsbtMultisigQRCode = () => {
|
const PsbtMultisigQRCode = () => {
|
||||||
const { wallets } = useContext(BlueStorageContext);
|
const { navigate } = useNavigation();
|
||||||
const { navigate, goBack } = useNavigation();
|
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const { walletID, psbtBase64 } = useRoute().params;
|
const { psbtBase64, isShowOpenScanner } = useRoute().params;
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const psbt = bitcoin.Psbt.fromBase64(psbtBase64);
|
const psbt = bitcoin.Psbt.fromBase64(psbtBase64);
|
||||||
|
@ -34,24 +32,8 @@ const PsbtMultisigQRCode = () => {
|
||||||
backgroundColor: colors.buttonDisabledBackgroundColor,
|
backgroundColor: colors.buttonDisabledBackgroundColor,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
/** @type MultisigHDWallet */
|
|
||||||
const wallet = wallets.find(w => w.getID() === walletID);
|
|
||||||
const fileName = `${Date.now()}.psbt`;
|
const fileName = `${Date.now()}.psbt`;
|
||||||
|
|
||||||
const howManySignaturesWeHave = () => {
|
|
||||||
return wallet.calculateHowManySignaturesWeHaveFromPsbt(psbt);
|
|
||||||
};
|
|
||||||
|
|
||||||
const _combinePSBT = receivedPSBTBase64 => {
|
|
||||||
try {
|
|
||||||
const receivedPSBT = bitcoin.Psbt.fromBase64(receivedPSBTBase64);
|
|
||||||
const newPsbt = psbt.combine(receivedPSBT);
|
|
||||||
navigate('PsbtMultisig', { receivedPSBTBase64: newPsbt });
|
|
||||||
} catch (error) {
|
|
||||||
alert(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onBarScanned = ret => {
|
const onBarScanned = ret => {
|
||||||
if (!ret.data) ret = { data: ret };
|
if (!ret.data) ret = { data: ret };
|
||||||
if (ret.data.toUpperCase().startsWith('UR')) {
|
if (ret.data.toUpperCase().startsWith('UR')) {
|
||||||
|
@ -61,7 +43,7 @@ const PsbtMultisigQRCode = () => {
|
||||||
// we dont support it in this flow
|
// we dont support it in this flow
|
||||||
} else {
|
} else {
|
||||||
// psbt base64?
|
// psbt base64?
|
||||||
_combinePSBT(ret.data);
|
navigate('PsbtMultisig', { receivedPSBTBase64: ret.data });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,16 +86,12 @@ const PsbtMultisigQRCode = () => {
|
||||||
setTimeout(() => fs.writeFileAndExport(fileName, psbt.toBase64()).finally(() => setIsLoading(false)), 10);
|
setTimeout(() => fs.writeFileAndExport(fileName, psbt.toBase64()).finally(() => setIsLoading(false)), 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isConfirmEnabled = () => {
|
|
||||||
return howManySignaturesWeHave() >= wallet.getM();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeBlueArea style={[styles.root, stylesHook.root]}>
|
<SafeBlueArea style={[styles.root, stylesHook.root]}>
|
||||||
<ScrollView centerContent contentContainerStyle={styles.scrollViewContent}>
|
<ScrollView centerContent contentContainerStyle={styles.scrollViewContent}>
|
||||||
<View style={[styles.modalContentShort, stylesHook.modalContentShort]}>
|
<View style={[styles.modalContentShort, stylesHook.modalContentShort]}>
|
||||||
<DynamicQRCode value={psbt.toHex()} capacity={666} />
|
<DynamicQRCode value={psbt.toHex()} capacity={666} />
|
||||||
{!isConfirmEnabled() && (
|
{!isShowOpenScanner && (
|
||||||
<>
|
<>
|
||||||
<BlueSpacing20 />
|
<BlueSpacing20 />
|
||||||
<SquareButton
|
<SquareButton
|
||||||
|
@ -130,8 +108,6 @@ const PsbtMultisigQRCode = () => {
|
||||||
) : (
|
) : (
|
||||||
<SquareButton style={[styles.exportButton, stylesHook.exportButton]} onPress={exportPSBT} title={loc.multisig.share} />
|
<SquareButton style={[styles.exportButton, stylesHook.exportButton]} onPress={exportPSBT} title={loc.multisig.share} />
|
||||||
)}
|
)}
|
||||||
<BlueSpacing20 />
|
|
||||||
<BlueButtonLink title={loc._.cancel} onPress={goBack} />
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</SafeBlueArea>
|
</SafeBlueArea>
|
||||||
|
|
Loading…
Add table
Reference in a new issue