Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-TASK]: Multi devices wallet improvements and bug-fixes #146

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[FIX]: Prevent adding own xpub
  • Loading branch information
Danswar committed Dec 13, 2024
commit bf2c984f09079f3c8fbeec3ba9710d05d1418f25
18 changes: 11 additions & 7 deletions screen/wallets/addMultisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ const WalletsAddMultisig = () => {
<Text style={[styles.textHeader, stylesHook.textHeader]}>{loc.multisig.quorum_header}</Text>
<Text style={[styles.textSubtitle, stylesHook.textSubtitle]}>{loc.multisig.required_keys_out_of_total}</Text>
<View style={styles.rowCenter}>
<View style={styles.column}>
<View style={[styles.column, styles.columnCenter]}>
{/*
<TouchableOpacity accessibilityRole="button" onPress={increaseM} disabled={n === m || m === 7} style={styles.chevron}>
<Icon
name="chevron-up"
Expand All @@ -131,10 +132,13 @@ const WalletsAddMultisig = () => {
color={n === m || m === 7 ? colors.buttonDisabledTextColor : '#007AFF'}
/>
</TouchableOpacity>
*/}
<Text style={[styles.textM, stylesHook.textHeader]}>{m}</Text>
{/*
<TouchableOpacity accessibilityRole="button" onPress={decreaseM} disabled={m === 2} style={styles.chevron}>
<Icon name="chevron-down" size={22} type="octicon" color={m === 2 ? colors.buttonDisabledTextColor : '#007AFF'} />
<Icon name="chevr on-down" size={22} type="octicon" color={m === 2 ? colors.buttonDisabledTextColor : '#007AFF'} />
</TouchableOpacity>
*/}
</View>

<View style={styles.columnOf}>
Expand Down Expand Up @@ -220,9 +224,7 @@ const WalletsAddMultisig = () => {
<Text style={[styles.textdescBold, stylesHook.textdesc]}>{loc.multisig.done_explanation}</Text>
</Text>
</View>
{/** Not removing as we might want to enable this in the future again */}
{/**
* isAdvancedModeEnabledRender && (
{isAdvancedModeEnabledRender && (
<>
<View>
<BlueListItem
Expand All @@ -234,8 +236,7 @@ const WalletsAddMultisig = () => {
</View>
{renderModal()}
</>
)*
*/}
)}
<View style={styles.buttonContainer}>
<BlueButton
buttonTextColor={colors.buttonAlternativeTextColor}
Expand Down Expand Up @@ -280,6 +281,9 @@ const styles = StyleSheet.create({
paddingRight: 20,
paddingLeft: 20,
},
columnCenter: {
justifyContent: 'center',
},
chevron: {
paddingBottom: 10,
paddingTop: 10,
Expand Down
15 changes: 13 additions & 2 deletions screen/wallets/addMultisigStep2.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const WalletsAddMultisigStep2 = () => {
const [cosigners, setCosigners] = useState([]); // array of cosigners user provided. if format [cosigner, fp, path]
const [isLoading, setIsLoading] = useState(false);
const [cosignerXpubURv2, setCosignerXpubURv2] = useState(''); // string displayed in renderCosignersXpubModal()
const [ownXpub, setOwnXpub] = useState('');
const scannedCache = {};
const quorum = useRef(new Array(n));

Expand Down Expand Up @@ -131,6 +132,7 @@ const WalletsAddMultisigStep2 = () => {
const path = getPath();
const xpub = getXpubCacheForMnemonics(cosigner[0]);
const fp = getFpCacheForMnemonics(cosigner[0], cosigner[3]);
setOwnXpub(xpub);
setCosignerXpubURv2(encodeUR(MultisigCosigner.exportToJson(fp, xpub, path))[0]);
}
};
Expand Down Expand Up @@ -302,12 +304,21 @@ const WalletsAddMultisigStep2 = () => {
}
}

// if the cosigner is the same as the one we already have, we don't need to add it again
if(cosigner.getXpub() === ownXpub) {
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
return;
}

// if the cosigner is already in the list, we don't need to add it again
for (const existingCosigner of cosigners) {
if (existingCosigner[0] === cosigner.getXpub()) return;
if (existingCosigner[0] === cosigner.getXpub()) {
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
return;
};
}

// now, validating that cosigner is in correct format:

let correctFormat = false;
switch (format) {
case MultisigHDWallet.FORMAT_P2WSH:
Expand Down