Skip to content

Commit 88dff2e

Browse files
committed
feat: parse tx osmosis swap name in the extension
1 parent 3563a94 commit 88dff2e

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

apps/extension/src/Approvals/Commitment.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TxType } from "@namada/sdk";
1+
import { IbcTransferProps, TxType } from "@namada/sdk";
22
import {
33
BondProps,
44
ClaimRewardsProps,
@@ -12,13 +12,17 @@ import {
1212
} from "@namada/types";
1313
import { shortenAddress } from "@namada/utils";
1414
import { NamCurrency } from "App/Common/NamCurrency";
15+
import * as J from "fp-ts/Json";
16+
import { pipe } from "fp-ts/lib/function";
17+
import * as O from "fp-ts/Option";
1518
import { ReactNode } from "react";
1619
import { FaVoteYea } from "react-icons/fa";
1720
import { FaRegEye, FaWallet } from "react-icons/fa6";
1821
import { GoStack } from "react-icons/go";
1922
import { PiDotsNineBold } from "react-icons/pi";
2023
import { isShieldedPool, parseTransferType, ShieldedPoolLabel } from "utils";
2124
import { TransactionCard } from "./TransactionCard";
25+
import { OsmosisSwapMemo } from "./types";
2226

2327
type CommitmentProps = {
2428
commitment: CommitmentDetailProps;
@@ -37,6 +41,7 @@ const IconMap: Record<TxType, React.ReactNode> = {
3741
[TxType.VoteProposal]: <FaVoteYea />,
3842
[TxType.Batch]: <PiDotsNineBold />,
3943
[TxType.ClaimRewards]: <GoStack />,
44+
[TxType.OsmosisSwap]: <FaWallet />,
4045
};
4146

4247
const TitleMap: Record<TxType, string> = {
@@ -51,6 +56,7 @@ const TitleMap: Record<TxType, string> = {
5156
[TxType.VoteProposal]: "Vote",
5257
[TxType.Batch]: "Batch",
5358
[TxType.ClaimRewards]: "Claim Rewards",
59+
[TxType.OsmosisSwap]: "Shielded Swap",
5460
};
5561

5662
const formatAddress = (address: string): string =>
@@ -147,6 +153,27 @@ export const Commitment = ({
147153
wrapperFeePayer
148154
);
149155
title = `${type} ${title}`;
156+
} else if (commitment.txType === TxType.IBCTransfer) {
157+
const ibcTx = commitment as CommitmentDetailProps<IbcTransferProps>;
158+
159+
// It's fine not to handle errors here as memo can be optional and not JSON at all
160+
const maybeMemo = pipe(
161+
O.fromNullable(ibcTx.memo),
162+
O.map((memo) => J.parse(memo)),
163+
O.map(O.fromEither),
164+
O.flatten
165+
);
166+
167+
const maybeOsmosisSwapMemo = pipe(
168+
maybeMemo,
169+
O.map(OsmosisSwapMemo.decode),
170+
O.map(O.fromEither),
171+
O.flatten
172+
);
173+
174+
if (O.isSome(maybeOsmosisSwapMemo)) {
175+
title = TitleMap[TxType.OsmosisSwap];
176+
}
150177
}
151178

152179
return (

apps/extension/src/Approvals/types.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as t from "io-ts";
12
import { Message } from "router";
23

34
export enum TopLevelRoute {
@@ -40,3 +41,63 @@ export enum Status {
4041
Pending,
4142
Failed,
4243
}
44+
45+
const NamadaOsmosisSwap = t.type({
46+
overflow_receiver: t.string,
47+
shielded_amount: t.string,
48+
shielding_data: t.string,
49+
});
50+
51+
const FinalMemoNamada = t.type({
52+
osmosis_swap: NamadaOsmosisSwap,
53+
});
54+
55+
const FinalMemo = t.type({
56+
namada: FinalMemoNamada,
57+
});
58+
59+
const OnFailedDelivery = t.type({
60+
local_recovery_addr: t.string,
61+
});
62+
63+
const RouteItem = t.type({
64+
pool_id: t.string,
65+
token_out_denom: t.string,
66+
});
67+
68+
const Slippage = t.type({
69+
min_output_amount: t.string,
70+
});
71+
72+
const OsmosisSwapMsg = t.type({
73+
final_memo: FinalMemo,
74+
on_failed_delivery: OnFailedDelivery,
75+
output_denom: t.string,
76+
receiver: t.string,
77+
route: t.array(RouteItem),
78+
slippage: Slippage,
79+
});
80+
81+
const Msg = t.type({
82+
osmosis_swap: OsmosisSwapMsg,
83+
});
84+
85+
const Wasm = t.type({
86+
contract: t.string,
87+
msg: Msg,
88+
});
89+
90+
export const OsmosisSwapMemo = t.type({
91+
wasm: Wasm,
92+
});
93+
94+
export type NamadaOsmosisSwap = t.TypeOf<typeof NamadaOsmosisSwap>;
95+
export type FinalMemoNamada = t.TypeOf<typeof FinalMemoNamada>;
96+
export type FinalMemo = t.TypeOf<typeof FinalMemo>;
97+
export type OnFailedDelivery = t.TypeOf<typeof OnFailedDelivery>;
98+
export type RouteItem = t.TypeOf<typeof RouteItem>;
99+
export type Slippage = t.TypeOf<typeof Slippage>;
100+
export type OsmosisSwapMsg = t.TypeOf<typeof OsmosisSwapMsg>;
101+
export type Msg = t.TypeOf<typeof Msg>;
102+
export type Wasm = t.TypeOf<typeof Wasm>;
103+
export type OsmosisSwapMemo = t.TypeOf<typeof OsmosisSwapMemo>;

0 commit comments

Comments
 (0)