Skip to content

Commit

Permalink
add asMulti with 6 args
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Nov 14, 2023
1 parent 39e7763 commit 5120dde
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
17 changes: 11 additions & 6 deletions packages/ui/src/components/modals/ChangeMultisig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Button } from '../library'
import { ModalCloseButton } from '../library/ModalCloseButton'
import { useGetSortAddress } from '../../hooks/useGetSortAddress'
import { useGetMultisigAddress } from '../../contexts/useGetMultisigAddress'
import { getAsMultiTx } from '../../utils/getAsMultiTx'

interface Props {
onClose: () => void
Expand Down Expand Up @@ -121,9 +122,11 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
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, {
refTime: 0,
proofSize: 0
return getAsMultiTx({
api,
threshold: oldThreshold,
otherSignatories: otherOldSignatories,
tx: proxyTx
})
}, [
api,
Expand Down Expand Up @@ -168,9 +171,11 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
)
const removeProxyTx = api.tx.proxy.removeProxy(selectedMultisig?.address, 'Any', 0)
const proxyTx = api.tx.proxy.proxy(selectedMultiProxy?.proxy, null, removeProxyTx)
return api.tx.multisig.asMulti(newThreshold, otherNewSignatories, null, proxyTx, {
refTime: 0,
proofSize: 0
return getAsMultiTx({
api,
otherSignatories: otherNewSignatories,
threshold: newThreshold,
tx: proxyTx
})
}, [
api,
Expand Down
17 changes: 11 additions & 6 deletions packages/ui/src/components/modals/ProposalSigning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ModalCloseButton } from '../library/ModalCloseButton'
import { useGetSortAddress } from '../../hooks/useGetSortAddress'
import { useCheckBalance } from '../../hooks/useCheckBalance'
import BN from 'bn.js'
import { getAsMultiTx } from '../../utils/getAsMultiTx'

export interface SigningModalProps {
onClose: () => void
Expand Down Expand Up @@ -177,6 +178,9 @@ const ProposalSigning = ({
})

const shouldSubmit = amountOfSigner >= threshold - 1
console.log(amountOfSigner, threshold)
console.log(shouldSubmit)
console.log('callInfo?.call && callInfo?.weight', callInfo?.call, callInfo?.weight)

setIsSubmitting(true)
let tx: SubmittableExtrinsic<'promise'>
Expand All @@ -192,13 +196,14 @@ const ProposalSigning = ({

// If we can submit the proposal and have the call data
} else if (shouldSubmit && callInfo?.call && callInfo?.weight) {
tx = api.tx.multisig.asMulti(
tx = getAsMultiTx({
api,
threshold,
otherSigners,
proposalData.info.when,
proposalData.callData || addedCallData,
callInfo.weight
)
otherSignatories: otherSigners,
weight: callInfo.weight,
when: proposalData.info.when,
tx: proposalData.callData || addedCallData
})

// if we can't submit yet (more signatures required), all we need is the call hash
} else if (!shouldSubmit && proposalData.hash) {
Expand Down
6 changes: 2 additions & 4 deletions packages/ui/src/hooks/useGetMultisigTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MultiProxy } from '../contexts/MultiProxyContext'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import { ISubmittableResult } from '@polkadot/types/types'
import { useGetSortAddress } from './useGetSortAddress'
import { getAsMultiTx } from '../utils/getAsMultiTx'

interface Params {
selectedMultisig?: MultiProxy['multisigs'][0]
Expand Down Expand Up @@ -62,10 +63,7 @@ export const useGetMultisigTx = ({
tx = extrinsicToCall
}

return api.tx.multisig.asMulti(threshold, otherSigners, null, tx, {
refTime: 0,
proofSize: 0
})
return getAsMultiTx({ api, threshold, otherSignatories: otherSigners, tx })
} catch (e) {
console.error('Error in multisigTx')
console.error(e)
Expand Down
12 changes: 4 additions & 8 deletions packages/ui/src/pages/Creation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import WithProxySelection from './WithProxySelection'
import { useGetSortAddress } from '../../hooks/useGetSortAddress'
import { useGetMultisigAddress } from '../../contexts/useGetMultisigAddress'
import { isEthereumAddress } from '@polkadot/util-crypto'
import { getAsMultiTx } from '../../utils/getAsMultiTx'

interface Props {
className?: string
Expand Down Expand Up @@ -100,10 +101,7 @@ const MultisigCreation = ({ className }: Props) => {
signatories.filter((sig) => sig !== selectedAccount.address)
)
const remarkTx = api.tx.system.remark(`Multix creation ${multiAddress}`)
return api.tx.multisig.asMulti(threshold, otherSignatories, null, remarkTx, {
refTime: 0,
proofSize: 0
})
return getAsMultiTx({ api, threshold, otherSignatories, tx: remarkTx })
}, [api, getSortAddress, multiAddress, selectedAccount, signatories, threshold, withProxy])

const batchCall = useMemo(() => {
Expand Down Expand Up @@ -139,10 +137,8 @@ const MultisigCreation = ({ className }: Props) => {
signatories.filter((sig) => sig !== selectedAccount.address)
)
const proxyTx = api.tx.proxy.createPure('Any', 0, 0)
const multiSigProxyCall = api.tx.multisig.asMulti(threshold, otherSignatories, null, proxyTx, {
refTime: 0,
proofSize: 0
})
const multiSigProxyCall = getAsMultiTx({ api, threshold, otherSignatories, tx: proxyTx })

// Some funds are needed on the multisig for the pure proxy creation
const transferTx = api.tx.balances.transferKeepAlive(
multiAddress,
Expand Down
28 changes: 28 additions & 0 deletions packages/ui/src/utils/getAsMultiTx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ApiPromise } from '@polkadot/api'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import { ISubmittableResult } from '@polkadot/types/types'
import { Weight } from '@polkadot/types/interfaces'
import { HexString, MultisigStorageInfo } from '../types'

interface Params {
api: ApiPromise
threshold: number
otherSignatories: string[]
tx?: SubmittableExtrinsic<'promise', ISubmittableResult> | HexString
weight?: Weight
when?: MultisigStorageInfo['when']
}
export const getAsMultiTx = ({ api, threshold, otherSignatories, tx, weight, when }: Params) => {
return api.tx.multisig.asMulti.meta.args.length === 6
? api.tx.multisig.asMulti(threshold, otherSignatories, when || null, tx, false, weight || 0)
: api.tx.multisig.asMulti(
threshold,
otherSignatories,
when || null,
tx,
weight || {
refTime: 0,
proofSize: 0
}
)
}

0 comments on commit 5120dde

Please sign in to comment.