From 0965d1e53f21a200997e9b9a8d8ee79be010c7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Santana=20Gon=C3=A7alves?= Date: Mon, 11 Nov 2024 22:59:25 -0300 Subject: [PATCH 1/4] add delegation section --- src/app/communities/HolderColumn.tsx | 23 ++++++++++++++ src/app/communities/NftHoldersSection.tsx | 22 +------------ src/app/user/Delegation/DelegationSection.tsx | 31 +++++++++++++++++++ src/app/user/Delegation/hooks/useDelegate.tsx | 21 +++++++++++++ src/app/user/Delegation/index.ts | 1 + src/app/user/page.tsx | 2 ++ src/components/Table/index.ts | 2 +- 7 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 src/app/communities/HolderColumn.tsx create mode 100644 src/app/user/Delegation/DelegationSection.tsx create mode 100644 src/app/user/Delegation/hooks/useDelegate.tsx create mode 100644 src/app/user/Delegation/index.ts diff --git a/src/app/communities/HolderColumn.tsx b/src/app/communities/HolderColumn.tsx new file mode 100644 index 00000000..222a173d --- /dev/null +++ b/src/app/communities/HolderColumn.tsx @@ -0,0 +1,23 @@ +import { Span } from '@/components/Typography' +import { EXPLORER_URL } from '@/lib/constants' +import { RxExternalLink } from 'react-icons/rx' + +interface HolderColumnProps { + address: string + rns?: string + image?: string +} + +export const HolderColumn = ({ address, rns, image }: HolderColumnProps) => ( + + Holders Image + + {rns || address} + + + +) diff --git a/src/app/communities/NftHoldersSection.tsx b/src/app/communities/NftHoldersSection.tsx index 03f996d3..64c67c98 100644 --- a/src/app/communities/NftHoldersSection.tsx +++ b/src/app/communities/NftHoldersSection.tsx @@ -10,27 +10,7 @@ import { useState } from 'react' import { TableIcon } from '@/app/communities/TableIcon' import { SquareIcon } from '@/app/communities/SquareIcon' import { ErrorMessageAlert } from '@/components/ErrorMessageAlert/ErrorMessageAlert' - -interface HolderColumnProps { - address: string - rns?: string - image?: string -} -const HolderColumn = ({ address, rns, image }: HolderColumnProps) => { - return ( - - Holders Image - - {rns || address} - - - - ) -} +import { HolderColumn } from './HolderColumn' interface IdNumberColumnProps { id: string diff --git a/src/app/user/Delegation/DelegationSection.tsx b/src/app/user/Delegation/DelegationSection.tsx new file mode 100644 index 00000000..7887df26 --- /dev/null +++ b/src/app/user/Delegation/DelegationSection.tsx @@ -0,0 +1,31 @@ +import { Table } from '@/components/Table' +import { HeaderTitle } from '@/components/Typography' +import { RenderTotalBalance } from '../Balances/RenderTotalBalance' +import { BalancesProvider } from '../Balances/context/BalancesContext' +import { useDelegate } from './hooks/useDelegate' +import { useAccount } from 'wagmi' +import { HolderColumn } from '@/app/communities/HolderColumn' + +export const DelegationSection = () => { + const { address } = useAccount() + const { delegateeAddress } = useDelegate(address) + + if (!delegateeAddress) { + return null + } + + const delegatees = [ + { + 'Voting Power Received': , + Amount: , + }, + ] + return ( + <> + Delegation + + + + + ) +} diff --git a/src/app/user/Delegation/hooks/useDelegate.tsx b/src/app/user/Delegation/hooks/useDelegate.tsx new file mode 100644 index 00000000..9bedca49 --- /dev/null +++ b/src/app/user/Delegation/hooks/useDelegate.tsx @@ -0,0 +1,21 @@ +import { StRIFTokenAbi } from '@/lib/abis/StRIFTokenAbi' +import { tokenContracts } from '@/lib/contracts' +import { Address } from 'viem' +import { useReadContract } from 'wagmi' + +const stRifContract = { + abi: StRIFTokenAbi, + address: tokenContracts.stRIF, +} + +export const useDelegate = (address: Address | undefined) => { + const { data: delegateeAddress } = useReadContract( + address && { + ...stRifContract, + functionName: 'delegates', + args: [address], + }, + ) + + return { delegateeAddress } +} diff --git a/src/app/user/Delegation/index.ts b/src/app/user/Delegation/index.ts new file mode 100644 index 00000000..2f903119 --- /dev/null +++ b/src/app/user/Delegation/index.ts @@ -0,0 +1 @@ +export * from './DelegationSection' diff --git a/src/app/user/page.tsx b/src/app/user/page.tsx index fe175e8b..6c331eec 100644 --- a/src/app/user/page.tsx +++ b/src/app/user/page.tsx @@ -9,6 +9,7 @@ import { withBuilderButton, useGetBuilderToGauge } from '@/app/collective-reward import { TxStatusMessage } from '@/components/TxStatusMessage' import { zeroAddress } from 'viem' import { useHandleErrors } from '@/app/collective-rewards/utils' +import { DelegationSection } from './Delegation' type MyHoldingsProps = { showBuilderButton?: boolean @@ -18,6 +19,7 @@ const MyHoldings = ({ showBuilderButton = false }: MyHoldingsProps) => ( <> + ) diff --git a/src/components/Table/index.ts b/src/components/Table/index.ts index c55a8cb2..6c3e3747 100644 --- a/src/components/Table/index.ts +++ b/src/components/Table/index.ts @@ -1,2 +1,2 @@ export * from './components' -export { Table } from './Table' +export * from './Table' From de329109d3b4ea7309f9cc79230555a926a809db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Santana=20Gon=C3=A7alves?= Date: Tue, 12 Nov 2024 12:29:00 -0300 Subject: [PATCH 2/4] check if it's not delegate to himself --- src/app/user/Delegation/DelegationSection.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/user/Delegation/DelegationSection.tsx b/src/app/user/Delegation/DelegationSection.tsx index 7887df26..240cb96a 100644 --- a/src/app/user/Delegation/DelegationSection.tsx +++ b/src/app/user/Delegation/DelegationSection.tsx @@ -10,7 +10,7 @@ export const DelegationSection = () => { const { address } = useAccount() const { delegateeAddress } = useDelegate(address) - if (!delegateeAddress) { + if (!delegateeAddress || address === delegateeAddress) { return null } From 9d94374ecbdc6f6f413b2db7e10de1df95e3f468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Santana=20Gon=C3=A7alves?= Date: Tue, 12 Nov 2024 12:32:13 -0300 Subject: [PATCH 3/4] fix subtitle --- src/app/user/Delegation/DelegationSection.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/app/user/Delegation/DelegationSection.tsx b/src/app/user/Delegation/DelegationSection.tsx index 240cb96a..fab8a7fb 100644 --- a/src/app/user/Delegation/DelegationSection.tsx +++ b/src/app/user/Delegation/DelegationSection.tsx @@ -1,30 +1,28 @@ +import { HolderColumn } from '@/app/communities/HolderColumn' import { Table } from '@/components/Table' import { HeaderTitle } from '@/components/Typography' +import { useAccount } from 'wagmi' import { RenderTotalBalance } from '../Balances/RenderTotalBalance' import { BalancesProvider } from '../Balances/context/BalancesContext' import { useDelegate } from './hooks/useDelegate' -import { useAccount } from 'wagmi' -import { HolderColumn } from '@/app/communities/HolderColumn' export const DelegationSection = () => { const { address } = useAccount() const { delegateeAddress } = useDelegate(address) - if (!delegateeAddress || address === delegateeAddress) { + if (!delegateeAddress || delegateeAddress === address) { return null } - const delegatees = [ - { - 'Voting Power Received': , - Amount: , - }, - ] + const delegatee = { + 'Voting Power Delegated': , + Amount: , + } return ( <> Delegation -
+
) From 17a97e16c5c36adc4ddb6365ee36534dc12aaf92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Santana=20Gon=C3=A7alves?= Date: Tue, 12 Nov 2024 12:41:09 -0300 Subject: [PATCH 4/4] rename hook --- src/app/user/Delegation/DelegationSection.tsx | 4 ++-- .../Delegation/hooks/{useDelegate.tsx => useGetDelegates.tsx} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/app/user/Delegation/hooks/{useDelegate.tsx => useGetDelegates.tsx} (87%) diff --git a/src/app/user/Delegation/DelegationSection.tsx b/src/app/user/Delegation/DelegationSection.tsx index fab8a7fb..1fa8fe15 100644 --- a/src/app/user/Delegation/DelegationSection.tsx +++ b/src/app/user/Delegation/DelegationSection.tsx @@ -4,11 +4,11 @@ import { HeaderTitle } from '@/components/Typography' import { useAccount } from 'wagmi' import { RenderTotalBalance } from '../Balances/RenderTotalBalance' import { BalancesProvider } from '../Balances/context/BalancesContext' -import { useDelegate } from './hooks/useDelegate' +import { useGetDelegates } from './hooks/useGetDelegates' export const DelegationSection = () => { const { address } = useAccount() - const { delegateeAddress } = useDelegate(address) + const { delegateeAddress } = useGetDelegates(address) if (!delegateeAddress || delegateeAddress === address) { return null diff --git a/src/app/user/Delegation/hooks/useDelegate.tsx b/src/app/user/Delegation/hooks/useGetDelegates.tsx similarity index 87% rename from src/app/user/Delegation/hooks/useDelegate.tsx rename to src/app/user/Delegation/hooks/useGetDelegates.tsx index 9bedca49..5073ce66 100644 --- a/src/app/user/Delegation/hooks/useDelegate.tsx +++ b/src/app/user/Delegation/hooks/useGetDelegates.tsx @@ -8,7 +8,7 @@ const stRifContract = { address: tokenContracts.stRIF, } -export const useDelegate = (address: Address | undefined) => { +export const useGetDelegates = (address: Address | undefined) => { const { data: delegateeAddress } = useReadContract( address && { ...stRifContract,