Skip to content

Commit

Permalink
Check wc account and network (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Dec 9, 2024
1 parent 36ec496 commit 6aff1ae
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
23 changes: 18 additions & 5 deletions packages/ui/src/components/CallInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ const isWhiteListedCall = (type: string, value: string) => {
'Staking.nominate',
'Proxy.add_proxy',
'Proxy.remove_proxy',
'Proxy.kill_pure'
'Proxy.kill_pure',
'ConvictionVoting.delegate',
'ConvictionVoting.vote',
'ConvictionVoting.remove_vote',
'ConvictionVoting.undelegate',
'ConvictionVoting.unlock'
].includes(`${type}.${value}`)
}

Expand All @@ -71,7 +76,9 @@ const formatBalance = (amount: bigint, label: string, chainInfo: ChainInfoHuman,

const eachFieldRendered = (value: Record<string, any>, chainInfo: ChainInfoHuman, id: string) => {
// for transfer, nomination, staking, bounties
const bigIntKey = ['value', 'fee', 'max_additional'].find((key) => typeof value[key] === 'bigint')
const bigIntKey = ['value', 'fee', 'max_additional', 'balance'].find(
(key) => typeof value[key] === 'bigint'
)

if (bigIntKey) {
return formatBalance(value[bigIntKey], bigIntKey, chainInfo, id)
Expand Down Expand Up @@ -120,9 +127,15 @@ const eachFieldRendered = (value: Record<string, any>, chainInfo: ChainInfoHuman
}

// that's an Account with MultiAddress.Id
const multiAddressKey = ['dest', 'beneficiary', 'curator', 'delegate', 'spawner'].find(
(key) => typeof value[key] === 'object' && value[key].type === 'Id'
)
const multiAddressKey = [
'dest',
'beneficiary',
'curator',
'delegate',
'spawner',
'to',
'target'
].find((key) => typeof value[key] === 'object' && value[key].type === 'Id')

if (multiAddressKey) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P
polkadot: {
accounts: accountsToShare,
methods,
events
events,
chains
}
}
})
Expand All @@ -81,7 +82,7 @@ const WalletConnectSessionProposal = ({ onClose, className, sessionProposal }: P
onClose()
refresh()
})
}, [accountsToShare, events, methods, onClose, refresh, sessionProposal, web3wallet])
}, [accountsToShare, chains, events, methods, onClose, refresh, sessionProposal, web3wallet])

const onReject = useCallback(() => {
if (!web3wallet || !sessionProposal) return
Expand Down
28 changes: 27 additions & 1 deletion packages/ui/src/components/modals/WalletConnectSigning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useMultisigProposalNeededFunds } from '../../hooks/useMultisigProposalN
import { useCheckBalance } from '../../hooks/useCheckBalance'
import { formatBigIntBalance } from '../../utils/formatBnBalance'
import { getErrorMessageReservedFunds } from '../../utils/getErrorMessageReservedFunds'
import { useGetWalletConnectNamespace } from '../../hooks/useWalletConnectNamespace'

export interface SigningModalProps {
onClose: () => void
Expand All @@ -37,6 +38,7 @@ export interface SigningModalProps {

const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModalProps) => {
const { api, chainInfo } = useApi()
const { currentNamespace } = useGetWalletConnectNamespace()
const [isSubmitting, setIsSubmitting] = useState(false)
const { web3wallet } = useWalletConnect()
const {
Expand Down Expand Up @@ -81,6 +83,30 @@ const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModa
address: selectedAccount?.address
})

useEffect(() => {
const requestedChainId = request.params.chainId
if (requestedChainId !== currentNamespace) {
setErrorMessage(
`Wrong selected network in Multix. Please reject, then select the correct network and resubmit the transaction. Request with namespace: ${requestedChainId}`
)
}
}, [currentNamespace, originAddress, request.params.chainId])

const isCorrectMultiproxySelected = useMemo(
() =>
selectedMultiProxy?.proxy === originAddress ||
selectedMultiProxy?.multisigs.map(({ address }) => address).includes(originAddress),
[selectedMultiProxy, originAddress]
)

useEffect(() => {
if (!isCorrectMultiproxySelected) {
setErrorMessage(
`Wrong multisig selected in Multix. Please reject, then select the correct multisig and resubmit the transaction. Request with address: ${originAddress}`
)
}
}, [isCorrectMultiproxySelected, originAddress])

useEffect(() => {
if (multisigProposalNeededFunds !== 0n && !hasSignerEnoughFunds) {
const requiredBalanceString = formatBigIntBalance(
Expand Down Expand Up @@ -260,7 +286,7 @@ const ProposalSigning = ({ onClose, className, request, onSuccess }: SigningModa
callData,
name: getExtrinsicName(callInfo?.section, callInfo?.method)
}}
expanded
expanded={!errorMessage}
/>
</Grid>
</>
Expand Down
2 changes: 1 addition & 1 deletion squid/assets/envs/.env.chopsticks-ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ DB_HOST=postgres
# kusama chopsticks
BLOCK_START=26000000
PREFIX=2
RPC_WS="ws://localhost:8000"
RPC_WS="http://localhost:8000"
CHAIN_ID='kusama'
4 changes: 2 additions & 2 deletions squid/assets/envs/.env.chopsticks-local
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# DB_PORT=5432
# GQL_PORT=4350
GQL_PORT=4350
# SQD_DEBUG=sqd:processor:mapping
# SQD_DEBUG=*

# kusama chopsticks
BLOCK_START=26000000
PREFIX=2
RPC_WS="ws://localhost:8000"
RPC_WS="http://localhost:8000"
CHAIN_ID='kusama'

0 comments on commit 6aff1ae

Please sign in to comment.