From 3bef51793e6301748474810bef97eecb34ec51ed Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Mon, 14 Oct 2024 08:28:27 +0200 Subject: [PATCH] 2 tx flow, first remove votes and undelegate then delegate (#186) --- .papi/polkadot-api.json | 4 +- src/assets/networks.json | 2 +- src/components/Alert.tsx | 11 +- src/components/LocksCard.tsx | 52 +------ src/header.tsx | 19 +-- src/hooks/useGetDelegateTx.tsx | 12 +- src/hooks/useGetSubsquareRefUrl.tsx | 8 ++ src/pages/Delegate/MultiTransactionDialog.tsx | 5 +- src/pages/Delegate/index.tsx | 128 +++++++++++------- 9 files changed, 110 insertions(+), 131 deletions(-) create mode 100644 src/hooks/useGetSubsquareRefUrl.tsx diff --git a/.papi/polkadot-api.json b/.papi/polkadot-api.json index dd4020e..2e3c365 100644 --- a/.papi/polkadot-api.json +++ b/.papi/polkadot-api.json @@ -11,7 +11,7 @@ "metadata": ".papi/metadata/ksm.scale" }, "fastWestend": { - "wsUrl": "wss://rpc-test-network-1.novasamatech.org", + "wsUrl": "wss://rpc-test-network-1.novasama-tech.org", "metadata": ".papi/metadata/fastWestend.scale" }, "westend": { @@ -31,4 +31,4 @@ "metadata": ".papi/metadata/westendPeople.scale" } } -} \ No newline at end of file +} diff --git a/src/assets/networks.json b/src/assets/networks.json index bb93c20..8ad5a8e 100644 --- a/src/assets/networks.json +++ b/src/assets/networks.json @@ -306,7 +306,7 @@ "options": ["testnet"], "nodes": [ { - "url": "wss://rpc-test-network-1.novasamatech.org", + "url": "wss://rpc-test-network-1.novasama-tech.org", "name": "Development node" } ], diff --git a/src/components/Alert.tsx b/src/components/Alert.tsx index 7426e99..808420b 100644 --- a/src/components/Alert.tsx +++ b/src/components/Alert.tsx @@ -1,16 +1,17 @@ import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' -import { AlertCircle } from 'lucide-react' +import { AlertCircle, InfoIcon } from 'lucide-react' interface Props { - title: string - message: string + title?: string + message: string | React.ReactNode variant?: 'default' | 'destructive' | null } export const AlertNote = ({ title, message, variant = 'default' }: Props) => ( - - {title} + {variant === 'destructive' && } + {variant === 'default' && } + {title && {title}} {message} ) diff --git a/src/components/LocksCard.tsx b/src/components/LocksCard.tsx index c31bff1..48206f9 100644 --- a/src/components/LocksCard.tsx +++ b/src/components/LocksCard.tsx @@ -10,7 +10,7 @@ import { planckToUnit } from '@polkadot-ui/utils' import { Button } from './ui/button' import { Title } from './ui/title' import { ContentReveal } from './ui/content-reveal' -import { BadgeCent, Clock2, Info, LockKeyholeOpen, Vote } from 'lucide-react' +import { BadgeCent, Clock2, Info, LockKeyholeOpen } from 'lucide-react' import { Badge } from './ui/badge' import { useAccounts } from '@/contexts/AccountsContext' import { @@ -30,7 +30,6 @@ export const LocksCard = () => { const [expectedBlockTime, setExpectedBlockTime] = useState(0) const { api, assetInfo } = useNetwork() const { voteLocks, delegationLocks } = useLocks() - const [ongoingVoteLocks, setOngoingVoteLocks] = useState([]) const [freeLocks, setFreeLocks] = useState>( [], ) @@ -47,14 +46,11 @@ export const LocksCard = () => { useEffect(() => { if (!currentBlock) return - const tempOngoingLocks: VoteLock[] = [] const tempFree: Array = [] const tempCurrent: VoteLock[] = [] voteLocks.forEach((voteLocks) => { - if (voteLocks.isOngoing) { - tempOngoingLocks.push(voteLocks) - } else if (voteLocks.endBlock <= currentBlock) { + if (voteLocks.endBlock <= currentBlock) { tempFree.push(voteLocks) } else { tempCurrent.push(voteLocks) @@ -74,7 +70,6 @@ export const LocksCard = () => { } }) - setOngoingVoteLocks(tempOngoingLocks) setFreeLocks(tempFree) setCurrentLocks(tempCurrent) setCurrentDelegationLocks(tempDelegationLocks) @@ -273,49 +268,6 @@ export const LocksCard = () => { - -
- Votes - - - - - -

- Votes casted on a referendum that is still in deciding - phase. -

-
-
-
-
- {ongoingVoteLocks.length} - -
- { - - } -
)} diff --git a/src/header.tsx b/src/header.tsx index 5b38bdf..0177972 100644 --- a/src/header.tsx +++ b/src/header.tsx @@ -122,24 +122,7 @@ export const Header = () => {
-
- {/* TODO: split submenu based on routes - - - File - - - New Tab ⌘T - - New Window - - Share - - Print - - - */} -
+
diff --git a/src/hooks/useGetDelegateTx.tsx b/src/hooks/useGetDelegateTx.tsx index 21d0f34..0f2dbb2 100644 --- a/src/hooks/useGetDelegateTx.tsx +++ b/src/hooks/useGetDelegateTx.tsx @@ -47,11 +47,13 @@ export const useGetDelegateTx = () => { >[] = [] Object.values(delegations || {}).forEach((delegation) => { - delegation.map(({ trackId }) => { - removeDelegationsTxs.push( - api.tx.ConvictionVoting.undelegate({ class: trackId }), - ) - }) + delegation + .filter(({ trackId }) => tracks.includes(trackId)) + .map(({ trackId }) => { + removeDelegationsTxs.push( + api.tx.ConvictionVoting.undelegate({ class: trackId }), + ) + }) }) const delegationTxs = tracks.map((trackId) => diff --git a/src/hooks/useGetSubsquareRefUrl.tsx b/src/hooks/useGetSubsquareRefUrl.tsx new file mode 100644 index 0000000..bc5d977 --- /dev/null +++ b/src/hooks/useGetSubsquareRefUrl.tsx @@ -0,0 +1,8 @@ +import { useNetwork } from '@/contexts/NetworkContext' + +export const useGetSubsquareRefUrl = () => { + const { network } = useNetwork() + + return (refId: number) => + `https://${network}.subsquare.io/referenda/${refId.toString()}` +} diff --git a/src/pages/Delegate/MultiTransactionDialog.tsx b/src/pages/Delegate/MultiTransactionDialog.tsx index 91aece6..00259d9 100644 --- a/src/pages/Delegate/MultiTransactionDialog.tsx +++ b/src/pages/Delegate/MultiTransactionDialog.tsx @@ -147,9 +147,8 @@ export const MultiTransactionDialog = ({
{step === 1 && - 'The delegation process is in 2 parts. First, please sign a transaction to remove current votes and delegations.'} - {step === 2 && - 'Votes and delegation are removed. You are now ready to sign a transaction to delegate.'} + "First, let's clear previous votes or delegations."} + {step === 2 && 'Now, we are ready to delegate.'}