Skip to content

Commit 1b6eca5

Browse files
committed
feat: wip
1 parent 9391b05 commit 1b6eca5

File tree

6 files changed

+87
-8
lines changed

6 files changed

+87
-8
lines changed

apps/namadillo/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# dependencies
2+
yalc.lock
3+
/.yalc
24
/node_modules
35
/.pnp
46
.pnp.js

apps/namadillo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@keplr-wallet/types": "^0.12.136",
1313
"@namada/chain-registry": "^1.3.0",
1414
"@namada/indexer-client": "3.3.2",
15-
"@namada/sdk-multicore": "^0.20.7",
15+
"@namada/sdk-multicore": "file:.yalc/@namada/sdk-multicore",
1616
"@tailwindcss/container-queries": "^0.1.1",
1717
"@tanstack/query-core": "^5.40.0",
1818
"@tanstack/react-query": "^5.40.0",

apps/namadillo/src/App/Masp/MaspUnshield.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Panel } from "@namada/components";
2+
import { MaxMaspTxAmountProps } from "@namada/sdk-multicore";
23
import { AccountType } from "@namada/types";
34
import { MaspSyncCover } from "App/Common/MaspSyncCover";
45
import { NamadaTransferTopHeader } from "App/NamadaTransfer/NamadaTransferTopHeader";
@@ -9,6 +10,7 @@ import {
910
} from "App/Transfer/TransferModule";
1011
import { allDefaultAccountsAtom } from "atoms/accounts";
1112
import {
13+
estimateMaxMaspTxAmountAtom,
1214
lastCompletedShieldedSyncAtom,
1315
namadaShieldedAssetsAtom,
1416
} from "atoms/balance/atoms";
@@ -25,7 +27,8 @@ import { wallets } from "integrations";
2527
import invariant from "invariant";
2628
import { useAtom, useAtomValue } from "jotai";
2729
import { createTransferDataFromNamada } from "lib/transactions";
28-
import { useState } from "react";
30+
import { useMemo, useState } from "react";
31+
import { isNamadaAsset, toBaseAmount } from "utils";
2932

3033
export const MaspUnshield: React.FC = () => {
3134
const [displayAmount, setDisplayAmount] = useState<BigNumber | undefined>();
@@ -140,6 +143,43 @@ export const MaspUnshield: React.FC = () => {
140143
}
141144
}
142145
};
146+
147+
const www = useMemo(() => {
148+
let props: MaxMaspTxAmountProps | null;
149+
if (!feeProps || !account || !destinationAddress || !selectedAsset) {
150+
props = null;
151+
} else {
152+
props = {
153+
maxNotes: 6,
154+
source: account.pseudoExtendedKey!,
155+
target: destinationAddress,
156+
token: selectedAsset.asset.address,
157+
feeToken: feeProps.gasConfig.gasToken,
158+
amount:
159+
isNamadaAsset(selectedAsset.asset) ?
160+
selectedAsset.amount.toString()
161+
: toBaseAmount(selectedAsset.asset, selectedAsset.amount).toString(),
162+
feeAmount: feeProps.gasConfig.gasPriceInMinDenom
163+
.times(feeProps.gasConfig.gasLimit)
164+
.toString(),
165+
};
166+
console.log(props.feeAmount);
167+
console.log(props.amount);
168+
console.log(feeProps.gasConfig.gasPriceInMinDenom.toString());
169+
}
170+
171+
return estimateMaxMaspTxAmountAtom(props);
172+
}, [
173+
selectedAsset?.asset.address,
174+
feeProps.gasConfig.gasToken,
175+
feeProps?.gasConfig.gasLimit.toString(),
176+
account?.pseudoExtendedKey,
177+
destinationAddress,
178+
]);
179+
180+
const res = useAtomValue(www);
181+
console.log(res);
182+
143183
// We stop the ledger status check when the transfer is in progress
144184
setLedgerStatusStop(isPerformingTransfer);
145185

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DefaultApi } from "@namada/indexer-client";
2+
import { MaxMaspTxAmountProps } from "@namada/sdk-multicore";
23
import { Account, AccountType, DatedViewingKey } from "@namada/types";
34
import {
45
accountsAtom,
@@ -24,8 +25,8 @@ import { sequenceT } from "fp-ts/lib/Apply";
2425
import { pipe } from "fp-ts/lib/function";
2526
import * as O from "fp-ts/Option";
2627
import invariant from "invariant";
27-
import { atom, getDefaultStore } from "jotai";
28-
import { atomWithQuery } from "jotai-tanstack-query";
28+
import { Atom, atom, getDefaultStore } from "jotai";
29+
import { atomWithQuery, AtomWithQueryResult } from "jotai-tanstack-query";
2930
import { atomWithStorage } from "jotai/utils";
3031
import { Address, TokenBalance } from "types";
3132
import { namadaAsset, toDisplayAmount } from "utils";
@@ -34,6 +35,7 @@ import {
3435
mapNamadaAssetsToTokenBalances,
3536
} from "./functions";
3637
import {
38+
estiamteMaxMaspTxAmountByNotes,
3739
fetchShieldedBalance,
3840
fetchShieldedRewards,
3941
fetchShieldedRewardsPerToken,
@@ -202,6 +204,31 @@ export const shieldedBalanceAtom = atomWithQuery((get) => {
202204
};
203205
});
204206

207+
export const estimateMaxMaspTxAmountAtom = (
208+
props: MaxMaspTxAmountProps | null
209+
): Atom<AtomWithQueryResult<[string, string] | null>> =>
210+
atomWithQuery((get) => {
211+
const chainParametersQuery = get(chainParametersAtom);
212+
const chainId = chainParametersQuery.data?.chainId;
213+
214+
return {
215+
queryKey: ["estimate-max-masp-tx-amount", chainId],
216+
...queryDependentFn(async () => {
217+
if (!props || !chainId) {
218+
return null;
219+
}
220+
221+
console.log(
222+
"Estimating max masp tx amount with props:",
223+
props,
224+
chainId
225+
);
226+
const result = await estiamteMaxMaspTxAmountByNotes(props, chainId);
227+
return result;
228+
}, [chainParametersQuery]),
229+
};
230+
});
231+
205232
export const namadaShieldedAssetsAtom = atomWithQuery((get) => {
206233
const storageShieldedBalance = get(storageShieldedBalanceAtom);
207234
const viewingKeysQuery = get(viewingKeysAtom);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Comlink from "comlink";
33
import {
44
Balance,
55
DatedViewingKey,
6+
MaxMaspTxAmountProps,
67
ProgressBarNames,
78
SdkEvents,
89
} from "@namada/sdk-multicore";
@@ -105,6 +106,15 @@ export const fetchShieldedBalance = async (
105106
return await sdk.rpc.queryBalance(viewingKey.key, addresses, chainId);
106107
};
107108

109+
//TODO: typo
110+
export const estiamteMaxMaspTxAmountByNotes = async (
111+
props: MaxMaspTxAmountProps,
112+
chainId: string
113+
): Promise<[string, string]> => {
114+
const sdk = await getSdkInstance();
115+
return await sdk.tx.estiamteMaxMaspTxAmountByNotes(props, chainId);
116+
};
117+
108118
export const fetchShieldedRewards = async (
109119
viewingKey: DatedViewingKey,
110120
chainId: string,

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,7 @@ __metadata:
37653765
"@keplr-wallet/types": "npm:^0.12.136"
37663766
"@namada/chain-registry": "npm:^1.3.0"
37673767
"@namada/indexer-client": "npm:3.3.2"
3768-
"@namada/sdk-multicore": "npm:^0.20.7"
3768+
"@namada/sdk-multicore": "file:.yalc/@namada/sdk-multicore"
37693769
"@namada/sdk-node": "npm:^0.20.7"
37703770
"@namada/vite-esbuild-plugin": "npm:^1.0.1"
37713771
"@playwright/test": "npm:^1.24.1"
@@ -3852,9 +3852,9 @@ __metadata:
38523852
languageName: unknown
38533853
linkType: soft
38543854

3855-
"@namada/sdk-multicore@npm:^0.20.7":
3855+
"@namada/sdk-multicore@file:.yalc/@namada/sdk-multicore::locator=%40namada%2Fnamadillo%40workspace%3Aapps%2Fnamadillo":
38563856
version: 0.20.7
3857-
resolution: "@namada/sdk-multicore@npm:0.20.7"
3857+
resolution: "@namada/sdk-multicore@file:.yalc/@namada/sdk-multicore#.yalc/@namada/sdk-multicore::hash=daaac3&locator=%40namada%2Fnamadillo%40workspace%3Aapps%2Fnamadillo"
38583858
dependencies:
38593859
"@cosmjs/encoding": "npm:^0.29.0"
38603860
"@dao-xyz/borsh": "npm:^5.1.5"
@@ -3865,7 +3865,7 @@ __metadata:
38653865
buffer: "npm:^6.0.3"
38663866
semver: "npm:^7.7.2"
38673867
slip44: "npm:^3.0.18"
3868-
checksum: 10c0/954de17370d879af0781454f3f13239c3e2557592f353051fbcd7236d18ed0d084bd3d23c67995701cc5bb07abd15b39568d366c8d632a72efe8c70dd60956f9
3868+
checksum: 10c0/44f75f778d763ae314236aeac9de6008b1c32f426c157868f422a487cfeb82d7775d969e794e205cbb1cfc567994611709309665ec3da00166502adda4ebad8e
38693869
languageName: node
38703870
linkType: hard
38713871

0 commit comments

Comments
 (0)