Skip to content

Commit 6289f04

Browse files
chore: update Namadillo to work with new 4.0.3 indexer client (#2296)
Co-authored-by: Mateusz Jasiuk <[email protected]>
1 parent 42c8227 commit 6289f04

File tree

22 files changed

+294
-186
lines changed

22 files changed

+294
-186
lines changed

apps/namadillo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@cosmjs/encoding": "^0.32.3",
1212
"@keplr-wallet/types": "^0.12.136",
1313
"@namada/chain-registry": "^1.3.0",
14-
"@namada/indexer-client": "3.3.2",
14+
"@namada/indexer-client": "4.0.3",
1515
"@namada/sdk-multicore": "^0.20.8",
1616
"@tailwindcss/container-queries": "^0.1.1",
1717
"@tanstack/query-core": "^5.40.0",

apps/namadillo/src/App/Common/GasFeeModal.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { TokenCurrency } from "./TokenCurrency";
2525
const useSortByNativeToken = () => {
2626
const nativeToken = useAtomValue(nativeTokenAddressAtom).data;
2727
return (a: GasPriceTableItem, b: GasPriceTableItem) =>
28-
a.token === nativeToken ? -1
29-
: b.token === nativeToken ? 1
28+
a.token.address === nativeToken ? -1
29+
: b.token.address === nativeToken ? 1
3030
: 0;
3131
};
3232

@@ -41,7 +41,7 @@ const useBuildGasOption = ({
4141
}) => {
4242
const gasDollarMap =
4343
useAtomValue(
44-
tokenPricesFamily(gasPriceTable?.map((item) => item.token) ?? [])
44+
tokenPricesFamily(gasPriceTable?.map((item) => item.token.address) ?? [])
4545
).data ?? {};
4646

4747
return (
@@ -126,19 +126,19 @@ export const GasFeeModal = ({
126126
isShielded ?
127127
shieldedAmount.data?.map((balance) => ({
128128
minDenomAmount: balance.minDenomAmount,
129-
tokenAddress: balance.address,
129+
token: balance.address,
130130
}))
131131
: transparentAmount.data;
132132

133133
return new BigNumber(
134-
balances?.find((token) => token.tokenAddress === tokenAddres)
135-
?.minDenomAmount || "0"
134+
balances?.find((token) => token.token === tokenAddres)?.minDenomAmount ||
135+
"0"
136136
);
137137
};
138138

139139
const filterAvailableTokensOnly = (item: GasPriceTableItem): boolean => {
140-
if (item.token === nativeToken) return true; // we should always keep the native token
141-
return findUserBalanceByTokenAddress(item.token).gt(0);
140+
if (item.token.address === nativeToken) return true; // we should always keep the native token
141+
return findUserBalanceByTokenAddress(item.token.address).gt(0);
142142
};
143143

144144
const isLoading = isShielded && !shieldedAmount.data;
@@ -252,25 +252,25 @@ export const GasFeeModal = ({
252252
totalInDollars,
253253
unitValueInDollars,
254254
} = buildGasOption({
255-
gasPriceInMinDenom: item.gasPrice,
256-
gasToken: item.token,
255+
gasPriceInMinDenom: item.gasPriceInMinDenom,
256+
gasToken: item.token.address,
257257
});
258258

259259
const availableAmount = toDisplayAmount(
260260
asset,
261-
findUserBalanceByTokenAddress(item.token)
261+
findUserBalanceByTokenAddress(item.token.address)
262262
);
263263

264264
return {
265-
id: item.token,
265+
id: item.token.address,
266266
value: (
267267
<div
268268
className={clsx(
269269
"grid grid-cols-[1.5fr_1fr_1fr] items-center gap-4",
270270
"justify-between w-full min-h-[42px] mr-5"
271271
)}
272272
>
273-
<TokenCard address={item.token} asset={asset} />
273+
<TokenCard address={item.token.address} asset={asset} />
274274
<div>
275275
<div className="text-white text-sm text-right">
276276
{unitValueInDollars && (

apps/namadillo/src/App/Governance/GovernanceOverview.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ export const GovernanceOverview: React.FC = () => {
2929
const activeAtoms = [allProposals, ...extensionAtoms];
3030

3131
const liveProposals =
32-
allProposals.data?.filter((proposal) => proposal.status === "ongoing") ||
33-
[];
32+
allProposals.data?.proposals?.filter(
33+
(proposal) => proposal.status === "ongoing"
34+
) || [];
3435

3536
const upcomingProposals =
36-
allProposals.data?.filter((proposal) => proposal.status === "pending") ||
37-
[];
37+
allProposals.data?.proposals?.filter(
38+
(proposal) => proposal.status === "pending"
39+
) || [];
3840

3941
useNotifyOnAtomError(activeAtoms, [
4042
allProposals.isError,
@@ -86,7 +88,9 @@ export const GovernanceOverview: React.FC = () => {
8688
<SkeletonLoading height="150px" width="100%" />
8789
)}
8890
{atomsAreLoaded(allProposals) && (
89-
<ProposalsSummary allProposals={allProposals.data!} />
91+
<ProposalsSummary
92+
allProposals={allProposals.data?.proposals || []}
93+
/>
9094
)}
9195
</Panel>
9296
<LearnAboutGovernance />

apps/namadillo/src/App/Governance/ProposalHeader.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import {
44
ProgressBar as ProgressBarComponent,
55
Stack,
66
} from "@namada/components";
7-
import { Proposal, UnknownVoteType, VoteType } from "@namada/types";
7+
import {
8+
EncodedProposalData,
9+
Proposal,
10+
UnknownVoteType,
11+
VoteType,
12+
} from "@namada/types";
813
import { routes } from "App/routes";
914
import {
1015
canVoteAtom,
@@ -142,14 +147,13 @@ const JsonButton: React.FC<{
142147

143148
const WasmButton: React.FC<{
144149
proposal: AtomWithQueryResult<Proposal>;
145-
proposalData: AtomWithQueryResult<string>;
150+
proposalData: AtomWithQueryResult<EncodedProposalData>;
146151
}> = ({ proposal, proposalData }) => {
147152
const { disabled, href, filename } = (() => {
148153
if (proposal.status === "success" && proposalData.status === "success") {
149-
const { proposalType } = proposal.data;
150154
const wasmCode =
151-
proposalType.type === "default_with_wasm" ?
152-
fromHex(proposalData.data)
155+
proposalData.data.type === "default_with_wasm" ?
156+
fromHex(proposalData.data.data!)
153157
: undefined;
154158

155159
if (typeof wasmCode !== "undefined") {

apps/namadillo/src/App/Governance/ProposalLabels.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ export const TypeLabel: React.FC<
7575
} & React.ComponentProps<typeof InsetLabel>
7676
> = ({ proposalType, ...rest }) => (
7777
<InsetLabel className="text-xs leading-[1.65em]" {...rest}>
78-
{proposalTypeStringToString(proposalType.type)}
78+
{proposalTypeStringToString(proposalType)}
7979
</InsetLabel>
8080
);

apps/namadillo/src/App/Governance/ViewJson.tsx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { useAtomValue } from "jotai";
22
import { generatePath, useNavigate } from "react-router-dom";
33

44
import { Modal } from "@namada/components";
5-
import { PgfIbcTarget, PgfTarget, Proposal } from "@namada/types";
5+
import {
6+
PgfIbcTarget,
7+
PgfTarget,
8+
ProposalData,
9+
ProposalWithData,
10+
} from "@namada/types";
611
import { assertNever, copyToClipboard } from "@namada/utils";
712
import { ModalContainer } from "App/Common/ModalContainer";
813
import { routes } from "App/routes";
9-
import { proposalFamily } from "atoms/proposals";
14+
import { proposalWithDataFamily } from "atoms/proposals";
1015
import clsx from "clsx";
1116
import { useProposalIdParam } from "hooks";
1217
import { useState } from "react";
@@ -70,16 +75,16 @@ const formatIbcPgfTarget = (value: PgfIbcTarget): PgfIbcTargetJson => ({
7075
},
7176
});
7277

73-
const formatData = (proposal: Proposal): DataJson => {
74-
switch (proposal.proposalType.type) {
78+
const formatData = (proposalData: ProposalData): DataJson => {
79+
switch (proposalData.type) {
7580
case "default":
7681
return undefined;
7782

7883
case "default_with_wasm":
79-
return proposal.proposalType.data;
84+
return proposalData.data;
8085

8186
case "pgf_steward":
82-
const addRemove = proposal.proposalType.data;
87+
const addRemove = proposalData.data;
8388

8489
// deliberately specify keys to ensure no unwanted data is printed
8590
return {
@@ -88,7 +93,7 @@ const formatData = (proposal: Proposal): DataJson => {
8893
};
8994

9095
case "pgf_payment":
91-
const pgfActions = proposal.proposalType.data;
96+
const pgfActions = proposalData.data;
9297

9398
const continuous = [
9499
...pgfActions.continuous.add,
@@ -113,11 +118,12 @@ const formatData = (proposal: Proposal): DataJson => {
113118
return { continuous, retro };
114119

115120
default:
116-
return assertNever(proposal.proposalType);
121+
return assertNever(proposalData);
117122
}
118123
};
119124

120-
const getProposalJsonString = (proposal: Proposal): string => {
125+
const getProposalJsonString = (proposalWithData: ProposalWithData): string => {
126+
const { proposal, decodedData } = proposalWithData;
121127
const proposalJson: ProposalJson = {
122128
proposal: {
123129
id: proposal.id,
@@ -127,7 +133,7 @@ const getProposalJsonString = (proposal: Proposal): string => {
127133
voting_end_epoch: proposal.endEpoch,
128134
activation_epoch: proposal.activationEpoch,
129135
},
130-
data: formatData(proposal),
136+
data: formatData(decodedData),
131137
};
132138

133139
const stringified = JSON.stringify(
@@ -151,7 +157,7 @@ const getProposalJsonString = (proposal: Proposal): string => {
151157
2
152158
);
153159

154-
const { type } = proposal.proposalType;
160+
const { type } = decodedData;
155161

156162
if (type === "default_with_wasm") {
157163
// remove double quotes around WASM data
@@ -187,17 +193,24 @@ export const ViewJson: React.FC = () => {
187193
};
188194

189195
const WithProposalId: React.FC<{ proposalId: bigint }> = ({ proposalId }) => {
190-
const proposal = useAtomValue(proposalFamily(proposalId));
196+
const proposalWithDataQuery = useAtomValue(
197+
proposalWithDataFamily(proposalId)
198+
);
191199

192-
return proposal.status === "pending" || proposal.status === "error" ?
200+
return (
201+
proposalWithDataQuery.status === "pending" ||
202+
proposalWithDataQuery.status === "error"
203+
) ?
193204
null
194-
: <Loaded proposal={proposal.data} />;
205+
: <Loaded proposalWithData={proposalWithDataQuery.data} />;
195206
};
196207

197-
const Loaded: React.FC<{ proposal: Proposal }> = ({ proposal }) => {
208+
const Loaded: React.FC<{ proposalWithData: ProposalWithData }> = ({
209+
proposalWithData,
210+
}) => {
198211
const [copied, setCopied] = useState(false);
199212

200-
const jsonString = getProposalJsonString(proposal);
213+
const jsonString = getProposalJsonString(proposalWithData);
201214

202215
const onCopy = (): void => {
203216
if (!copied) {

apps/namadillo/src/App/Governance/VoteInfoCards.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
PgfActions,
88
PgfIbcTarget,
99
PgfTarget,
10-
Proposal,
10+
ProposalWithData,
1111
} from "@namada/types";
1212

13-
import { proposalFamily } from "atoms/proposals";
13+
import { proposalWithDataFamily } from "atoms/proposals";
1414
import BigNumber from "bignumber.js";
1515
import { useAtomValue } from "jotai";
1616
import { useEffect, useState } from "react";
@@ -150,18 +150,23 @@ const PgfPaymentInfoCards: React.FC<{
150150
export const VoteInfoCards: React.FC<{
151151
proposalId: bigint;
152152
}> = ({ proposalId }) => {
153-
const proposal = useAtomValue(proposalFamily(proposalId));
153+
const proposalWithDataQuery = useAtomValue(
154+
proposalWithDataFamily(proposalId)
155+
);
154156

155157
return (
156158
<div className="grid grid-cols-6 gap-2 m-4">
157-
{proposal.status === "pending" || proposal.status === "error" ?
159+
{(
160+
proposalWithDataQuery.status === "pending" ||
161+
proposalWithDataQuery.status === "error"
162+
) ?
158163
<>
159164
<LoadingCard className="col-span-2" />
160165
<LoadingCard className="col-span-2" />
161166
<LoadingCard className="col-span-2" />
162167
<LoadingCard className="col-span-full" />
163168
</>
164-
: <Loaded proposal={proposal.data} />}
169+
: <Loaded proposalWithData={proposalWithDataQuery.data} />}
165170
</div>
166171
);
167172
};
@@ -185,16 +190,17 @@ const DateTimeEpoch: React.FC<{ date: bigint; epoch: bigint }> = ({
185190
);
186191

187192
const Loaded: React.FC<{
188-
proposal: Proposal;
189-
}> = ({ proposal }) => {
193+
proposalWithData: ProposalWithData;
194+
}> = ({ proposalWithData }) => {
195+
const { proposal, decodedData, encodedData } = proposalWithData;
190196
const [dataHash, setDataHash] = useState<string>();
191197

192198
useEffect(() => {
193199
if (
194-
proposal.proposalType.type === "default_with_wasm" &&
195-
proposal.proposalType.data.length > 0
200+
encodedData?.type === "default_with_wasm" &&
201+
encodedData.data!.length > 0
196202
) {
197-
setDataHash(proposal.proposalType.data);
203+
setDataHash(encodedData.hash);
198204
}
199205
}, [proposal.proposalType]);
200206

@@ -239,11 +245,11 @@ const Loaded: React.FC<{
239245
className="col-span-full"
240246
/>
241247
)}
242-
{proposal.proposalType.type === "pgf_steward" && (
243-
<PgfStewardInfoCards addRemove={proposal.proposalType.data} />
248+
{decodedData.type === "pgf_steward" && (
249+
<PgfStewardInfoCards addRemove={decodedData.data} />
244250
)}
245-
{proposal.proposalType.type === "pgf_payment" && (
246-
<PgfPaymentInfoCards pgfActions={proposal.proposalType.data} />
251+
{decodedData.type === "pgf_payment" && (
252+
<PgfPaymentInfoCards pgfActions={decodedData.data} />
247253
)}
248254
</>
249255
);

apps/namadillo/src/App/Transactions/TransactionHistory.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ export const TransactionHistory = (): JSX.Element => {
221221
): TableRow => {
222222
const key =
223223
transaction.type === "bundled" ?
224-
`${transaction.revealPkTx.tx?.txId}-${transaction.mainTx.tx?.txId}`
225-
: transaction.tx.tx?.txId || index.toString();
224+
`${transaction.revealPkTx.tx?.id}-${transaction.mainTx.tx?.id}`
225+
: transaction.tx.tx?.id || index.toString();
226226

227227
return {
228228
key,

apps/namadillo/src/atoms/accounts/atoms.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ export const accountBalanceAtom = atomWithQuery<BigNumber>((get) => {
105105
queryKey: ["balances", tokenAddress.data, transparentBalanceQuery.data],
106106
...queryDependentFn(async (): Promise<BigNumber> => {
107107
const balance = transparentBalanceQuery.data
108-
?.filter(({ tokenAddress: ta }) => ta === tokenAddress.data)
109-
.map(({ tokenAddress, minDenomAmount }) => ({
110-
token: tokenAddress,
108+
?.filter(({ token: ta }) => ta.address === tokenAddress.data)
109+
.map(({ token, minDenomAmount }) => ({
110+
token,
111111
amount: toDisplayAmount(namadaAsset(), new BigNumber(minDenomAmount)),
112112
}))
113113
.at(0);

apps/namadillo/src/atoms/balance/atoms.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ export const namadaShieldedAssetsAtom = atomWithQuery((get) => {
218218

219219
return mapNamadaAddressesToAssets({
220220
balances:
221-
shieldedBalance?.map((i) => ({ ...i, tokenAddress: i.address })) ??
222-
[],
221+
shieldedBalance?.map((i) => ({
222+
minDenomAmount: i.minDenomAmount,
223+
token: { address: i.address },
224+
})) ?? [],
223225
assets: Object.values(chainAssetsMap.data),
224226
});
225227
}, [viewingKeysQuery, chainTokensQuery, chainAssetsMap]),

0 commit comments

Comments
 (0)