added beneficiary remove method

This commit is contained in:
Sadaqat Ali 2022-04-17 14:56:59 +05:00
parent 97d55c57a7
commit 98436fe1f2
2 changed files with 20 additions and 1 deletions

View File

@ -22,6 +22,7 @@ interface BeneficiarySelectionContentProps {
powerDown?: boolean;
powerDownBeneficiaries?: Beneficiary[];
handleSaveBeneficiary?: (beneficiaries: Beneficiary[]) => void;
handleRemoveBeneficiary?: (beneficiary: Beneficiary) => void;
}
const BeneficiarySelectionContent = ({
@ -30,6 +31,7 @@ const BeneficiarySelectionContent = ({
powerDown,
powerDownBeneficiaries,
handleSaveBeneficiary,
handleRemoveBeneficiary,
}: BeneficiarySelectionContentProps) => {
const intl = useIntl();
const dispatch = useAppDispatch();
@ -306,8 +308,13 @@ const BeneficiarySelectionContent = ({
const _onRemovePress = () => {
beneficiaries[0].weight = beneficiaries[0].weight + item.weight;
beneficiaries.splice(index, 1);
const removedBeneficiary = beneficiaries.splice(index, 1);
setBeneficiaries([...beneficiaries]);
console.log('removedBeneficiary : ', removedBeneficiary);
if(handleRemoveBeneficiary){
handleRemoveBeneficiary(removedBeneficiary[0]);
return;
}
_saveBeneficiaries(beneficiaries);
};

View File

@ -185,6 +185,17 @@ class PowerDownView extends Component {
);
}
};
const _handleRemoveBeneficiary = (beneficiary) => {
if (beneficiary) {
const beneficiaryAccount = {
username: beneficiary.account,
percent: beneficiary.weight / 100,
autoPowerUp: beneficiary.autoPowerUp,
};
this._removeDestinationAccount(beneficiaryAccount);
}
};
return (
<View style={styles.beneficiaryContainer}>
<BeneficiarySelectionContent
@ -192,6 +203,7 @@ class PowerDownView extends Component {
powerDown={true}
powerDownBeneficiaries={powerDownBeneficiaries}
handleSaveBeneficiary={_handleSaveBeneficiary}
handleRemoveBeneficiary={_handleRemoveBeneficiary}
/>
</View>
);