Skip to content

Commit

Permalink
Prevent changing for the same multisig (ChainSafe#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Jul 6, 2023
1 parent 23bd8f5 commit 72b2115
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions packages/ui/src/components/modals/ChangeMultisig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
).length > 0,
[ownAddressList, newSignatories, selectedMultisig?.signatories]
)
const newMultisigAddress = useMemo(() => {
if (!newThreshold || !chainInfo) return

const multisigPubKey = createKeyMulti(newSignatories, newThreshold)
let newMultiAddress: string | undefined
try {
newMultiAddress = encodeAddress(multisigPubKey, chainInfo.ss58Format)
} catch (e) {
console.error(`Error encoding the address ${multisigPubKey}`, e)
return
}

return newMultiAddress
}, [chainInfo, newSignatories, newThreshold])

const canGoNext = useMemo(
() => newMultisigAddress !== selectedMultisig?.address,
[newMultisigAddress, selectedMultisig]
)
const isCallStep = useMemo(
() => currentStep === 'call1' || currentStep === 'call2',
[currentStep]
Expand Down Expand Up @@ -95,20 +114,15 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
return
}

if (!newMultisigAddress) {
return
}

const otherOldSignatories = sortAddresses(
selectedMultisig.signatories.filter((sig) => sig !== selectedAccount.address)
)

const multisigPubKey = createKeyMulti(newSignatories, newThreshold)
let newMultiAddress: string | undefined
try {
newMultiAddress = encodeAddress(multisigPubKey, chainInfo.ss58Format)
} catch (e) {
console.error(`Error encoding the address ${multisigPubKey}`, e)
return
}

const addProxyTx = api.tx.proxy.addProxy(newMultiAddress, 'Any', 0)
const addProxyTx = api.tx.proxy.addProxy(newMultisigAddress, 'Any', 0)
const proxyTx = api.tx.proxy.proxy(selectedMultiProxy?.proxy, null, addProxyTx)
// call with the old multisig
return api.tx.multisig.asMulti(oldThreshold, otherOldSignatories, null, proxyTx, {
Expand All @@ -119,11 +133,11 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
api,
chainInfo,
isApiReady,
newSignatories,
newMultisigAddress,
newThreshold,
oldThreshold,
selectedAccount,
selectedMultiProxy?.proxy,
selectedMultiProxy,
selectedMultisig
])

Expand Down Expand Up @@ -468,6 +482,7 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
<Button
variant="primary"
disabled={
!canGoNext ||
!!errorMessage ||
!hasProxyEnoughFunds ||
(currentStep === 'summary' && !hasSignerEnoughFunds)
Expand Down

0 comments on commit 72b2115

Please sign in to comment.