FIX: Setting SendDetails info on navigation of PC

This commit is contained in:
Marcos Rodriguez Velez 2024-06-10 22:41:14 -04:00
parent f013366cf6
commit cb50d49f86
No known key found for this signature in database
GPG key ID: 6030B2F48CCE86D7
2 changed files with 37 additions and 20 deletions

View file

@ -158,26 +158,9 @@ const SendDetails = () => {
};
}, []);
// handle selecting a contact (payment code list)
useEffect(() => {
if (routeParams.addRecipientParams) {
setAddresses(addrs => {
if (routeParams.addRecipientParams?.amount) {
addrs[scrollIndex.current].amount = routeParams.addRecipientParams?.amount;
addrs[scrollIndex.current].amountSats = btcToSatoshi(routeParams.addRecipientParams?.amount);
}
if (routeParams.addRecipientParams?.address) {
addrs[scrollIndex.current].address = routeParams.addRecipientParams?.address;
}
return [...addrs];
});
}
setParams({ addRecipientParams: undefined });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [routeParams.addRecipientParams]);
useEffect(() => {
// decode route params
console.warn('routeParams', routeParams);
const currentAddress = addresses[scrollIndex.current];
if (routeParams.uri) {
try {
@ -230,11 +213,43 @@ const SendDetails = () => {
u[scrollIndex.current] = unit;
return [...u];
});
} else if (routeParams.addRecipientParams) {
const index = addresses.length === 0 ? 0 : scrollIndex.current;
const isEmptyArray = addresses.length > 0 || addresses.length < 2;
const addRecipientParams = routeParams.addRecipientParams;
console.warn('isEmptyArray', isEmptyArray);
if (isEmptyArray) {
if (Number(addRecipientParams.amount) > 0) {
setAddresses([
{
address: addRecipientParams.address,
amount: addRecipientParams.amount,
amountSats: btcToSatoshi(addRecipientParams.amount!),
key: String(Math.random()),
} as IPaymentDestinations,
]);
} else {
setAddresses([{ address: addRecipientParams.address, key: String(Math.random()) } as IPaymentDestinations]);
}
} else {
setAddresses(addrs => {
if (routeParams.addRecipientParams?.amount) {
addrs[index].amount = routeParams.addRecipientParams?.amount;
addrs[index].amountSats = btcToSatoshi(routeParams.addRecipientParams?.amount);
}
if (routeParams.addRecipientParams?.address) {
addrs[index].address = routeParams.addRecipientParams?.address;
}
return [...addrs];
});
setParams({ addRecipientParams: undefined });
}
} else {
setAddresses([{ address: '', key: String(Math.random()) } as IPaymentDestinations]); // key is for the FlatList
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [routeParams.uri, routeParams.address]);
}, [routeParams.uri, routeParams.address, routeParams.addRecipientParams]);
useEffect(() => {
// check if we have a suitable wallet

View file

@ -156,7 +156,9 @@ export default function PaymentCodesList() {
screen: 'SendDetails',
params: {
walletID,
address: pc,
addRecipientParams: {
address: pc,
},
},
merge: true,
});