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; powerDown?: boolean;
powerDownBeneficiaries?: Beneficiary[]; powerDownBeneficiaries?: Beneficiary[];
handleSaveBeneficiary?: (beneficiaries: Beneficiary[]) => void; handleSaveBeneficiary?: (beneficiaries: Beneficiary[]) => void;
handleRemoveBeneficiary?: (beneficiary: Beneficiary) => void;
} }
const BeneficiarySelectionContent = ({ const BeneficiarySelectionContent = ({
@ -30,6 +31,7 @@ const BeneficiarySelectionContent = ({
powerDown, powerDown,
powerDownBeneficiaries, powerDownBeneficiaries,
handleSaveBeneficiary, handleSaveBeneficiary,
handleRemoveBeneficiary,
}: BeneficiarySelectionContentProps) => { }: BeneficiarySelectionContentProps) => {
const intl = useIntl(); const intl = useIntl();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -306,8 +308,13 @@ const BeneficiarySelectionContent = ({
const _onRemovePress = () => { const _onRemovePress = () => {
beneficiaries[0].weight = beneficiaries[0].weight + item.weight; beneficiaries[0].weight = beneficiaries[0].weight + item.weight;
beneficiaries.splice(index, 1); const removedBeneficiary = beneficiaries.splice(index, 1);
setBeneficiaries([...beneficiaries]); setBeneficiaries([...beneficiaries]);
console.log('removedBeneficiary : ', removedBeneficiary);
if(handleRemoveBeneficiary){
handleRemoveBeneficiary(removedBeneficiary[0]);
return;
}
_saveBeneficiaries(beneficiaries); _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 ( return (
<View style={styles.beneficiaryContainer}> <View style={styles.beneficiaryContainer}>
<BeneficiarySelectionContent <BeneficiarySelectionContent
@ -192,6 +203,7 @@ class PowerDownView extends Component {
powerDown={true} powerDown={true}
powerDownBeneficiaries={powerDownBeneficiaries} powerDownBeneficiaries={powerDownBeneficiaries}
handleSaveBeneficiary={_handleSaveBeneficiary} handleSaveBeneficiary={_handleSaveBeneficiary}
handleRemoveBeneficiary={_handleRemoveBeneficiary}
/> />
</View> </View>
); );