From 05f50994fa2db7320a3d2d8b4bb098c0859742ac Mon Sep 17 00:00:00 2001 From: Amir Ekbatanifard Date: Sat, 8 Jun 2024 10:14:03 +0330 Subject: [PATCH] Fix RemoveAll issue --- .../pool/commonTasks/removeAll/Review.tsx | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/packages/extension-polkagate/src/fullscreen/stake/pool/commonTasks/removeAll/Review.tsx b/packages/extension-polkagate/src/fullscreen/stake/pool/commonTasks/removeAll/Review.tsx index 250f1d395..b2bf22f9c 100644 --- a/packages/extension-polkagate/src/fullscreen/stake/pool/commonTasks/removeAll/Review.tsx +++ b/packages/extension-polkagate/src/fullscreen/stake/pool/commonTasks/removeAll/Review.tsx @@ -43,8 +43,8 @@ export default function Review ({ address, api, chain, mode, pool, poolMembers, const [proxyItems, setProxyItems] = useState(); const [isPasswordError, setIsPasswordError] = useState(false); const [selectedProxy, setSelectedProxy] = useState(); - const [membersToUnboundAll, setMembersToUnboundAll] = useState(); - const [membersToRemoveAll, setMembersToRemoveAll] = useState(); + const [membersToUnbond, setMembersToUnbond] = useState(); + const [membersToRemove, setMembersToRemove] = useState(); const [inputs, setInputs] = useState(); const estimatedFee = useEstimatedFee(address, inputs?.call, inputs?.params); @@ -79,16 +79,16 @@ export default function Review ({ address, api, chain, mode, pool, poolMembers, const membersToUnbond = nonZeroPointMembers.filter((m) => m.accountId !== poolDepositorAddr); - setMembersToUnboundAll(membersToUnbond); + setMembersToUnbond(membersToUnbond); } else { const membersToRemove = poolMembers.filter((m) => m.accountId !== poolDepositorAddr); - setMembersToRemoveAll(membersToRemove); + setMembersToRemove(membersToRemove); } }, [poolMembers, mode, poolDepositorAddr]); useEffect(() => { - if ((!membersToUnboundAll && !membersToRemoveAll) || !formatted || !api) { + if ((!membersToUnbond && !membersToRemove) || !formatted || !api) { return; } @@ -97,39 +97,47 @@ export default function Review ({ address, api, chain, mode, pool, poolMembers, if (mode === 'UnbondAll') { const unbonded = api.tx.nominationPools.unbond; - const params = membersToUnboundAll?.map((m) => [m.accountId, m.points]); + const members = membersToUnbond?.map((m) => [m.accountId, m.points]); - if (!params || params.length === 0) { + if (!members || members.length === 0) { return; } - const call = params.length > 1 + const call = members.length > 1 ? batchAll : unbonded; + const params = members.length > 1 + ? [members.map((member) => unbonded(...member))] + : members[0]; + setInputs({ call, - params: params.length > 1 ? params : params[0] + params }); } else if (mode === 'RemoveAll') { const redeem = api.tx.nominationPools.withdrawUnbonded; - const params = membersToRemoveAll?.map((m) => [m.accountId, m.points]); + const members = membersToRemove?.map((m) => [m.accountId, m.points]); - if (!params || params.length === 0) { + if (!members || members.length === 0) { return; } - const call = params.length > 1 + const call = members.length > 1 ? batchAll : redeem; + const params = members.length > 1 + ? [members.map((member) => redeem(...member))] + : members[0]; + setInputs({ call, - params: params.length > 1 ? params : params[0] + params }); } - }, [api, formatted, membersToRemoveAll, membersToUnboundAll, mode, setInputs]); + }, [api, formatted, membersToRemove, membersToUnbond, mode, setInputs]); const closeProxy = useCallback(() => setStep(STEPS.REVIEW), [setStep]); @@ -150,14 +158,14 @@ export default function Review ({ address, api, chain, mode, pool, poolMembers, {mode === 'UnbondAll' ? ( - {t('Unstaking all members of the pool except yourself forcefully.')} + {t('Unstaking all members of the pool except yourself forcefully.')} ) : (<> - {t('Removing all members from the pool')} + {t('Removing all members from the pool')} - {t('When you confirm, you will be able to unstake your tokens')} + {t('When you confirm, you will be able to unstake your tokens')} ) }