Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter proxy only for the currently selected pure #616

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/ui/src/components/EasySetup/FromCallData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import { getExtrinsicName } from '../../utils/getExtrinsicName'
import { usePjsLinks } from '../../hooks/usePjsLinks'
import { Binary, HexString, Transaction } from 'polkadot-api'
import { getPapiHowLink } from '../../utils/getPapiHowLink'
import { decodeAddress } from '@polkadot/util-crypto'
import { u8aToHex } from '@polkadot/util'

interface Props {
className?: string
onSetExtrinsic: (ext: Transaction<any, any, any, any>) => void
currentProxy?: string
}

const FromCallData = ({ className, onSetExtrinsic }: Props) => {
const FromCallData = ({ className, onSetExtrinsic, currentProxy }: Props) => {
const { api } = useApi()
const [pastedCallData, setPastedCallData] = useState<HexString | undefined>(undefined)
const [callDataError, setCallDataError] = useState('')
Expand All @@ -27,15 +30,25 @@ const FromCallData = ({ className, onSetExtrinsic }: Props) => {
setIsProxyProxyRemoved(false)
if (!api) return call

if (!currentProxy) return call

try {
const decodedCall = (await api.txFromCallData(Binary.fromHex(call))).decodedCall

const real = `0x${call.substring(8, 72)}`
const currentProxyAddress = u8aToHex(decodeAddress(currentProxy))

// check if this call is a proxy.proxy
if (decodedCall.type === 'Proxy' && decodedCall.value.type === 'proxy') {
if (
decodedCall.type === 'Proxy' &&
decodedCall.value.type === 'proxy' &&
real === currentProxyAddress
) {
// a proxy.proxy call is encoded with e.g
// callIndex 1e00
// real 00 eb53ed54b7f921a438923e6eb52c4d89afc5c0fed5d0d15fb78648c53da227a0
// forceProxyType 00
// only remove the proxy if it's the proxy associated with the multisig
setIsProxyProxyRemoved(true)
return `0x${call.substring(74)}` as HexString
}
Expand All @@ -46,7 +59,7 @@ const FromCallData = ({ className, onSetExtrinsic }: Props) => {
return
}
},
[api]
[api, currentProxy]
)

// users may erroneously paste callData from the multisig calldata
Expand Down
9 changes: 7 additions & 2 deletions packages/ui/src/components/modals/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ const Send = ({ onClose, className, onSuccess, onFinalized, preselected }: Props
// hasErrorMessage={!!easyOptionErrorMessage}
// />
// ),
[EasyTransferTitle.FromCallData]: <FromCallData onSetExtrinsic={setExtrinsicToCall} />
[EasyTransferTitle.FromCallData]: (
<FromCallData
onSetExtrinsic={setExtrinsicToCall}
currentProxy={isProxySelected ? selectedOrigin.address : undefined}
/>
)
} as Partial<Record<EasyTransferTitle, ReactNode>>

// if (hasIdentityPallet && !hasPplChain) {
Expand All @@ -176,7 +181,7 @@ const Send = ({ onClose, className, onSuccess, onFinalized, preselected }: Props
// }

return res
}, [selectedOrigin.address])
}, [selectedOrigin.address, isProxySelected])

const signCallback = useSigningCallback({
onSuccess: () => {
Expand Down
Loading