Skip to content

Commit 067998f

Browse files
committed
fixed other areas that needs to hard token hardcoded as 18
1 parent 96d02f9 commit 067998f

4 files changed

Lines changed: 32 additions & 7 deletions

File tree

src/modules/etherlink/components/EvmProposalVoteDetail.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export const EvmProposalVoteDetail: React.FC<{
3535
tokenAddress: daoSelected?.token,
3636
tokenID: daoSelected?.id,
3737
symbol: daoSelected?.symbol,
38-
decimals: daoSelected?.decimals
38+
// decimals: daoSelected?.decimals || 18
39+
// Hardcoded because of https://github.com/dOrgTech/homebase-app/issues/932
40+
decimals: 18
3941
}),
4042
[daoSelected]
4143
)

src/modules/etherlink/components/EvmProposalVoterList.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { etherlinkStyled as _est } from "components/ui"
2323
const { Container, CustomContent, Header, VotesRow, StyledTableCell, StyledTableRow, CopyIcon } = _est
2424
import OpenInNewIcon from "@mui/icons-material/OpenInNew"
2525
import { getBlockExplorerUrl } from "modules/etherlink/utils"
26+
import { ethers } from "ethers"
2627
interface IVoter {
2728
voter: string
2829
option: number
@@ -37,7 +38,7 @@ export const EvmProposalVoterList = () => {
3738
const theme = useTheme()
3839
const isMobileSmall = useMediaQuery(theme.breakpoints.down("sm"))
3940
const { copyAddress, showProposalVoterList, setShowProposalVoterList } = useEvmDaoUiOps()
40-
const { daoProposalSelected, daoProposalVoters, network } = useContext(EtherlinkContext)
41+
const { daoProposalSelected, daoProposalVoters, network, daoSelected } = useContext(EtherlinkContext)
4142

4243
// Sort votes by cast time (desc)
4344
const sortedVotes: IVoter[] = useMemo(() => {
@@ -69,6 +70,17 @@ export const EvmProposalVoterList = () => {
6970
}
7071
}, [daoProposalVoters])
7172

73+
const formatWeight = (weight: number | string): string => {
74+
try {
75+
const decimals = daoSelected?.decimals || 18
76+
const weightStr = String(weight)
77+
if (!weightStr || weightStr === "0") return "0"
78+
return ethers.formatUnits(weightStr, decimals)
79+
} catch {
80+
return String(weight)
81+
}
82+
}
83+
7284
const handlePageClick = (event: { selected: number }) => {
7385
setCurrentPage(event.selected)
7486
}
@@ -153,7 +165,7 @@ export const EvmProposalVoterList = () => {
153165
</Grid>
154166
<Grid item container direction="row" alignItems="center" justifyContent="center">
155167
<Typography color="textPrimary" variant="body1">
156-
{row.weight}
168+
{formatWeight(row.weight)}
157169
</Typography>
158170
</Grid>
159171
</Grid>{" "}
@@ -176,7 +188,7 @@ export const EvmProposalVoterList = () => {
176188
<StyledTableCell align="right">
177189
{" "}
178190
<Typography color="textPrimary" variant="body1">
179-
{row.weight}
191+
{formatWeight(row.weight)}
180192
</Typography>
181193
</StyledTableCell>
182194
<StyledTableCell align="right">

src/services/contracts/etherlinkDAO/hooks/useEvmProposalOps.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ export const useEvmProposalCreateZustantStore = create<EvmProposalCreateStore>()
475475
typeof targetAmountStr === "string" && targetAmountStr.trim() !== "" && !isNaN(Number(targetAmountStr))
476476

477477
if (hasValidAddress && hasValidAmount) {
478-
const amountWithDecimals = ethers.parseUnits(targetAmountStr, tokenDecimals || 0)
478+
// const tokenActualDecimals = tokenDecimals || 18
479+
// Hardcoded because of https://github.com/dOrgTech/homebase-app/issues/932
480+
const amountWithDecimals = ethers.parseUnits(targetAmountStr, 18)
479481
const encodedData = iface.encodeFunctionData(selectedInterface.name, [targetAddress, amountWithDecimals])
480482
payload.createProposalPayload = {
481483
...get().createProposalPayload,

src/services/wagmi/etherlink/hooks/useDaoState.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ export const useDaoState = ({ network }: { network: string }) => {
101101
if (!firebaseRootCollection) return
102102
if (firestoreData?.[firebaseRootCollection]) {
103103
const allDaoList = firestoreData[firebaseRootCollection]
104-
setDaoData(allDaoList)
104+
const normalizedDaoList = allDaoList.map((dao: any) => ({
105+
...dao,
106+
// decimals: dao.decimals || 18
107+
// Hardcoded because of https://github.com/dOrgTech/homebase-app/issues/932
108+
decimals: 18
109+
}))
110+
setDaoData(normalizedDaoList)
105111
setIsLoadingDaos(false)
106112
}
107113
const firestoreNetworkName = getFirestoreNetworkName(network)
@@ -721,7 +727,10 @@ export const useDaoState = ({ network }: { network: string }) => {
721727
(daoId: string) => {
722728
const dao = daoData.find(dao => (dao?.id || "").toLowerCase() === (daoId || "").toLowerCase())
723729
if (dao) {
724-
setDaoSelected(dao)
730+
setDaoSelected({
731+
...dao,
732+
decimals: dao.decimals || 18
733+
})
725734
selectedDaoIdRef.current = daoId
726735
}
727736
},

0 commit comments

Comments
 (0)