diff --git a/packages/next-common/components/collectives/core/member/salary.js b/packages/next-common/components/collectives/core/member/salary.js index a773cf82cb..61def90dc7 100644 --- a/packages/next-common/components/collectives/core/member/salary.js +++ b/packages/next-common/components/collectives/core/member/salary.js @@ -1,4 +1,4 @@ -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import ValueDisplay from "next-common/components/valueDisplay"; import { toPrecision } from "next-common/utils"; import { getRankSalary } from "next-common/utils/fellowship/getRankSalary"; @@ -13,7 +13,7 @@ export function CoreFellowshipMemberSalaryContent({ const { activeSalary, passiveSalary } = params; const salaryArray = isActive ? activeSalary : passiveSalary; const salary = getRankSalary(salaryArray, rank); - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); return ( -; + } + + return ( +
+ {hasUsdt && ( + + )} + {hasHollar && ( + + )} +
+ ); +} diff --git a/packages/next-common/components/detail/treasury/common/bountyCountDown.js b/packages/next-common/components/detail/treasury/common/bountyCountDown.js index 5dd589cdba..9807513a15 100644 --- a/packages/next-common/components/detail/treasury/common/bountyCountDown.js +++ b/packages/next-common/components/detail/treasury/common/bountyCountDown.js @@ -10,7 +10,7 @@ import { useOnchainData } from "next-common/context/post"; */ export default function BountyCountDown() { const data = useOnchainData(); - if (data.state?.state !== "PendingPayout") { + if (!data || data.state?.state !== "PendingPayout") { return null; } diff --git a/packages/next-common/components/feeds/fellowshipCommonEvent.js b/packages/next-common/components/feeds/fellowshipCommonEvent.js index d31e253b2e..f4c8141c19 100644 --- a/packages/next-common/components/feeds/fellowshipCommonEvent.js +++ b/packages/next-common/components/feeds/fellowshipCommonEvent.js @@ -61,6 +61,7 @@ function EventContent({ feed, showUserInfo = true }) { ); } diff --git a/packages/next-common/components/fellowship/params/descriptions.jsx b/packages/next-common/components/fellowship/params/descriptions.jsx index 387d953765..5b958f331f 100644 --- a/packages/next-common/components/fellowship/params/descriptions.jsx +++ b/packages/next-common/components/fellowship/params/descriptions.jsx @@ -1,7 +1,7 @@ import { isNumber } from "lodash-es"; import BillBoardPanel from "next-common/components/billBoardPanel"; import ValueDisplay from "next-common/components/valueDisplay"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import { toPrecision } from "next-common/utils"; import dynamic from "next/dynamic"; import Period from "./period"; @@ -75,7 +75,7 @@ function getMemberInfoItems({ rank, params, decimals, symbol }) { } function useRankInfoItems(rank, params) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); if (!isNumber(rank)) { return []; diff --git a/packages/next-common/components/fellowship/params/list.jsx b/packages/next-common/components/fellowship/params/list.jsx index 6ab48b3fa5..6cc993d46b 100644 --- a/packages/next-common/components/fellowship/params/list.jsx +++ b/packages/next-common/components/fellowship/params/list.jsx @@ -1,6 +1,6 @@ import DataList from "next-common/components/dataList"; import ValueDisplay from "next-common/components/valueDisplay"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import { toPrecision } from "next-common/utils"; import Period, { PromotionPeriod, @@ -38,7 +38,7 @@ export default function FellowshipParamsList({ rank, params }) { minPromotionPeriod = [], } = params ?? {}; - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); const rows = activeSalary?.map?.((_, idx) => { return [ diff --git a/packages/next-common/components/fellowship/salary/actions/hooks/useMyAccountSalaryWithSymbol.js b/packages/next-common/components/fellowship/salary/actions/hooks/useMyAccountSalaryWithSymbol.js index 174f8796b3..9c8c8bdf53 100644 --- a/packages/next-common/components/fellowship/salary/actions/hooks/useMyAccountSalaryWithSymbol.js +++ b/packages/next-common/components/fellowship/salary/actions/hooks/useMyAccountSalaryWithSymbol.js @@ -1,4 +1,4 @@ -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import rankToIndex from "next-common/utils/fellowship/rankToIndex"; import { useCoreFellowshipParams } from "next-common/context/collectives/collectives"; import { isSameAddress } from "next-common/utils"; @@ -26,7 +26,7 @@ export function useMySalary() { export function useMyAccountSalaryWithSymbol() { const salaryValue = useMySalary() ?? 0; - const { decimals, symbol } = getSalaryAsset(); + const { decimals, symbol } = useSalaryAsset(); return { value: salaryValue, diff --git a/packages/next-common/components/fellowship/salary/claimants/list.jsx b/packages/next-common/components/fellowship/salary/claimants/list.jsx index 241dfb756d..8847d57f49 100644 --- a/packages/next-common/components/fellowship/salary/claimants/list.jsx +++ b/packages/next-common/components/fellowship/salary/claimants/list.jsx @@ -5,7 +5,6 @@ import { has, isNil } from "lodash-es"; import AddressUser from "next-common/components/user/addressUser"; import FellowshipSalaryMemberIsRegistered from "./isRegistered"; import Link from "next-common/components/link"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; import ValueDisplay from "next-common/components/valueDisplay"; import { toPrecision } from "next-common/utils"; import { getRankSalary } from "next-common/utils/fellowship/getRankSalary"; @@ -18,9 +17,10 @@ import Tooltip from "next-common/components/tooltip"; import { isSameAddress } from "next-common/utils"; import FieldLoading from "next-common/components/icons/fieldLoading"; import { SystemVoteAbstain } from "@osn/icons/subsquare"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; function SalaryCellTooltip({ isActive, rank, params, children }) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); const { activeSalary = [], passiveSalary = [] } = params ?? {}; const activeRankSalary = getRankSalary(activeSalary, rank); @@ -54,7 +54,7 @@ function SalaryCellTooltip({ isActive, rank, params, children }) { } function ClaimantAmountCell({ claimant }) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); const status = claimant?.status?.status || {}; const registered = has(status, "registered") ? status?.registered @@ -72,7 +72,7 @@ function ClaimantSalaryCell({ claimant, member, params }) { const isActive = member?.status?.isActive; const rank = claimant?.rank; - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); const { activeSalary = [], passiveSalary = [] } = params ?? {}; const activeRankSalary = getRankSalary(activeSalary, rank); diff --git a/packages/next-common/components/fellowship/salary/claimants/status.jsx b/packages/next-common/components/fellowship/salary/claimants/status.jsx index ea2054739b..72fa22c174 100644 --- a/packages/next-common/components/fellowship/salary/claimants/status.jsx +++ b/packages/next-common/components/fellowship/salary/claimants/status.jsx @@ -1,10 +1,10 @@ import { has } from "lodash-es"; import Tooltip from "next-common/components/tooltip"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import { toPrecision } from "next-common/utils"; export default function FellowshipSalaryMemberStatus({ status }) { - const { decimals, symbol } = getSalaryAsset(); + const { decimals, symbol } = useSalaryAsset(); let content = -; let tooltipContent; diff --git a/packages/next-common/components/fellowship/salary/cycles/history/expenditure.jsx b/packages/next-common/components/fellowship/salary/cycles/history/expenditure.jsx index 2a6a4f94b0..7f2d303e76 100644 --- a/packages/next-common/components/fellowship/salary/cycles/history/expenditure.jsx +++ b/packages/next-common/components/fellowship/salary/cycles/history/expenditure.jsx @@ -1,12 +1,12 @@ import ValueDisplay from "next-common/components/valueDisplay"; import Progress from "next-common/components/progress"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; import { toPercentage, toPrecision } from "next-common/utils"; import Tooltip from "next-common/components/tooltip"; import bigAdd from "next-common/utils/math/bigAdd"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; export default function FellowshipSalaryExpenditure({ cycle = {} }) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(cycle?.indexer?.blockHeight); const { status = {}, registeredPaid, unRegisteredPaid } = cycle || {}; const { budget } = status; diff --git a/packages/next-common/components/fellowship/salary/cycles/history/registerPaid.jsx b/packages/next-common/components/fellowship/salary/cycles/history/registerPaid.jsx index 1e91b48e07..703d5555ca 100644 --- a/packages/next-common/components/fellowship/salary/cycles/history/registerPaid.jsx +++ b/packages/next-common/components/fellowship/salary/cycles/history/registerPaid.jsx @@ -1,10 +1,10 @@ import Tooltip from "next-common/components/tooltip"; import ValueDisplay from "next-common/components/valueDisplay"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; import { toPrecision } from "next-common/utils"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; -function RegisterPaid({ count, paid, type = "" }) { - const { symbol, decimals } = getSalaryAsset(); +function RegisterPaid({ count, paid, type = "", blockHeight }) { + const { symbol, decimals } = useSalaryAsset(blockHeight); return (
@@ -27,6 +27,7 @@ export function FellowshipSalaryRegisteredPaid({ cycle = {} }) { paid={cycle.registeredPaid} count={cycle.registeredPaidCount} type="Registers" + blockHeight={cycle?.indexer?.blockHeight} /> ); } @@ -37,6 +38,7 @@ export function FellowshipSalaryUnregisteredPaid({ cycle = {} }) { paid={cycle.unRegisteredPaid} count={cycle.unRegisteredPaidCount} type="Unregisters" + blockHeight={cycle?.indexer?.blockHeight} /> ); } diff --git a/packages/next-common/components/fellowship/salary/cycles/info/closed.jsx b/packages/next-common/components/fellowship/salary/cycles/info/closed.jsx index 970304a5a4..cd2c12954d 100644 --- a/packages/next-common/components/fellowship/salary/cycles/info/closed.jsx +++ b/packages/next-common/components/fellowship/salary/cycles/info/closed.jsx @@ -29,7 +29,10 @@ export default function FellowshipSalaryCycleDetailInfoClosed({ cycle = {} }) {
- + diff --git a/packages/next-common/components/fellowship/salary/cycles/info/ongoing.jsx b/packages/next-common/components/fellowship/salary/cycles/info/ongoing.jsx index 444fd68489..c83e7deb6a 100644 --- a/packages/next-common/components/fellowship/salary/cycles/info/ongoing.jsx +++ b/packages/next-common/components/fellowship/salary/cycles/info/ongoing.jsx @@ -40,7 +40,10 @@ export default function FellowshipSalaryCycleDetailInfoOngoing({ - + @@ -55,7 +58,10 @@ export default function FellowshipSalaryCycleDetailInfoOngoing({ - +
); } -function PaidLabel({ value, label = "", color = "" }) { - const { decimals, symbol } = getSalaryAsset(); +function PaidLabel({ value, label = "", color = "", blockHeight }) { + const { decimals, symbol } = useSalaryAsset(blockHeight); return (
diff --git a/packages/next-common/components/fellowship/salary/cycles/summary/budgetItem.js b/packages/next-common/components/fellowship/salary/cycles/summary/budgetItem.js index bf82dbee0e..e0b7ba96e0 100644 --- a/packages/next-common/components/fellowship/salary/cycles/summary/budgetItem.js +++ b/packages/next-common/components/fellowship/salary/cycles/summary/budgetItem.js @@ -3,10 +3,10 @@ import LoadableContent from "next-common/components/common/loadableContent"; import { isNil } from "lodash-es"; import ValueDisplay from "next-common/components/valueDisplay"; import { toPrecision } from "next-common/utils"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; -export default function SalaryStatsBudgetItem({ budget }) { - const { decimals, symbol } = getSalaryAsset(); +export default function SalaryStatsBudgetItem({ budget, blockHeight }) { + const { decimals, symbol } = useSalaryAsset(blockHeight); return ( diff --git a/packages/next-common/components/fellowship/salary/cycles/summary/potItem.js b/packages/next-common/components/fellowship/salary/cycles/summary/potItem.js index 3f9901dba7..2b50b719e7 100644 --- a/packages/next-common/components/fellowship/salary/cycles/summary/potItem.js +++ b/packages/next-common/components/fellowship/salary/cycles/summary/potItem.js @@ -1,12 +1,12 @@ -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import SummaryItem from "next-common/components/summary/layout/item"; import LoadableContent from "next-common/components/common/loadableContent"; import { isNil } from "lodash-es"; import ValueDisplay from "next-common/components/valueDisplay"; import { toPrecision } from "next-common/utils"; -export default function SalaryStatsPotItem({ pot }) { - const { decimals, symbol } = getSalaryAsset(); +export default function SalaryStatsPotItem({ pot, blockHeight }) { + const { decimals, symbol } = useSalaryAsset(blockHeight); return ( diff --git a/packages/next-common/components/fellowship/salary/cycles/summary/registrationItem.js b/packages/next-common/components/fellowship/salary/cycles/summary/registrationItem.js index 47016352ff..e32644930d 100644 --- a/packages/next-common/components/fellowship/salary/cycles/summary/registrationItem.js +++ b/packages/next-common/components/fellowship/salary/cycles/summary/registrationItem.js @@ -1,5 +1,5 @@ import SummaryItem from "next-common/components/summary/layout/item"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import { isNil } from "lodash-es"; import LoadableContent from "next-common/components/common/loadableContent"; import ValueDisplay from "next-common/components/valueDisplay"; @@ -10,7 +10,8 @@ export default function SalaryStatsRegistrationItem({ cycleData }) { const stats = useFellowshipSalaryStats(); const { totalRegistrations } = stats || {}; - const { decimals, symbol } = getSalaryAsset(); + const { indexer } = cycleData || {}; + const { decimals, symbol } = useSalaryAsset(indexer?.blockHeight); const { registeredCount } = cycleData || {}; return ( diff --git a/packages/next-common/components/fellowship/salary/cycles/summary/unregisteredItem.js b/packages/next-common/components/fellowship/salary/cycles/summary/unregisteredItem.js index 1cc58add5c..c8231ab663 100644 --- a/packages/next-common/components/fellowship/salary/cycles/summary/unregisteredItem.js +++ b/packages/next-common/components/fellowship/salary/cycles/summary/unregisteredItem.js @@ -3,14 +3,15 @@ import { isNil } from "lodash-es"; import LoadableContent from "next-common/components/common/loadableContent"; import ValueDisplay from "next-common/components/valueDisplay"; import { toPrecision } from "next-common/utils"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import { useFellowshipSalaryStats } from "next-common/hooks/fellowship/salary/useFellowshipSalaryStats"; export default function SalaryStatsUnregisteredItem({ cycleData }) { const stats = useFellowshipSalaryStats(); const { totalUnregisteredPaid } = stats || {}; - const { decimals, symbol } = getSalaryAsset(); + const { indexer } = cycleData || {}; + const { decimals, symbol } = useSalaryAsset(indexer?.blockHeight); const { unRegisteredPaidCount } = cycleData || {}; return ( diff --git a/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/paid.jsx b/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/paid.jsx index 3af04e60ad..a8999f8456 100644 --- a/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/paid.jsx +++ b/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/paid.jsx @@ -1,15 +1,19 @@ import ValueDisplay from "next-common/components/valueDisplay"; import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; import { toPrecision } from "next-common/utils"; +import { useCollectivesSection } from "next-common/context/collectives/collectives"; export function useFellowshipSalaryCyclePaidColumn() { - const { decimals, symbol } = getSalaryAsset(); - + const section = useCollectivesSection(); return { name: "Paid", width: 160, className: "text-right", cellRender(data) { + const { decimals, symbol } = getSalaryAsset( + section, + data?.paidIndexer?.blockHeight, + ); return ( diff --git a/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/yearlySalary.jsx b/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/yearlySalary.jsx index fca4234d1a..9162f20671 100644 --- a/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/yearlySalary.jsx +++ b/packages/next-common/components/fellowship/salary/cycles/tabsList/columns/yearlySalary.jsx @@ -1,14 +1,18 @@ import ValueDisplay from "next-common/components/valueDisplay"; import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; import { toPrecision } from "next-common/utils"; +import { useCollectivesSection } from "next-common/context/collectives/collectives"; export function useFellowshipSalaryCycleYearlySalaryColumn() { - const { decimals, symbol } = getSalaryAsset(); - + const section = useCollectivesSection(); return { name: "Salary", width: 160, cellRender(data) { + const { decimals, symbol } = getSalaryAsset( + section, + data?.paidIndexer?.blockHeight ?? data?.indexer?.blockHeight, + ); return ( ), CycleStarted: , diff --git a/packages/next-common/components/fellowship/salary/feeds/events/paid.js b/packages/next-common/components/fellowship/salary/feeds/events/paid.js index 1241472efa..797d69642c 100644 --- a/packages/next-common/components/fellowship/salary/feeds/events/paid.js +++ b/packages/next-common/components/fellowship/salary/feeds/events/paid.js @@ -2,14 +2,14 @@ import AddressUser from "next-common/components/user/addressUser"; import { FellowshipFeedEventLabel } from "next-common/components/fellowship/feeds/label"; import ValueDisplay from "next-common/components/valueDisplay"; import { toPrecision } from "next-common/utils"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; export default function FellowshipSalaryPaidFeed({ feed = {}, showUserInfo = true, }) { const { args: { who, amount } = {} } = feed || {}; - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(feed?.indexer?.blockHeight); return ( <> diff --git a/packages/next-common/components/fellowship/salary/feeds/events/registered.js b/packages/next-common/components/fellowship/salary/feeds/events/registered.js index 6f60e23998..8033860c0b 100644 --- a/packages/next-common/components/fellowship/salary/feeds/events/registered.js +++ b/packages/next-common/components/fellowship/salary/feeds/events/registered.js @@ -1,14 +1,18 @@ import AddressUser from "next-common/components/user/addressUser"; import { FellowshipFeedEventLabel } from "next-common/components/fellowship/feeds/label"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; import ValueDisplay from "next-common/components/valueDisplay"; import { toPrecision } from "next-common/utils"; import Link from "next-common/components/link"; -import { useCollectivesContext } from "next-common/context/collectives/collectives"; +import { useCollectivesSection } from "next-common/context/collectives/collectives"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; -export function FellowshipRegisteredFeedContent({ amount, index }) { - const { symbol, decimals } = getSalaryAsset(); - const { section } = useCollectivesContext(); +export function FellowshipRegisteredFeedContent({ + amount, + index, + blockHeight, +}) { + const section = useCollectivesSection(); + const { symbol, decimals } = useSalaryAsset(blockHeight); return ( <> @@ -32,12 +36,17 @@ export default function FellowshipRegisteredFeed({ amount, index, showUserInfo = true, + blockHeight, }) { return ( <> {showUserInfo && } - + ); diff --git a/packages/next-common/components/fellowship/statistics/common.js b/packages/next-common/components/fellowship/statistics/common.js index e7fbb9d085..edae0b2071 100644 --- a/packages/next-common/components/fellowship/statistics/common.js +++ b/packages/next-common/components/fellowship/statistics/common.js @@ -1,7 +1,6 @@ import { useTheme } from "styled-components"; import deepmerge from "deepmerge"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; -import { toPrecision, formatNum } from "next-common/utils"; +import { abbreviateBigNumber } from "next-common/utils"; import Loading from "next-common/components/loading"; export const expenditureDoughnutChartOptions = { @@ -12,7 +11,7 @@ export const expenditureDoughnutChartOptions = { const name = item.dataset.name[item.dataIndex]; const percentage = item.dataset.percentage[item.dataIndex]; const count = item.dataset.data[item.dataIndex]; - return `${name}: ${getAbbreviateBigNumber(count)} (${percentage})`; + return `${name}: $${abbreviateBigNumber(count, 2)} (${percentage})`; }, }, }, @@ -72,14 +71,6 @@ export const doughnutChartColors = [ "#E684B8", ]; -export function getAbbreviateBigNumber(count, showSymbol = true) { - const { symbol, decimals } = getSalaryAsset(); - const precisionCount = toPrecision(count, decimals); - return showSymbol - ? `${formatNum(precisionCount)} ${symbol}` - : formatNum(precisionCount); -} - export function useBarChartOptions(userOptions) { const theme = useTheme(); /** @@ -136,7 +127,7 @@ export function useBarChartOptions(userOptions) { }, ticks: { callback: function (value) { - return getAbbreviateBigNumber(value, false); + return abbreviateBigNumber(value, 2); }, font: { size: 12, diff --git a/packages/next-common/components/fellowship/statistics/expenditure/claimants/columns/paid.jsx b/packages/next-common/components/fellowship/statistics/expenditure/claimants/columns/paid.jsx index c1326e1e4e..5072672510 100644 --- a/packages/next-common/components/fellowship/statistics/expenditure/claimants/columns/paid.jsx +++ b/packages/next-common/components/fellowship/statistics/expenditure/claimants/columns/paid.jsx @@ -1,22 +1,12 @@ -import ValueDisplay from "next-common/components/valueDisplay"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; -import { toPrecision } from "next-common/utils"; +import SalaryAssetValues from "next-common/components/collectives/salaryAssetValues"; export function useStatisticsClaimantsPaidColumn() { - const { decimals, symbol } = getSalaryAsset(); - return { name: "Total Paid", - width: 160, + width: 240, className: "text-right", cellRender(data, idx) { - return ( - - ); + return ; }, }; } diff --git a/packages/next-common/components/fellowship/statistics/expenditure/cycles/cyclesChart.jsx b/packages/next-common/components/fellowship/statistics/expenditure/cycles/cyclesChart.jsx index 5dea067162..f748416dd3 100644 --- a/packages/next-common/components/fellowship/statistics/expenditure/cycles/cyclesChart.jsx +++ b/packages/next-common/components/fellowship/statistics/expenditure/cycles/cyclesChart.jsx @@ -2,7 +2,13 @@ import React from "react"; import BarChart from "./barChart"; import { startCase } from "lodash-es"; import BigNumber from "bignumber.js"; -import { getAbbreviateBigNumber } from "next-common/components/fellowship/statistics/common.js"; +import { abbreviateBigNumber } from "next-common/utils"; +import { normalizeSalaryAssetValue } from "next-common/components/collectives/salaryAssetValues"; + +function getCycleTotal(value) { + const v = normalizeSalaryAssetValue(value); + return new BigNumber(v.usdt || 0).plus(v.hollar || 0).toNumber(); +} function getTooltipTitle(item) { const tooltipItem = item[0]; @@ -18,18 +24,39 @@ function getTooltipLabel(item, currentDataset) { registeredPaid, unRegisteredPaid, } = currentDataset; - const totalPaid = getAbbreviateBigNumber( - new BigNumber(registeredPaid).plus(unRegisteredPaid), + + const registeredTotal = normalizeSalaryAssetValue(registeredPaid); + const unRegisteredTotal = normalizeSalaryAssetValue(unRegisteredPaid); + const totalUsdt = new BigNumber(registeredTotal.usdt || 0).plus( + unRegisteredTotal.usdt || 0, + ); + const totalHollar = new BigNumber(registeredTotal.hollar || 0).plus( + unRegisteredTotal.hollar || 0, ); + const totalPaid = totalUsdt.plus(totalHollar).toNumber(); + + const abbreviatedPaid = (value) => { + if (value >= 1000) { + return abbreviateBigNumber(value, 2); + } + return value.toFixed(2); + }; + if (datasetIndex === 0) { + const registeredTotalNum = new BigNumber(registeredTotal.usdt || 0) + .plus(registeredTotal.hollar || 0) + .toNumber(); return [ - `Total: ${totalPaid}`, - `${dataset.label}: ${getAbbreviateBigNumber(registeredPaid)}`, + `Total: $${abbreviatedPaid(totalPaid)}`, + `${dataset.label}: $${abbreviatedPaid(registeredTotalNum)}`, ]; } if (datasetIndex === 1) { + const unRegisteredTotalNum = new BigNumber(unRegisteredTotal.usdt || 0) + .plus(unRegisteredTotal.hollar || 0) + .toNumber(); return [ - `${dataset.label}: ${getAbbreviateBigNumber(unRegisteredPaid)}`, + `${dataset.label}: $${abbreviatedPaid(unRegisteredTotalNum)}`, `Registered Paid Count: ${registeredPaidCount}`, `Unregistered Paid Count: ${unRegisteredPaidCount}`, ]; @@ -47,7 +74,7 @@ export default function CyclesChart({ values }) { categoryPercentage, barPercentage, label: "Registered Paid", - data: values.map((value) => value.registeredPaid), + data: values.map((value) => getCycleTotal(value.registeredPaid)), backgroundColor: "rgba(230, 0, 122, 1)", tooltip: true, }, @@ -55,7 +82,7 @@ export default function CyclesChart({ values }) { categoryPercentage, barPercentage, label: "Unregistered Paid", - data: values.map((value) => value.unRegisteredPaid), + data: values.map((value) => getCycleTotal(value.unRegisteredPaid)), backgroundColor: "rgba(230, 0, 122, 0.4)", tooltip: true, }, diff --git a/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/index.jsx b/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/index.jsx index 0ce28c67ea..67dfbe10d2 100644 --- a/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/index.jsx +++ b/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/index.jsx @@ -12,39 +12,69 @@ import { getUniqueRanks, useDoughnutChartOptions, } from "next-common/components/fellowship/statistics/common.js"; +import { normalizeSalaryAssetValue } from "next-common/components/collectives/salaryAssetValues"; import DoughnutChartLabels from "./labels"; import { useNavCollapsed } from "next-common/context/nav"; function getTotalSalary(ranksData) { return ranksData.reduce((acc, item) => { - return acc.plus(new BigNumber(item.salary)); + const s = normalizeSalaryAssetValue(item.salary); + const usdt = new BigNumber(s.usdt || 0); + const hollar = new BigNumber(s.hollar || 0); + return acc.plus(usdt).plus(hollar); }, new BigNumber(0)); } function transformRanksDataToObject(ranksData) { return ranksData.reduce((acc, item) => { - acc[item.rank] = new BigNumber(item.salary); + const s = normalizeSalaryAssetValue(item.salary); + const usdt = new BigNumber(s.usdt || 0); + const hollar = new BigNumber(s.hollar || 0); + acc[item.rank] = usdt.plus(hollar); + acc[`${item.rank}_usdt`] = usdt; + acc[`${item.rank}_hollar`] = hollar; return acc; }, {}); } +function getRankArr(members, ranksData) { + const memberRanks = getUniqueRanks(members || []); + if (memberRanks.length > 0) { + return memberRanks; + } + + return ranksData + .map((item) => item.rank) + .filter((rank) => rank !== undefined && rank !== null) + .sort((a, b) => a - b); +} + function handleLabelDataArr(members, ranksData) { - const rankArr = getUniqueRanks(members); + const rankArr = getRankArr(members, ranksData); const totalSalary = getTotalSalary(ranksData); const ranksDataObj = transformRanksDataToObject(ranksData); - const dataArr = rankArr.map((rank, index) => { - const count = ranksDataObj[rank] || 0; - const percent = ranksDataObj[rank] - ? new BigNumber(ranksDataObj[rank]).div(totalSalary) - : ""; - return { - label: `Rank ${rank}`, - bgColor: colors[index], - count, - percent, - }; - }); - return dataArr.reverse(); + return rankArr + .map((rank, index) => { + const totalAmount = ranksDataObj[rank] || new BigNumber(0); + const usdtAmount = ranksDataObj[`${rank}_usdt`] || new BigNumber(0); + const hollarAmount = ranksDataObj[`${rank}_hollar`] || new BigNumber(0); + const percent = + totalSalary.gt(0) && totalAmount.gt(0) + ? totalAmount.div(totalSalary) + : ""; + return { + label: `Rank ${rank}`, + bgColor: colors[index], + salary: { + usdt: usdtAmount.toString(), + hollar: hollarAmount.toString(), + total: totalAmount.toNumber(), + }, + percent, + }; + }) + .filter((item) => item.salary.total > 0) + .reverse(); } function RankChart({ labelDataArr, data }) { @@ -63,7 +93,7 @@ function RankChart({ labelDataArr, data }) {
@@ -102,13 +132,13 @@ export default function RankDoughnutChart({ members = [] }) { labels: labelDataArr.map((i) => i.label), datasets: [ { - data: labelDataArr.map((item) => item.count), + data: labelDataArr.map((item) => item.salary.total), backgroundColor: labelDataArr.map((item) => item.bgColor), borderColor: labelDataArr.map((item) => item.bgColor), borderWidth: 0, name: labelDataArr.map((i) => i.label), - percentage: labelDataArr.map( - (item) => `${(item.percent * 100).toFixed(2)}%`, + percentage: labelDataArr.map((item) => + item.percent ? `${item.percent.times(100).toFixed(2)}%` : "0%", ), }, ], diff --git a/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/labels.jsx b/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/labels.jsx index 2d1c34259c..74cbc28755 100644 --- a/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/labels.jsx +++ b/packages/next-common/components/fellowship/statistics/expenditure/rank/doughnutChart/labels.jsx @@ -1,27 +1,49 @@ import { cn } from "next-common/utils"; -import ValueDisplay from "next-common/components/valueDisplay"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; -import { toPrecision } from "next-common/utils"; import { getPercentageValue } from "next-common/components/fellowship/statistics/common"; +import { normalizeSalaryAssetValue } from "next-common/components/collectives/salaryAssetValues"; +import ValueDisplay from "next-common/components/valueDisplay"; +import Tooltip from "next-common/components/tooltip"; +import BigNumber from "bignumber.js"; -function getSalaryValue(count, decimals, symbol) { - return count ? ( - - ) : ( - `0 ${symbol}` - ); +function tooltipContent(salary) { + const value = normalizeSalaryAssetValue(salary); + const parts = []; + if (new BigNumber(value.usdt || 0).gt(0)) { + parts.push( +
+ +
, + ); + } + if (new BigNumber(value.hollar || 0).gt(0)) { + parts.push( +
+ +
, + ); + } + return parts.length > 0 ? parts : null; } -function RowItem({ bgColor, label, percentage, count }) { +function RowItem({ bgColor, label, percentage, salary }) { return (
- {label} - {count} - + {label} + + + + {percentage}
@@ -29,18 +51,15 @@ function RowItem({ bgColor, label, percentage, count }) { } export default function DoughnutChartLabels({ labelDataArr }) { - const { symbol, decimals } = getSalaryAsset(); return ( -
+
{labelDataArr.map((i) => ( ))}
diff --git a/packages/next-common/components/fellowship/statistics/expenditure/summary/index.jsx b/packages/next-common/components/fellowship/statistics/expenditure/summary/index.jsx index df5efa097f..98f820fdb1 100644 --- a/packages/next-common/components/fellowship/statistics/expenditure/summary/index.jsx +++ b/packages/next-common/components/fellowship/statistics/expenditure/summary/index.jsx @@ -3,34 +3,69 @@ import SummaryItem from "next-common/components/summary/layout/item"; import SummaryLayout from "next-common/components/summary/layout/layout"; import BigNumber from "bignumber.js"; import ValueDisplay from "next-common/components/valueDisplay"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; -import { toPrecision } from "next-common/utils"; +import Tooltip from "next-common/components/tooltip"; +import { normalizeSalaryAssetValue } from "next-common/components/collectives/salaryAssetValues"; function getTotalSpent(data) { if (data && data.length > 0) { - const totalSpent = data.reduce((total, item) => { - const registeredPaid = new BigNumber(item.registeredPaid); - const unRegisteredPaid = new BigNumber(item.unRegisteredPaid); - return total.plus(registeredPaid).plus(unRegisteredPaid); - }, new BigNumber(0)); - return totalSpent; + let totalUsdt = new BigNumber(0); + let totalHollar = new BigNumber(0); + + data.forEach((item) => { + const registered = normalizeSalaryAssetValue(item.registeredPaid); + const unRegistered = normalizeSalaryAssetValue(item.unRegisteredPaid); + totalUsdt = totalUsdt + .plus(registered.usdt || 0) + .plus(unRegistered.usdt || 0); + totalHollar = totalHollar + .plus(registered.hollar || 0) + .plus(unRegistered.hollar || 0); + }); + + return { + usdt: totalUsdt.toString(), + hollar: totalHollar.toString(), + total: totalUsdt.plus(totalHollar), + }; } - return new BigNumber(0); + return { usdt: "0", hollar: "0", total: new BigNumber(0) }; } function SpentCycles({ count }) { return {count}; } +function tooltipContent(salary) { + const value = normalizeSalaryAssetValue(salary); + const parts = []; + if (new BigNumber(value.usdt || 0).gt(0)) { + parts.push( +
+ +
, + ); + } + if (new BigNumber(value.hollar || 0).gt(0)) { + parts.push( +
+ +
, + ); + } + return parts.length > 0 ? parts : null; +} + function TotalSpent({ cycles }) { - const totalSpent = getTotalSpent(cycles); - const { symbol, decimals } = getSalaryAsset(); + const { total, usdt, hollar } = getTotalSpent(cycles); return ( - + + + ); } diff --git a/packages/next-common/components/fellowship/statistics/membership/summary/summaryItems.jsx b/packages/next-common/components/fellowship/statistics/membership/summary/summaryItems.jsx index 100e653000..737b4529c2 100644 --- a/packages/next-common/components/fellowship/statistics/membership/summary/summaryItems.jsx +++ b/packages/next-common/components/fellowship/statistics/membership/summary/summaryItems.jsx @@ -1,11 +1,11 @@ import SummaryItem from "next-common/components/summary/layout/item"; import SummaryLayout from "next-common/components/summary/layout/layout"; import ValueDisplay from "next-common/components/valueDisplay"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import { toPrecision } from "next-common/utils"; export default function StatisticsMembershipSummaryItems({ summaryData }) { - const { decimals, symbol } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); if (!summaryData) { return null; } diff --git a/packages/next-common/components/overview/fellowship/salary/stats/index.js b/packages/next-common/components/overview/fellowship/salary/stats/index.js index 825762d5b7..4000858990 100644 --- a/packages/next-common/components/overview/fellowship/salary/stats/index.js +++ b/packages/next-common/components/overview/fellowship/salary/stats/index.js @@ -51,8 +51,14 @@ export default function FellowshipSalaryStats() { className={cn(navCollapsed ? "max-sm:hidden" : "max-md:hidden")} > - - + + @@ -62,8 +68,14 @@ export default function FellowshipSalaryStats() { - - + + diff --git a/packages/next-common/components/pages/fellowship/member/fellowshipMember/salary.js b/packages/next-common/components/pages/fellowship/member/fellowshipMember/salary.js index 6029ad4a1e..e1a1da8ab7 100644 --- a/packages/next-common/components/pages/fellowship/member/fellowshipMember/salary.js +++ b/packages/next-common/components/pages/fellowship/member/fellowshipMember/salary.js @@ -4,7 +4,8 @@ import ValueDisplay from "next-common/components/valueDisplay"; import { usePageProps } from "next-common/context/page"; import useSubCollectiveRank from "next-common/hooks/collectives/useSubCollectiveRank"; import { isSameAddress, toPrecision } from "next-common/utils"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; +import SalaryAssetValues from "next-common/components/collectives/salaryAssetValues"; import { getRankSalary } from "next-common/utils/fellowship/getRankSalary"; import { BorderedRow, @@ -22,7 +23,7 @@ import useSubCoreCollectivesMember from "next-common/hooks/collectives/useSubCor function Wrapper({ children }) { return ( -
+
{children}
); @@ -48,7 +49,7 @@ function ActionsWrapper({ children, className = "" }) { function NotImportedSalary() { return ( -
+
Salary -
@@ -72,7 +73,7 @@ export function LastPayment() { } function SalaryValue({ salary }) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = useSalaryAsset(); return ( @@ -81,15 +82,14 @@ function SalaryValue({ salary }) { } function TotalPaid({ totalPaid }) { - const { decimals } = getSalaryAsset(); return (
- + Total Paid
- +
); @@ -99,7 +99,7 @@ function JoinedCycles({ joinedCycles }) { return (
- + Joined Cycles
{joinedCycles} @@ -133,13 +133,13 @@ function MemberSalary({ address }) { return ( -
+
Salary
diff --git a/packages/next-common/components/pages/secretary/members.js b/packages/next-common/components/pages/secretary/members.js index b3f58b9c85..0415d347a6 100644 --- a/packages/next-common/components/pages/secretary/members.js +++ b/packages/next-common/components/pages/secretary/members.js @@ -32,7 +32,7 @@ const columns = [ ]; function SalaryCell({ rank }) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = getSalaryAsset("secretary"); const salary = getSecretaryMemberSalary(rank); return ; } diff --git a/packages/next-common/components/profile/fellowship/memberInfo.jsx b/packages/next-common/components/profile/fellowship/memberInfo.jsx index 6257045efe..084807af32 100644 --- a/packages/next-common/components/profile/fellowship/memberInfo.jsx +++ b/packages/next-common/components/profile/fellowship/memberInfo.jsx @@ -8,7 +8,7 @@ import SummaryLayout from "next-common/components/summary/layout/layout"; import ValueDisplay from "next-common/components/valueDisplay"; import { usePageProps } from "next-common/context/page"; import useFellowshipCoreMembersWithRank from "next-common/hooks/fellowship/core/useFellowshipCoreMembersWithRank"; -import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; +import { useSalaryAsset } from "next-common/hooks/fellowship/salary/useSalaryAsset"; import { backendApi } from "next-common/services/nextApi"; import { ambassadorParamsApi, @@ -132,7 +132,7 @@ function ProfileFellowshipMemberInfoPanel({ member, paramsApi }) { function MemberSalaryItem({ params, isActive, rank, loading }) { const { activeSalary, passiveSalary } = params; - const { decimals, symbol } = getSalaryAsset(); + const { decimals, symbol } = useSalaryAsset(); const salaryTable = isActive ? activeSalary : passiveSalary; const salary = getRankSalary(salaryTable, rank); diff --git a/packages/next-common/components/profile/fellowship/salary/payments/columns/paid.jsx b/packages/next-common/components/profile/fellowship/salary/payments/columns/paid.jsx index 70026969ca..71894fab55 100644 --- a/packages/next-common/components/profile/fellowship/salary/payments/columns/paid.jsx +++ b/packages/next-common/components/profile/fellowship/salary/payments/columns/paid.jsx @@ -1,15 +1,20 @@ import ValueDisplay from "next-common/components/valueDisplay"; import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; import { toPrecision } from "next-common/utils"; +import { useCollectivesSection } from "next-common/context/collectives/collectives"; export function useProfileFellowshipSalaryPaymentPaidColumn(props = {}) { - const { decimals, symbol } = getSalaryAsset(); + const section = useCollectivesSection(); return { name: "Paid", width: 160, className: "text-right", cellRender(data, idx) { + const { decimals, symbol } = getSalaryAsset( + section, + data?.paidIndexer?.blockHeight, + ); return ( - + diff --git a/packages/next-common/components/secretary/salary/claimants/list.jsx b/packages/next-common/components/secretary/salary/claimants/list.jsx index b067e5d1b6..1fbec0149f 100644 --- a/packages/next-common/components/secretary/salary/claimants/list.jsx +++ b/packages/next-common/components/secretary/salary/claimants/list.jsx @@ -28,7 +28,7 @@ function getClaimantAmount(claimant) { } function ClaimantAmountCell({ claimant }) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = getSalaryAsset("secretary"); const amount = getClaimantAmount(claimant); if (isNil(amount)) { @@ -39,7 +39,7 @@ function ClaimantAmountCell({ claimant }) { } function ClaimantSalaryCell({ rank }) { - const { symbol, decimals } = getSalaryAsset(); + const { symbol, decimals } = getSalaryAsset("secretary"); const salary = getSecretaryMemberSalary(rank); if (!salary) { return -; diff --git a/packages/next-common/components/secretary/statistics/claimants/index.jsx b/packages/next-common/components/secretary/statistics/claimants/index.jsx index 8dc0a530b4..0a221ae890 100644 --- a/packages/next-common/components/secretary/statistics/claimants/index.jsx +++ b/packages/next-common/components/secretary/statistics/claimants/index.jsx @@ -19,9 +19,11 @@ import { getReferendaTotalByAddress, getReferendaUsdByAddress, } from "next-common/components/secretary/statistics/breakdown"; -import ValueDisplay from "next-common/components/valueDisplay"; +import SalaryAssetValues, { + isPositiveAmount, +} from "next-common/components/collectives/salaryAssetValues"; import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; -import { formatNum, toPrecision } from "next-common/utils"; +import { formatNum } from "next-common/utils"; function handleClaimantsData(originalMembers, members) { const membersRank = members.reduce((acc, member) => { @@ -78,43 +80,58 @@ function useSecretaryClaimantsReferendaColumn(paymentReferenda) { } function useSecretaryClaimantsPaidColumn(paymentReferenda) { - const { decimals, symbol } = getSalaryAsset(); + const { decimals } = getSalaryAsset("secretary"); return { name: "Total Paid", className: "text-right", + width: 240, cellRender(data, idx) { - const salary = BigInt(data.salary || 0); + const salary = data.salary || {}; + const usdt = salary.usdt || "0"; + const hollar = salary.hollar || "0"; const address = data.who; const referendaTotal = getReferendaTotalByAddress( paymentReferenda, address, ); + const hasHollar = isPositiveAmount(hollar); + const hasUsdt = isPositiveAmount(usdt); + if (referendaTotal.isZero()) { - return ( - - ); + return ; } const referendaUsd = getReferendaUsdByAddress(paymentReferenda, address); - const cyclesUsd = new BigNumber(salary.toString()).div( - Math.pow(10, decimals), - ); - const usdTotal = cyclesUsd.plus(referendaUsd).toFixed(2); + const salaryUsd = new BigNumber(usdt).plus(hollar); + const usdTotal = salaryUsd.plus(referendaUsd).toFixed(2); + + const rows = []; + + if (hasUsdt) { + rows.push({ + value: new BigNumber(usdt).shiftedBy(decimals).toFixed(0), + decimals, + symbol: "USDT", + }); + } + + if (hasHollar) { + rows.push({ + value: new BigNumber(hollar).shiftedBy(18).toFixed(0), + decimals: 18, + symbol: "HOLLAR", + }); + } - const rows = [ - { value: salary.toString(), decimals, symbol }, - { + if (referendaTotal.gt(0)) { + rows.push({ value: referendaTotal.toString(), decimals: 10, symbol: "DOT", - }, - ]; + }); + } return ( ); - tooltipContent = `${bigValue.toFixed()}${ - symbol ? " " + symbol : "" - } ${tooltipOtherContent}`; + tooltipContent = `${bigValue.toFixed()}${symbol ? " " + symbol : ""} ${ + tooltipOtherContent || "" + }`; } else if ( Number(value) >= 100000 || getEffectiveNumbers(value)?.length >= 11 diff --git a/packages/next-common/hooks/fellowship/core/useSubFellowshipCoreMember.js b/packages/next-common/hooks/fellowship/core/useSubFellowshipCoreMember.js index 57caec40f7..148e125318 100644 --- a/packages/next-common/hooks/fellowship/core/useSubFellowshipCoreMember.js +++ b/packages/next-common/hooks/fellowship/core/useSubFellowshipCoreMember.js @@ -1,4 +1,4 @@ -import { useCallback, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import useSubStorage from "next-common/hooks/common/useSubStorage"; export default function useSubFellowshipCoreMember( @@ -6,13 +6,25 @@ export default function useSubFellowshipCoreMember( pallet = "fellowshipCore", ) { const [member, setMember] = useState(null); - const { loading } = useSubStorage(pallet, "member", [address], { - callback: useCallback((rawOptional) => { - if (rawOptional.isSome) { - setMember(rawOptional.unwrap().toJSON()); - } - }, []), - }); + useEffect(() => { + if (!address) { + setMember(null); + } + }, [address]); + + const { loading } = useSubStorage( + pallet, + "member", + address ? [address] : [], + { + callback: useCallback((rawOptional) => { + if (rawOptional.isSome) { + setMember(rawOptional.unwrap().toJSON()); + } + }, []), + skip: !address, + }, + ); return { isLoading: loading, member }; } diff --git a/packages/next-common/hooks/fellowship/salary/useSalaryAsset.js b/packages/next-common/hooks/fellowship/salary/useSalaryAsset.js new file mode 100644 index 0000000000..cf6d40380f --- /dev/null +++ b/packages/next-common/hooks/fellowship/salary/useSalaryAsset.js @@ -0,0 +1,24 @@ +import { useCollectivesSection } from "next-common/context/collectives/collectives"; +import useChainOrScanHeight from "next-common/hooks/height"; +import { getSalaryAsset } from "next-common/utils/consts/getSalaryAsset"; + +/** + * React hook that returns the salary asset info. + * Automatically reads the current section from CollectivesContext. + * If blockHeight is not provided, uses the current chain/scan height. + * + * @param {number} [blockHeight] - Optional block height to determine asset switching + * @returns {{ symbol: string, decimals: number }} + * + * Usage: + * // With explicit blockHeight (from API data) + * const { symbol, decimals } = useSalaryAsset(data.paidIndexer?.blockHeight); + * + * // Without blockHeight (uses current chain height for live data) + * const { symbol, decimals } = useSalaryAsset(); + */ +export function useSalaryAsset(blockHeight) { + const section = useCollectivesSection(); + const height = useChainOrScanHeight(); + return getSalaryAsset(section, blockHeight ?? height); +} diff --git a/packages/next-common/utils/consts/getSalaryAsset.js b/packages/next-common/utils/consts/getSalaryAsset.js index 2d5c23c2a1..a10240680e 100644 --- a/packages/next-common/utils/consts/getSalaryAsset.js +++ b/packages/next-common/utils/consts/getSalaryAsset.js @@ -1,6 +1,26 @@ -export function getSalaryAsset() { - return { - decimals: 6, - symbol: "USDT", - }; +// Asset switch points per section. +// Each section has its own independent switch timeline. + +import { isNil } from "lodash-es"; + +// Proposal #568: Fellowship switches from USDT(6) to HOLLAR(18) at block 9,247,655. +const SWITCH_POINTS = { + fellowship: [{ blockHeight: 9247655, symbol: "HOLLAR", decimals: 18 }], + ambassador: [], + secretary: [], +}; + +/** + * Get the salary asset info based on section and optional block height. + * @param {string} section - "fellowship" | "ambassador" | "secretary" + * @param {number} [blockHeight] - Optional block height to determine asset switching + * @returns {{ symbol: string, decimals: number }} + */ +export function getSalaryAsset(section = "fellowship", blockHeight) { + const switches = SWITCH_POINTS[section] || []; + const active = [...switches] + .reverse() + .find((s) => !isNil(blockHeight) && blockHeight >= s.blockHeight); + if (active) return { symbol: active.symbol, decimals: active.decimals }; + return { symbol: "USDT", decimals: 6 }; }