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