diff --git a/apps/namadillo/src/App/Masp/MaspShield.tsx b/apps/namadillo/src/App/Masp/MaspShield.tsx index 6bb6e050f6..cdbc4ac448 100644 --- a/apps/namadillo/src/App/Masp/MaspShield.tsx +++ b/apps/namadillo/src/App/Masp/MaspShield.tsx @@ -3,44 +3,38 @@ import { Panel } from "@namada/components"; import { AccountType } from "@namada/types"; import { Timeline } from "App/Common/Timeline"; import { params } from "App/routes"; -import { - OnSubmitTransferParams, - TransferModule, -} from "App/Transfer/TransferModule"; +import { TransferModule } from "App/Transfer/TransferModule"; import { allDefaultAccountsAtom } from "atoms/accounts"; import { namadaTransparentAssetsAtom } from "atoms/balance/atoms"; import { chainParametersAtom } from "atoms/chain/atoms"; -import { defaultGasConfigFamily } from "atoms/fees/atoms"; -import { shieldTxAtom } from "atoms/shield/atoms"; +import { rpcUrlAtom } from "atoms/settings"; import BigNumber from "bignumber.js"; import clsx from "clsx"; import { AnimatePresence, motion } from "framer-motion"; import { useTransactionActions } from "hooks/useTransactionActions"; +import { useTransfer } from "hooks/useTransfer"; import { wallets } from "integrations"; import { getAssetImageUrl } from "integrations/utils"; +import invariant from "invariant"; import { useAtomValue } from "jotai"; +import { createTransferDataFromNamada } from "lib/transactions"; import { useEffect, useState } from "react"; import { useSearchParams } from "react-router-dom"; import namadaChain from "registry/namada.json"; -import { - Address, - PartialTransferTransactionData, - TransferStep, - TransferTransactionData, -} from "types"; +import { Address, PartialTransferTransactionData, TransferStep } from "types"; import { MaspTopHeader } from "./MaspTopHeader"; export const MaspShield: React.FC = () => { const [searchParams, setSearchParams] = useSearchParams(); + const rpcUrl = useAtomValue(rpcUrlAtom); const chainParameters = useAtomValue(chainParametersAtom); const defaultAccounts = useAtomValue(allDefaultAccountsAtom); const { data: availableAssets, isLoading: isLoadingAssets } = useAtomValue( namadaTransparentAssetsAtom ); - const performShieldTransfer = useAtomValue(shieldTxAtom); - const [amount, setAmount] = useState(); + const [displayAmount, setDisplayAmount] = useState(); const [currentStepIndex, setCurrentStepIndex] = useState(0); const [generalErrorMessage, setGeneralErrorMessage] = useState(""); @@ -65,10 +59,20 @@ export const MaspShield: React.FC = () => { const selectedAssetAddress = searchParams.get(params.asset) || undefined; const selectedAsset = selectedAssetAddress ? availableAssets?.[selectedAssetAddress] : undefined; + const source = sourceAddress ?? ""; + const target = destinationAddress ?? ""; - const { data: gasConfig } = useAtomValue( - defaultGasConfigFamily(["ShieldingTransfer"]) - ); + const { + execute: performTransfer, + isPending: isPerformingTransfer, + txKind, + gasConfig, + } = useTransfer({ + source, + target, + token: selectedAsset?.originalAddress ?? "", + displayAmount: displayAmount ?? new BigNumber(0), + }); const assetImage = selectedAsset ? getAssetImageUrl(selectedAsset.asset) : ""; @@ -96,29 +100,15 @@ export const MaspShield: React.FC = () => { ); }; - const onSubmitTransfer = async ({ - displayAmount, - destinationAddress, - }: OnSubmitTransferParams): Promise => { + const onSubmitTransfer = async (): Promise => { try { setGeneralErrorMessage(""); setCurrentStepIndex(1); - if (typeof sourceAddress === "undefined") { - throw new Error("Source address is not defined"); - } - - if (!chainId) { - throw new Error("Chain ID is undefined"); - } - - if (!selectedAsset) { - throw new Error("No asset is selected"); - } - - if (typeof gasConfig === "undefined") { - throw new Error("No gas config"); - } + invariant(sourceAddress, "Source address is not defined"); + invariant(chainId, "Chain ID is undefined"); + invariant(selectedAsset, "No asset is selected"); + invariant(gasConfig, "No gas config"); setTransaction({ type: "TransparentToShielded", @@ -127,38 +117,30 @@ export const MaspShield: React.FC = () => { chainId, }); - const txResponse = await performShieldTransfer.mutateAsync({ - sourceAddress, - destinationAddress, - tokenAddress: selectedAsset.originalAddress, - amount: displayAmount, - gasConfig, - }); + const txResponse = await performTransfer(); - // TODO review and improve this data to be more precise and full of details - const tx: TransferTransactionData = { - type: "TransparentToShielded", - currentStep: TransferStep.Complete, - sourceAddress, - destinationAddress, - asset: selectedAsset.asset, - displayAmount, - rpc: txResponse.msg.payload.chain.rpcUrl, - chainId: txResponse.msg.payload.chain.chainId, - hash: txResponse.encodedTxData.txs[0]?.hash, - feePaid: txResponse.encodedTxData.wrapperTxProps.feeAmount, - resultTxHash: txResponse.encodedTxData.txs[0]?.innerTxHashes[0], - status: "success", - createdAt: new Date(), - updatedAt: new Date(), - }; - setTransaction(tx); - storeTransaction(tx); - - setCurrentStepIndex(2); + if (txResponse) { + const txList = createTransferDataFromNamada( + txKind, + selectedAsset.asset, + rpcUrl, + txResponse + ); + + // Currently we don't have the option of batching transfer transactions + if (txList.length === 0) { + throw "Couldn't create TransferData object "; + } + + const tx = txList[0]; + setTransaction(tx); + storeTransaction(tx); + } else { + throw "Invalid transaction response"; + } } catch (err) { setGeneralErrorMessage(err + ""); - setCurrentStepIndex(0); + setTransaction(undefined); } }; @@ -187,8 +169,8 @@ export const MaspShield: React.FC = () => { wallet: wallets.namada, walletAddress: sourceAddress, onChangeSelectedAsset, - amount, - onChangeAmount: setAmount, + amount: displayAmount, + onChangeAmount: setDisplayAmount, }} destination={{ chain: namadaChain as Chain, @@ -198,7 +180,7 @@ export const MaspShield: React.FC = () => { isShielded: true, }} gasConfig={gasConfig} - isSubmitting={performShieldTransfer.isPending} + isSubmitting={isPerformingTransfer} errorMessage={generalErrorMessage} onSubmitTransfer={onSubmitTransfer} /> diff --git a/apps/namadillo/src/App/Masp/MaspUnshield.tsx b/apps/namadillo/src/App/Masp/MaspUnshield.tsx index e7a3a8392c..c97abfb970 100644 --- a/apps/namadillo/src/App/Masp/MaspUnshield.tsx +++ b/apps/namadillo/src/App/Masp/MaspUnshield.tsx @@ -3,44 +3,38 @@ import { Panel } from "@namada/components"; import { AccountType } from "@namada/types"; import { Timeline } from "App/Common/Timeline"; import { params } from "App/routes"; -import { - OnSubmitTransferParams, - TransferModule, -} from "App/Transfer/TransferModule"; +import { TransferModule } from "App/Transfer/TransferModule"; import { allDefaultAccountsAtom } from "atoms/accounts"; import { namadaShieldedAssetsAtom } from "atoms/balance/atoms"; import { chainParametersAtom } from "atoms/chain/atoms"; -import { defaultGasConfigFamily } from "atoms/fees/atoms"; -import { unshieldTxAtom } from "atoms/shield/atoms"; +import { rpcUrlAtom } from "atoms/settings"; import BigNumber from "bignumber.js"; import clsx from "clsx"; import { AnimatePresence, motion } from "framer-motion"; import { useTransactionActions } from "hooks/useTransactionActions"; +import { useTransfer } from "hooks/useTransfer"; import { wallets } from "integrations"; import { getAssetImageUrl } from "integrations/utils"; +import invariant from "invariant"; import { useAtomValue } from "jotai"; +import { createTransferDataFromNamada } from "lib/transactions"; import { useEffect, useState } from "react"; import { useSearchParams } from "react-router-dom"; import namadaChain from "registry/namada.json"; -import { - Address, - PartialTransferTransactionData, - TransferStep, - TransferTransactionData, -} from "types"; +import { Address, PartialTransferTransactionData, TransferStep } from "types"; import { MaspTopHeader } from "./MaspTopHeader"; export const MaspUnshield: React.FC = () => { const [searchParams, setSearchParams] = useSearchParams(); + const rpcUrl = useAtomValue(rpcUrlAtom); const chainParameters = useAtomValue(chainParametersAtom); const defaultAccounts = useAtomValue(allDefaultAccountsAtom); const { data: availableAssets, isLoading: isLoadingAssets } = useAtomValue( namadaShieldedAssetsAtom ); - const performUnshieldTransfer = useAtomValue(unshieldTxAtom); - const [amount, setAmount] = useState(); + const [displayAmount, setDisplayAmount] = useState(); const [currentStepIndex, setCurrentStepIndex] = useState(0); const [generalErrorMessage, setGeneralErrorMessage] = useState(""); @@ -54,11 +48,10 @@ export const MaspUnshield: React.FC = () => { } = useTransactionActions(); const chainId = chainParameters.data?.chainId; - - const sourceAccount = defaultAccounts.data?.find( + const account = defaultAccounts.data?.find( (account) => account.type === AccountType.ShieldedKeys ); - const sourceAddress = sourceAccount?.address; + const sourceAddress = account?.address; const destinationAddress = defaultAccounts.data?.find( (account) => account.type !== AccountType.ShieldedKeys )?.address; @@ -66,10 +59,20 @@ export const MaspUnshield: React.FC = () => { const selectedAssetAddress = searchParams.get(params.asset) || undefined; const selectedAsset = selectedAssetAddress ? availableAssets?.[selectedAssetAddress] : undefined; + const source = sourceAddress ?? ""; + const target = destinationAddress ?? ""; - const { data: gasConfig } = useAtomValue( - defaultGasConfigFamily(["UnshieldingTransfer"]) - ); + const { + execute: performTransfer, + isPending: isPerformingTransfer, + txKind, + gasConfig, + } = useTransfer({ + source, + target, + token: selectedAsset?.originalAddress ?? "", + displayAmount: displayAmount ?? new BigNumber(0), + }); const assetImage = selectedAsset ? getAssetImageUrl(selectedAsset.asset) : ""; @@ -97,33 +100,15 @@ export const MaspUnshield: React.FC = () => { ); }; - const onSubmitTransfer = async ({ - displayAmount, - destinationAddress, - }: OnSubmitTransferParams): Promise => { + const onSubmitTransfer = async (): Promise => { try { setGeneralErrorMessage(""); setCurrentStepIndex(1); - if (typeof sourceAccount?.pseudoExtendedKey === "undefined") { - throw new Error("Pseudo extended key is not defined"); - } - - if (typeof sourceAddress === "undefined") { - throw new Error("Source address is not defined"); - } - - if (!chainId) { - throw new Error("Chain ID is undefined"); - } - - if (!selectedAsset) { - throw new Error("No asset is selected"); - } - - if (typeof gasConfig === "undefined") { - throw new Error("No gas config"); - } + invariant(sourceAddress, "Source address is not defined"); + invariant(chainId, "Chain ID is undefined"); + invariant(selectedAsset, "No asset is selected"); + invariant(gasConfig, "No gas config"); setTransaction({ type: "ShieldedToTransparent", @@ -132,37 +117,30 @@ export const MaspUnshield: React.FC = () => { currentStep: TransferStep.Sign, }); - const txResponse = await performUnshieldTransfer.mutateAsync({ - sourceAddress: sourceAccount.pseudoExtendedKey, - destinationAddress, - tokenAddress: selectedAsset.originalAddress, - amount: displayAmount, - gasConfig, - }); + const txResponse = await performTransfer(); - // TODO review and improve this data to be more precise and full of details - const tx: TransferTransactionData = { - type: "ShieldedToTransparent", - currentStep: TransferStep.WaitingConfirmation, - sourceAddress: sourceAccount.pseudoExtendedKey, - destinationAddress, - asset: selectedAsset.asset, - displayAmount, - rpc: txResponse.msg.payload.chain.rpcUrl, - chainId: txResponse.msg.payload.chain.chainId, - hash: txResponse.encodedTxData.txs[0]?.hash, - feePaid: txResponse.encodedTxData.wrapperTxProps.feeAmount, - resultTxHash: txResponse.encodedTxData.txs[0]?.innerTxHashes[0], - status: "success", - createdAt: new Date(), - updatedAt: new Date(), - }; - setTransaction(tx); - storeTransaction(tx); - setCurrentStepIndex(2); + if (txResponse) { + const txList = createTransferDataFromNamada( + txKind, + selectedAsset.asset, + rpcUrl, + txResponse + ); + + // Currently we don't have the option of batching transfer transactions + if (txList.length === 0) { + throw "Couldn't create TransferData object "; + } + + const tx = txList[0]; + setTransaction(tx); + storeTransaction(tx); + } else { + throw "Invalid transaction response"; + } } catch (err) { setGeneralErrorMessage(err + ""); - setCurrentStepIndex(0); + setTransaction(undefined); } }; @@ -192,8 +170,8 @@ export const MaspUnshield: React.FC = () => { walletAddress: sourceAddress, isShielded: true, onChangeSelectedAsset, - amount, - onChangeAmount: setAmount, + amount: displayAmount, + onChangeAmount: setDisplayAmount, }} destination={{ chain: namadaChain as Chain, @@ -203,7 +181,7 @@ export const MaspUnshield: React.FC = () => { isShielded: false, }} gasConfig={gasConfig} - isSubmitting={performUnshieldTransfer.isPending} + isSubmitting={isPerformingTransfer} errorMessage={generalErrorMessage} onSubmitTransfer={onSubmitTransfer} /> diff --git a/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx b/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx index 6dd496fb64..0e42ffd617 100644 --- a/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx +++ b/apps/namadillo/src/App/NamadaTransfer/NamadaTransfer.tsx @@ -12,34 +12,19 @@ import { allDefaultAccountsAtom } from "atoms/accounts"; import { namadaTransparentAssetsAtom } from "atoms/balance/atoms"; import { chainParametersAtom } from "atoms/chain/atoms"; import { applicationFeaturesAtom, rpcUrlAtom } from "atoms/settings"; -import { - shieldedTxAtom, - shieldTxAtom, - unshieldTxAtom, -} from "atoms/shield/atoms"; -import { - createShieldedTransferAtom, - createShieldingTransferAtom, - createTransparentTransferAtom, - createUnshieldingTransferAtom, -} from "atoms/transfer/atoms"; import BigNumber from "bignumber.js"; import clsx from "clsx"; -import { useTransaction } from "hooks/useTransaction"; import { useTransactionActions } from "hooks/useTransactionActions"; +import { useTransfer } from "hooks/useTransfer"; import { wallets } from "integrations"; +import invariant from "invariant"; import { useAtomValue } from "jotai"; import { createTransferDataFromNamada } from "lib/transactions"; import { useEffect, useMemo, useState } from "react"; import { useSearchParams } from "react-router-dom"; import namadaChain from "registry/namada.json"; import { twMerge } from "tailwind-merge"; -import { - Address, - NamadaTransferTxKind, - PartialTransferTransactionData, - TransferStep, -} from "types"; +import { Address, PartialTransferTransactionData, TransferStep } from "types"; import { isNamadaAsset } from "utils"; import { NamadaTransferTopHeader } from "./NamadaTransferTopHeader"; @@ -60,12 +45,6 @@ export const NamadaTransfer: React.FC = () => { const { data: availableAssetsData, isLoading: isLoadingAssets } = useAtomValue(namadaTransparentAssetsAtom); - // TODO: remove this block once transfer logic is unified - const { mutateAsync: performUnshieldTransfer } = useAtomValue(unshieldTxAtom); - const { mutateAsync: performShieldingTransfer } = useAtomValue(shieldTxAtom); - const { mutateAsync: performShieldedTransfer } = useAtomValue(shieldedTxAtom); - // end of block - const { transactions: myTransactions, findByHash, @@ -96,72 +75,20 @@ export const NamadaTransfer: React.FC = () => { const selectedAssetAddress = searchParams.get(params.asset) || undefined; const selectedAsset = selectedAssetAddress ? availableAssets?.[selectedAssetAddress] : undefined; - const token = selectedAsset?.originalAddress ?? ""; const source = sourceAddress ?? ""; const target = customAddress ?? ""; - const txAmount = displayAmount || new BigNumber(0); - - const commomProps = { - parsePendingTxNotification: () => ({ - title: "Transfer transaction in progress", - description: "Your transfer transaction is being processed", - }), - parseErrorTxNotification: () => ({ - title: "Transfer transaction failed", - description: "", - }), - }; - - const transparentTransaction = useTransaction({ - eventType: "TransparentTransfer", - createTxAtom: createTransparentTransferAtom, - params: [{ data: [{ source, target, token, amount: txAmount }] }], - ...commomProps, - }); - - const shieldedTransaction = useTransaction({ - eventType: "ShieldedTransfer", - createTxAtom: createShieldedTransferAtom, - params: [{ data: [{ source, target, token, amount: txAmount }] }], - ...commomProps, - }); - - const shieldingTransaction = useTransaction({ - eventType: "ShieldingTransfer", - createTxAtom: createShieldingTransferAtom, - params: [{ target, data: [{ source, token, amount: txAmount }] }], - ...commomProps, - }); - - const unshieldingTransaction = useTransaction({ - eventType: "UnshieldingTransfer", - createTxAtom: createUnshieldingTransferAtom, - params: [{ source, data: [{ target, token, amount: txAmount }] }], - ...commomProps, - }); - - const getAddressKind = (address: Address): "Shielded" | "Transparent" => - isShieldedAddress(address) ? "Shielded" : "Transparent"; - - const txKind: NamadaTransferTxKind = - `${getAddressKind(source)}To${getAddressKind(target)}` as const; const { execute: performTransfer, - gasConfig, isPending: isPerformingTransfer, - } = (() => { - switch (txKind) { - case "TransparentToTransparent": - return transparentTransaction; - case "TransparentToShielded": - return shieldingTransaction; - case "ShieldedToTransparent": - return unshieldingTransaction; - case "ShieldedToShielded": - return shieldedTransaction; - } - })(); + txKind, + gasConfig, + } = useTransfer({ + source, + target, + token: selectedAsset?.originalAddress ?? "", + displayAmount: displayAmount ?? new BigNumber(0), + }); const isSourceShielded = isShieldedAddress(source); const isTargetShielded = isShieldedAddress(target); @@ -196,21 +123,10 @@ export const NamadaTransfer: React.FC = () => { try { setGeneralErrorMessage(""); - if (typeof sourceAddress === "undefined") { - throw new Error("Source address is not defined"); - } - - if (!chainId) { - throw new Error("Chain ID is undefined"); - } - - if (!selectedAsset) { - throw new Error("No asset is selected"); - } - - if (typeof gasConfig === "undefined") { - throw new Error("No gas config"); - } + invariant(sourceAddress, "Source address is not defined"); + invariant(chainId, "Chain ID is undefined"); + invariant(selectedAsset, "No asset is selected"); + invariant(gasConfig, "No gas config"); setTransaction({ type: txKind, @@ -219,24 +135,7 @@ export const NamadaTransfer: React.FC = () => { chainId, }); - // TODO: once transfer logic is unified, this block should be replaced by a single - // call to the performTransfer function - const shieldedTransferParams = { - sourceAddress: account!.pseudoExtendedKey || sourceAddress, - destinationAddress: target, - tokenAddress: selectedAsset.originalAddress, - amount: txAmount, - gasConfig, - }; - const txResponse = - txKind === "ShieldedToTransparent" ? - await performUnshieldTransfer(shieldedTransferParams) - : txKind === "TransparentToShielded" ? - await performShieldingTransfer(shieldedTransferParams) - : txKind === "ShieldedToShielded" ? - await performShieldedTransfer(shieldedTransferParams) - : await performTransfer({ memo }); - // end of block + const txResponse = await performTransfer({ memo }); if (txResponse) { const txList = createTransferDataFromNamada( diff --git a/apps/namadillo/src/App/WorkerTest.tsx b/apps/namadillo/src/App/WorkerTest.tsx index b42c484d77..4371b90efe 100644 --- a/apps/namadillo/src/App/WorkerTest.tsx +++ b/apps/namadillo/src/App/WorkerTest.tsx @@ -96,7 +96,7 @@ export function WorkerTest(): JSX.Element { gasPrice: BigNumber(0), gasToken: "tnam1", }, - shieldingProps: [shieldingMsgValue], + props: [shieldingMsgValue], indexerUrl, chain: chain!, }, @@ -109,7 +109,7 @@ export function WorkerTest(): JSX.Element { await shieldWorker.broadcast({ type: "broadcast", payload: { - encodedTx, + encodedTxData: encodedTx, signedTxs, }, }); @@ -158,7 +158,7 @@ export function WorkerTest(): JSX.Element { gasPrice: BigNumber(0), gasToken: "tnam1", }, - unshieldingProps: [shieldingMsgValue], + props: [shieldingMsgValue], chain: chain!, }, }; @@ -169,7 +169,7 @@ export function WorkerTest(): JSX.Element { await shieldWorker.broadcast({ type: "broadcast", payload: { - encodedTx, + encodedTxData: encodedTx, signedTxs, }, }); @@ -229,7 +229,7 @@ export function WorkerTest(): JSX.Element { await shieldWorker.broadcast({ type: "broadcast", payload: { - encodedTx, + encodedTxData: encodedTx, signedTxs, }, }); diff --git a/apps/namadillo/src/atoms/integrations/functions.ts b/apps/namadillo/src/atoms/integrations/functions.ts index 2aa26255b1..43ee5a455e 100644 --- a/apps/namadillo/src/atoms/integrations/functions.ts +++ b/apps/namadillo/src/atoms/integrations/functions.ts @@ -31,6 +31,8 @@ import { toDisplayAmount } from "utils"; import { unknownAsset } from "utils/assets"; import { getSdkInstance } from "utils/sdk"; +import campfireAssets from "namada-chain-registry/_testnets/namadacampfire/assetlist.json"; +import campfireChain from "namada-chain-registry/_testnets/namadacampfire/chain.json"; import housefireAssets from "namada-chain-registry/_testnets/namadahousefire/assetlist.json"; import housefireChain from "namada-chain-registry/_testnets/namadahousefire/chain.json"; import housefireOldAssets from "namada-chain-registry/_testnets/namadahousefireold/assetlist.json"; @@ -40,6 +42,7 @@ import internalDevnetChain from "namada-chain-registry/_testnets/namadainternald import namadaAssets from "namada-chain-registry/namada/assetlist.json"; import namadaChain from "namada-chain-registry/namada/chain.json"; +import campfireOsmosisTestnetIbc from "namada-chain-registry/_testnets/_IBC/namadacampfire-osmosistestnet.json"; import housefireOldCosmosTestnetIbc from "namada-chain-registry/_testnets/_IBC/namadahousefireold-cosmoshubtestnet.json"; import housefireOldOsmosisTestnetIbc from "namada-chain-registry/_testnets/_IBC/namadahousefireold-osmosistestnet.json"; import internalDevnetCosmosTestnetIbc from "namada-chain-registry/_testnets/_IBC/namadainternaldevnet-cosmoshubtestnet.json"; @@ -49,6 +52,7 @@ import cosmosRegistry from "chain-registry"; cosmosRegistry.chains.push( internalDevnetChain, + campfireChain, housefireChain, housefireOldChain, namadaChain @@ -56,12 +60,14 @@ cosmosRegistry.chains.push( cosmosRegistry.assets.push( internalDevnetAssets, + campfireAssets, housefireAssets, housefireOldAssets, namadaAssets ); cosmosRegistry.ibc.push( + campfireOsmosisTestnetIbc, internalDevnetCosmosTestnetIbc, housefireOldCosmosTestnetIbc, housefireOldOsmosisTestnetIbc diff --git a/apps/namadillo/src/atoms/shield/atoms.ts b/apps/namadillo/src/atoms/shield/atoms.ts deleted file mode 100644 index 299622741f..0000000000 --- a/apps/namadillo/src/atoms/shield/atoms.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { defaultAccountAtom } from "atoms/accounts"; -import { chainAtom } from "atoms/chain"; -import { indexerUrlAtom, rpcUrlAtom } from "atoms/settings"; -import { NamadaKeychain } from "hooks/useNamadaKeychain"; -import { atomWithMutation } from "jotai-tanstack-query"; -import { - ShieldedTransferParams, - ShieldTransferParams, - submitShieldedTx, - submitShieldTx, - submitUnshieldTx, - UnshieldTransferParams, -} from "./services"; - -export const shieldTxAtom = atomWithMutation((get) => { - const rpcUrl = get(rpcUrlAtom); - const { data: account } = get(defaultAccountAtom); - const { data: chain } = get(chainAtom); - const indexerUrl = get(indexerUrlAtom); - - return { - mutationKey: ["shield-tx"], - mutationFn: async (params: ShieldTransferParams) => { - return await submitShieldTx(rpcUrl, account!, chain!, indexerUrl, params); - }, - }; -}); - -export const unshieldTxAtom = atomWithMutation((get) => { - const rpcUrl = get(rpcUrlAtom); - const { data: account } = get(defaultAccountAtom); - const { data: chain } = get(chainAtom); - - return { - mutationKey: ["unshield-tx"], - mutationFn: async (params: UnshieldTransferParams) => { - const namada = await new NamadaKeychain().get(); - const disposableSigner = await namada?.genDisposableKeypair(); - if (!disposableSigner) { - throw new Error("No signer available"); - } - - return submitUnshieldTx( - rpcUrl, - account!, - chain!, - params, - disposableSigner - ); - }, - }; -}); - -export const shieldedTxAtom = atomWithMutation((get) => { - const rpcUrl = get(rpcUrlAtom); - const { data: account } = get(defaultAccountAtom); - const { data: chain } = get(chainAtom); - - return { - mutationKey: ["shielded-tx"], - mutationFn: async (params: ShieldedTransferParams) => { - const namada = await new NamadaKeychain().get(); - const disposableSigner = await namada?.genDisposableKeypair(); - if (!disposableSigner) { - throw new Error("No signer available"); - } - - return submitShieldedTx( - rpcUrl, - account!, - chain!, - params, - disposableSigner - ); - }, - }; -}); diff --git a/apps/namadillo/src/atoms/shield/services.ts b/apps/namadillo/src/atoms/shield/services.ts deleted file mode 100644 index 371cd22b46..0000000000 --- a/apps/namadillo/src/atoms/shield/services.ts +++ /dev/null @@ -1,223 +0,0 @@ -import { - Account, - GenDisposableSignerResponse, - ShieldedTransferMsgValue, - ShieldingTransferMsgValue, - UnshieldingTransferMsgValue, -} from "@namada/types"; -import BigNumber from "bignumber.js"; -import * as Comlink from "comlink"; -import { EncodedTxData, signTx } from "lib/query"; -import { Address, ChainSettings, GasConfig } from "types"; -import { Shield, ShieldedTransfer, Unshield } from "workers/MaspTxMessages"; -import { - Worker as MaspTxWorkerApi, - registerTransferHandlers as maspTxRegisterTransferHandlers, -} from "workers/MaspTxWorker"; -import MaspTxWorker from "workers/MaspTxWorker?worker"; - -export type ShieldTransferParams = { - sourceAddress: Address; - destinationAddress: Address; - tokenAddress: Address; - amount: BigNumber; - gasConfig: GasConfig; -}; - -export type UnshieldTransferParams = { - sourceAddress: Address; - destinationAddress: Address; - tokenAddress: Address; - amount: BigNumber; - gasConfig: GasConfig; -}; - -export type ShieldedTransferParams = { - sourceAddress: Address; - destinationAddress: Address; - tokenAddress: Address; - amount: BigNumber; - gasConfig: GasConfig; -}; - -export const submitShieldTx = async ( - rpcUrl: string, - account: Account, - chain: ChainSettings, - indexerUrl: string, - params: ShieldTransferParams -): Promise<{ - msg: Shield; - encodedTxData: EncodedTxData; -}> => { - const { - sourceAddress: source, - destinationAddress: target, - tokenAddress: token, - amount, - gasConfig, - } = params; - - maspTxRegisterTransferHandlers(); - const worker = new MaspTxWorker(); - const shieldWorker = Comlink.wrap(worker); - await shieldWorker.init({ - type: "init", - payload: { rpcUrl, token, maspIndexerUrl: "" }, - }); - - const shieldingMsgValue = new ShieldingTransferMsgValue({ - target, - data: [{ source, token, amount }], - }); - - const msg: Shield = { - type: "shield", - payload: { - account, - gasConfig, - shieldingProps: [shieldingMsgValue], - chain, - indexerUrl, - }, - }; - - const { payload: encodedTx } = await shieldWorker.shield(msg); - - const signedTxs = await signTx(encodedTx, source); - - await shieldWorker.broadcast({ - type: "broadcast", - payload: { - encodedTx, - signedTxs, - }, - }); - - worker.terminate(); - - return { msg, encodedTxData: encodedTx }; -}; - -export const submitUnshieldTx = async ( - rpcUrl: string, - account: Account, - chain: ChainSettings, - params: UnshieldTransferParams, - disposableSigner: GenDisposableSignerResponse -): Promise<{ - msg: Unshield; - encodedTxData: EncodedTxData; -}> => { - const { - sourceAddress: source, - destinationAddress: target, - tokenAddress: token, - amount, - gasConfig, - } = params; - - maspTxRegisterTransferHandlers(); - const worker = new MaspTxWorker(); - const unshieldWorker = Comlink.wrap(worker); - await unshieldWorker.init({ - type: "init", - payload: { rpcUrl, token, maspIndexerUrl: "" }, - }); - - const unshieldingMsgValue = new UnshieldingTransferMsgValue({ - source, - gasSpendingKey: source, - data: [{ target, token, amount }], - }); - - const msg: Unshield = { - type: "unshield", - payload: { - account: { - ...account, - publicKey: disposableSigner.publicKey, - }, - gasConfig, - unshieldingProps: [unshieldingMsgValue], - chain, - }, - }; - - const { payload: encodedTxData } = await unshieldWorker.unshield(msg); - - const signedTxs = await signTx(encodedTxData, disposableSigner.address); - - await unshieldWorker.broadcast({ - type: "broadcast", - payload: { - encodedTx: encodedTxData, - signedTxs, - }, - }); - - worker.terminate(); - - return { msg, encodedTxData }; -}; - -export const submitShieldedTx = async ( - rpcUrl: string, - account: Account, - chain: ChainSettings, - params: ShieldedTransferParams, - disposableSigner: GenDisposableSignerResponse -): Promise<{ - msg: ShieldedTransfer; - encodedTxData: EncodedTxData; -}> => { - const { - sourceAddress: source, - destinationAddress: target, - tokenAddress: token, - amount, - gasConfig, - } = params; - - maspTxRegisterTransferHandlers(); - const worker = new MaspTxWorker(); - const workerApi = Comlink.wrap(worker); - await workerApi.init({ - type: "init", - payload: { rpcUrl, token, maspIndexerUrl: "" }, - }); - - const shieldedTransferMsgValue = new ShieldedTransferMsgValue({ - gasSpendingKey: source, - data: [{ source, target, token, amount }], - }); - - const msg: ShieldedTransfer = { - type: "shielded-transfer", - payload: { - account: { - ...account, - publicKey: disposableSigner.publicKey, - }, - gasConfig, - props: [shieldedTransferMsgValue], - chain, - }, - }; - - const { payload: encodedTxData } = await workerApi.shieldedTransfer(msg); - - const signedTxs = await signTx(encodedTxData, disposableSigner.address); - - await workerApi.broadcast({ - type: "broadcast", - payload: { - encodedTx: encodedTxData, - signedTxs, - }, - }); - - worker.terminate(); - - return { msg, encodedTxData }; -}; diff --git a/apps/namadillo/src/atoms/transfer/atoms.ts b/apps/namadillo/src/atoms/transfer/atoms.ts index 65a4d61345..ec70331878 100644 --- a/apps/namadillo/src/atoms/transfer/atoms.ts +++ b/apps/namadillo/src/atoms/transfer/atoms.ts @@ -5,6 +5,7 @@ import { UnshieldingTransferMsgValue, } from "@namada/types"; import { chainAtom } from "atoms/chain"; +import { indexerUrlAtom, rpcUrlAtom } from "atoms/settings"; import { atomWithMutation } from "jotai-tanstack-query"; import { BuildTxAtomParams } from "types"; import { @@ -37,6 +38,7 @@ export const createTransparentTransferAtom = atomWithMutation((get) => { export const createShieldedTransferAtom = atomWithMutation((get) => { const chain = get(chainAtom); + const rpcUrl = get(rpcUrlAtom); return { mutationKey: ["create-shielded-transfer-tx"], enabled: chain.isSuccess, @@ -46,12 +48,21 @@ export const createShieldedTransferAtom = atomWithMutation((get) => { account, memo, }: BuildTxAtomParams) => - createShieldedTransferTx(chain.data!, account, params, gasConfig, memo), + createShieldedTransferTx( + chain.data!, + account, + params, + gasConfig, + rpcUrl, + memo + ), }; }); export const createShieldingTransferAtom = atomWithMutation((get) => { const chain = get(chainAtom); + const rpcUrl = get(rpcUrlAtom); + const indexerUrl = get(indexerUrlAtom); return { mutationKey: ["create-shielding-transfer-tx"], enabled: chain.isSuccess, @@ -61,12 +72,21 @@ export const createShieldingTransferAtom = atomWithMutation((get) => { account, memo, }: BuildTxAtomParams) => - createShieldingTransferTx(chain.data!, account, params, gasConfig, memo), + createShieldingTransferTx( + chain.data!, + account, + params, + gasConfig, + rpcUrl, + indexerUrl, + memo + ), }; }); export const createUnshieldingTransferAtom = atomWithMutation((get) => { const chain = get(chainAtom); + const rpcUrl = get(rpcUrlAtom); return { mutationKey: ["create-unshielding-transfer-tx"], enabled: chain.isSuccess, @@ -81,6 +101,7 @@ export const createUnshieldingTransferAtom = atomWithMutation((get) => { account, params, gasConfig, + rpcUrl, memo ), }; diff --git a/apps/namadillo/src/atoms/transfer/services.ts b/apps/namadillo/src/atoms/transfer/services.ts index e27640ded3..7e6e16471b 100644 --- a/apps/namadillo/src/atoms/transfer/services.ts +++ b/apps/namadillo/src/atoms/transfer/services.ts @@ -1,5 +1,6 @@ import { Account, + GenDisposableSignerResponse, ShieldedTransferMsgValue, ShieldedTransferProps, ShieldingTransferMsgValue, @@ -9,9 +10,69 @@ import { UnshieldingTransferMsgValue, UnshieldingTransferProps, } from "@namada/types"; -import { buildTxPair, TransactionPair } from "lib/query"; -import { ChainSettings, GasConfig } from "types"; +import BigNumber from "bignumber.js"; +import * as Comlink from "comlink"; +import { NamadaKeychain } from "hooks/useNamadaKeychain"; +import { buildTxPair, EncodedTxData, signTx, TransactionPair } from "lib/query"; +import { Address, ChainSettings, GasConfig } from "types"; import { getSdkInstance } from "utils/sdk"; +import { Shield, ShieldedTransfer, Unshield } from "workers/MaspTxMessages"; +import { + registerTransferHandlers as maspTxRegisterTransferHandlers, + Worker as MaspTxWorkerApi, +} from "workers/MaspTxWorker"; +import MaspTxWorker from "workers/MaspTxWorker?worker"; + +export type WorkerTransferParams = { + sourceAddress: Address; + destinationAddress: Address; + tokenAddress: Address; + amount: BigNumber; + gasConfig: GasConfig; +}; + +const workerBuildTxPair = async ({ + rpcUrl, + token, + signerAddress, + buildTxFn, +}: { + rpcUrl: string; + token: Address; + signerAddress: string; + buildTxFn: ( + workerLink: Comlink.Remote + ) => Promise>; +}): Promise> => { + maspTxRegisterTransferHandlers(); + const worker = new MaspTxWorker(); + const workerLink = Comlink.wrap(worker); + await workerLink.init({ + type: "init", + payload: { rpcUrl, token, maspIndexerUrl: "" }, + }); + + const encodedTxData = await buildTxFn(workerLink); + const signedTxs = await signTx(encodedTxData, signerAddress); + + const transactionPair: TransactionPair = { + signedTxs, + encodedTxData, + }; + + worker.terminate(); + + return transactionPair; +}; + +const getDisposableSigner = async (): Promise => { + const namada = await new NamadaKeychain().get(); + const disposableSigner = await namada?.genDisposableKeypair(); + if (!disposableSigner) { + throw new Error("No signer available"); + } + return disposableSigner; +}; export const createTransparentTransferTx = async ( chain: ChainSettings, @@ -38,19 +99,40 @@ export const createShieldedTransferTx = async ( account: Account, props: ShieldedTransferMsgValue[], gasConfig: GasConfig, + rpcUrl: string, memo?: string ): Promise | undefined> => { - const { tx } = await getSdkInstance(); - const transactionPairs = await buildTxPair( - account, - gasConfig, - chain, - props, - tx.buildShieldedTransfer, - props[0]?.data[0]?.source, - memo - ); - return transactionPairs; + const disposableSigner = await getDisposableSigner(); + const source = props[0]?.data[0]?.source; + const destination = props[0]?.data[0]?.target; + const token = props[0]?.data[0]?.token; + const amount = props[0]?.data[0]?.amount; + + return await workerBuildTxPair({ + rpcUrl, + token, + signerAddress: disposableSigner.address, + buildTxFn: async (workerLink) => { + const msgValue = new ShieldedTransferMsgValue({ + gasSpendingKey: source, + data: [{ source, target: destination, token, amount }], + }); + const msg: ShieldedTransfer = { + type: "shielded-transfer", + payload: { + account: { + ...account, + publicKey: disposableSigner.publicKey, + }, + gasConfig, + props: [msgValue], + chain, + memo, + }, + }; + return (await workerLink.shieldedTransfer(msg)).payload; + }, + }); }; export const createShieldingTransferTx = async ( @@ -58,19 +140,38 @@ export const createShieldingTransferTx = async ( account: Account, props: ShieldingTransferMsgValue[], gasConfig: GasConfig, + rpcUrl: string, + indexerUrl: string, memo?: string ): Promise | undefined> => { - const { tx } = await getSdkInstance(); - const transactionPairs = await buildTxPair( - account, - gasConfig, - chain, - props, - tx.buildShieldingTransfer, - props[0]?.data[0]?.source, - memo - ); - return transactionPairs; + const source = props[0]?.data[0]?.source; + const destination = props[0]?.target; + const token = props[0]?.data[0]?.token; + const amount = props[0]?.data[0]?.amount; + + return await workerBuildTxPair({ + rpcUrl, + token, + signerAddress: source, + buildTxFn: async (workerLink) => { + const msgValue = new ShieldingTransferMsgValue({ + target: destination, + data: [{ source, token, amount }], + }); + const msg: Shield = { + type: "shield", + payload: { + account, + gasConfig, + props: [msgValue], + chain, + indexerUrl, + memo, + }, + }; + return (await workerLink.shield(msg)).payload; + }, + }); }; export const createUnshieldingTransferTx = async ( @@ -78,17 +179,39 @@ export const createUnshieldingTransferTx = async ( account: Account, props: UnshieldingTransferMsgValue[], gasConfig: GasConfig, + rpcUrl: string, memo?: string ): Promise | undefined> => { - const { tx } = await getSdkInstance(); - const transactionPairs = await buildTxPair( - account, - gasConfig, - chain, - props, - tx.buildUnshieldingTransfer, - props[0]?.source, - memo - ); - return transactionPairs; + const disposableSigner = await getDisposableSigner(); + const source = props[0]?.source; + const destination = props[0]?.data[0]?.target; + const token = props[0]?.data[0]?.token; + const amount = props[0]?.data[0]?.amount; + + return await workerBuildTxPair({ + rpcUrl, + token, + signerAddress: disposableSigner.address, + buildTxFn: async (workerLink) => { + const msgValue = new UnshieldingTransferMsgValue({ + source, + gasSpendingKey: source, + data: [{ target: destination, token, amount }], + }); + const msg: Unshield = { + type: "unshield", + payload: { + account: { + ...account, + publicKey: disposableSigner.publicKey, + }, + gasConfig, + props: [msgValue], + chain, + memo, + }, + }; + return (await workerLink.unshield(msg)).payload; + }, + }); }; diff --git a/apps/namadillo/src/hooks/useTransaction.tsx b/apps/namadillo/src/hooks/useTransaction.tsx index 66d273954e..59a13976f2 100644 --- a/apps/namadillo/src/hooks/useTransaction.tsx +++ b/apps/namadillo/src/hooks/useTransaction.tsx @@ -33,7 +33,7 @@ export type useTransactionProps = { onSuccess?: (tx: TransactionPair) => void; }; -type useTransactionOutput = { +export type useTransactionOutput = { execute: ( additionalParms?: Partial> ) => Promise | void>; @@ -66,14 +66,6 @@ export const useTransaction = ({ defaultGasConfigFamily(new Array(params.length).fill(eventType)) ); - const validate = (): void => { - invariant(gasConfig.data, "Gas config not loaded"); - invariant( - account?.address, - "Extension not connected or no account is selected" - ); - }; - const broadcast = (txPair: TransactionPair): Promise => broadcastTx( txPair.encodedTxData, @@ -109,11 +101,16 @@ export const useTransaction = ({ txAdditionalParams: Partial> = {} ): Promise | void> => { try { - validate(); + invariant(gasConfig.data, "Gas config not loaded"); + invariant( + account?.address, + "Extension not connected or no account is selected" + ); + const tx = await buildTx({ params, - gasConfig: gasConfig.data!, - account: account!, + gasConfig: gasConfig.data, + account: account, ...txAdditionalParams, }); diff --git a/apps/namadillo/src/hooks/useTransfer.ts b/apps/namadillo/src/hooks/useTransfer.ts new file mode 100644 index 0000000000..7598afab9a --- /dev/null +++ b/apps/namadillo/src/hooks/useTransfer.ts @@ -0,0 +1,110 @@ +import { + AccountType, + ShieldedTransferMsgValue, + ShieldingTransferMsgValue, + TransparentTransferMsgValue, + UnshieldingTransferMsgValue, +} from "@namada/types"; +import { isShieldedAddress } from "App/Transfer/common"; +import { allDefaultAccountsAtom } from "atoms/accounts"; +import { + createShieldedTransferAtom, + createShieldingTransferAtom, + createTransparentTransferAtom, + createUnshieldingTransferAtom, +} from "atoms/transfer/atoms"; +import BigNumber from "bignumber.js"; +import { useTransaction, useTransactionOutput } from "hooks/useTransaction"; +import { useAtomValue } from "jotai"; +import { Address, NamadaTransferTxKind } from "types"; + +type useTransferParams = { + source: Address; + target: Address; + token: Address; + displayAmount: BigNumber; +}; + +type useTransferOutput = ( + | useTransactionOutput + | useTransactionOutput + | useTransactionOutput + | useTransactionOutput +) & { + txKind: NamadaTransferTxKind; +}; + +export const useTransfer = ({ + source, + target, + token, + displayAmount: amount, +}: useTransferParams): useTransferOutput => { + const defaultAccounts = useAtomValue(allDefaultAccountsAtom); + const shieldedAccount = defaultAccounts.data?.find( + (account) => account.type === AccountType.ShieldedKeys + ); + const pseudoExtendedKey = shieldedAccount?.pseudoExtendedKey ?? ""; + + const commomProps = { + parsePendingTxNotification: () => ({ + title: "Transfer transaction in progress", + description: "Your transfer transaction is being processed", + }), + parseErrorTxNotification: () => ({ + title: "Transfer transaction failed", + description: "", + }), + }; + + const transparentTransaction = useTransaction({ + eventType: "TransparentTransfer", + createTxAtom: createTransparentTransferAtom, + params: [{ data: [{ source, target, token, amount }] }], + ...commomProps, + }); + + const shieldedTransaction = useTransaction({ + eventType: "ShieldedTransfer", + createTxAtom: createShieldedTransferAtom, + params: [{ data: [{ source: pseudoExtendedKey, target, token, amount }] }], + ...commomProps, + }); + + const shieldingTransaction = useTransaction({ + eventType: "ShieldingTransfer", + createTxAtom: createShieldingTransferAtom, + params: [{ target, data: [{ source, token, amount }] }], + ...commomProps, + }); + + const unshieldingTransaction = useTransaction({ + eventType: "UnshieldingTransfer", + createTxAtom: createUnshieldingTransferAtom, + params: [{ source: pseudoExtendedKey, data: [{ target, token, amount }] }], + ...commomProps, + }); + + const getAddressKind = (address: Address): "Shielded" | "Transparent" => + isShieldedAddress(address) ? "Shielded" : "Transparent"; + + const txKind: NamadaTransferTxKind = `${getAddressKind(source)}To${getAddressKind(target)}`; + + const result = (() => { + switch (txKind) { + case "TransparentToTransparent": + return transparentTransaction; + case "TransparentToShielded": + return shieldingTransaction; + case "ShieldedToTransparent": + return unshieldingTransaction; + case "ShieldedToShielded": + return shieldedTransaction; + } + })(); + + return { + ...result, + txKind, + }; +}; diff --git a/apps/namadillo/src/lib/transactions.ts b/apps/namadillo/src/lib/transactions.ts index ff2b59a0ab..5b2cdd674d 100644 --- a/apps/namadillo/src/lib/transactions.ts +++ b/apps/namadillo/src/lib/transactions.ts @@ -24,7 +24,7 @@ import { TransferTransactionData, } from "types"; import { toDisplayAmount } from "utils"; -import { EncodedTxData, TransactionPair } from "./query"; +import { TransactionPair } from "./query"; export const getEventAttribute = ( tx: DeliverTxResponse, @@ -167,13 +167,7 @@ export const createTransferDataFromNamada = ( | TransactionPair | TransactionPair | TransactionPair - | TransactionPair - // TODO: remove this block after transfer logic unification - | { encodedTxData: EncodedTxData } - | { encodedTxData: EncodedTxData } - | { encodedTxData: EncodedTxData }, - // end of block - + | TransactionPair, memo?: string ): TransferTransactionData[] => { if (!txResponse?.encodedTxData?.txs?.length) { diff --git a/apps/namadillo/src/utils/index.ts b/apps/namadillo/src/utils/index.ts index 8c173a0590..74e2529ca1 100644 --- a/apps/namadillo/src/utils/index.ts +++ b/apps/namadillo/src/utils/index.ts @@ -76,8 +76,7 @@ const findDisplayUnit = (asset: Asset): AssetDenomUnit | undefined => { return denom_units.find((unit) => unit.denom === display); }; -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export const namadaAsset = () => { +export const namadaAsset = (): Asset => { const store = getDefaultStore(); const config = store.get(localnetConfigAtom); diff --git a/apps/namadillo/src/workers/MaspTxMessages.ts b/apps/namadillo/src/workers/MaspTxMessages.ts index d67d3a666c..359f27db1e 100644 --- a/apps/namadillo/src/workers/MaspTxMessages.ts +++ b/apps/namadillo/src/workers/MaspTxMessages.ts @@ -5,7 +5,7 @@ import { TxResponseMsgValue, UnshieldingTransferMsgValue, } from "@namada/types"; -import { EncodedTxData } from "lib/query"; +import { EncodedTxData, TransactionPair } from "lib/query"; import { ChainSettings, GasConfig } from "types"; import { WebWorkerMessage } from "./utils"; @@ -21,9 +21,10 @@ export type InitDone = WebWorkerMessage<"init-done", null>; type ShieldPayload = { account: Account; gasConfig: GasConfig; - shieldingProps: ShieldingTransferMsgValue[]; + props: ShieldingTransferMsgValue[]; chain: ChainSettings; indexerUrl: string; + memo?: string; }; export type Shield = WebWorkerMessage<"shield", ShieldPayload>; export type ShieldDone = WebWorkerMessage< @@ -34,8 +35,9 @@ export type ShieldDone = WebWorkerMessage< type UnshieldPayload = { account: Account; gasConfig: GasConfig; - unshieldingProps: UnshieldingTransferMsgValue[]; + props: UnshieldingTransferMsgValue[]; chain: ChainSettings; + memo?: string; }; export type Unshield = WebWorkerMessage<"unshield", UnshieldPayload>; export type UnshieldDone = WebWorkerMessage< @@ -48,6 +50,7 @@ type ShieldedTransferPayload = { gasConfig: GasConfig; props: ShieldedTransferMsgValue[]; chain: ChainSettings; + memo?: string; }; export type ShieldedTransfer = WebWorkerMessage< "shielded-transfer", @@ -58,10 +61,8 @@ export type ShieldedTransferDone = WebWorkerMessage< EncodedTxData >; -type BroadcastPayload = { - encodedTx: EncodedTxData; - signedTxs: Uint8Array[]; -}; +type BroadcastPayload = TransactionPair; + export type Broadcast = WebWorkerMessage<"broadcast", BroadcastPayload>; export type BroadcastDone = WebWorkerMessage< "broadcast-done", diff --git a/apps/namadillo/src/workers/MaspTxWorker.ts b/apps/namadillo/src/workers/MaspTxWorker.ts index 412f847b6d..7a35608826 100644 --- a/apps/namadillo/src/workers/MaspTxWorker.ts +++ b/apps/namadillo/src/workers/MaspTxWorker.ts @@ -77,7 +77,14 @@ async function shield( sdk: Sdk, payload: Shield["payload"] ): Promise> { - const { indexerUrl, account, gasConfig, chain, shieldingProps } = payload; + const { + indexerUrl, + account, + gasConfig, + chain, + props: shieldingProps, + memo, + } = payload; const configuration = new Configuration({ basePath: indexerUrl }); const api = new DefaultApi(configuration); @@ -93,7 +100,8 @@ async function shield( chain, shieldingProps, sdk.tx.buildShieldingTransfer, - Boolean(publicKeyRevealed) + Boolean(publicKeyRevealed), + memo ); return encodedTxData; @@ -103,7 +111,7 @@ async function unshield( sdk: Sdk, payload: Unshield["payload"] ): Promise> { - const { account, gasConfig, chain, unshieldingProps } = payload; + const { account, gasConfig, chain, props } = payload; await sdk.masp.loadMaspParams("", chain.chainId); @@ -112,7 +120,7 @@ async function unshield( account, gasConfig, chain, - unshieldingProps, + props, sdk.tx.buildUnshieldingTransfer, true ); @@ -146,15 +154,15 @@ async function broadcast( sdk: Sdk, payload: Broadcast["payload"] ): Promise { - const { encodedTx, signedTxs } = payload; + const { encodedTxData, signedTxs } = payload; const result: TxResponseMsgValue[] = []; for await (const signedTx of signedTxs) { - for await (const _ of encodedTx.txs) { + for await (const _ of encodedTxData.txs) { const response = await sdk.rpc.broadcastTx( signedTx, - encodedTx.wrapperTxProps + encodedTxData.wrapperTxProps ); result.push(response); } diff --git a/packages/shared/lib/src/types/masp.rs b/packages/shared/lib/src/types/masp.rs index d353979798..cff5b901e8 100644 --- a/packages/shared/lib/src/types/masp.rs +++ b/packages/shared/lib/src/types/masp.rs @@ -79,7 +79,7 @@ impl PseudoExtendedKey { hex::encode(borsh::to_vec(&self.0).expect("Serializing PseudoExtendedKey should not fail!")) } pub fn decode(encoded: String) -> PseudoExtendedKey { - let decoded = hex::decode(encoded).expect("Decoding PsuedoExtendedKey should not fail!"); + let decoded = hex::decode(encoded).expect("Decoding PseudoExtendedKey should not fail!"); PseudoExtendedKey( zip32::PseudoExtendedKey::try_from_slice(decoded.as_slice()) diff --git a/yarn.lock b/yarn.lock index cbe90c8c7d..53cde8664d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15873,8 +15873,8 @@ __metadata: "namada-chain-registry@https://github.com/anoma/namada-chain-registry": version: 0.0.1 - resolution: "namada-chain-registry@https://github.com/anoma/namada-chain-registry.git#commit=6b495f9763b7539d7577e0b862689215909b2a01" - checksum: 8dfbc049889f55973d42f79551251ad98228fe248da52eed9944456c37b1e7c263348af7f6bb4675369f8c9c49f54b1a90abbe1e81e7169f4b13d686daf90b71 + resolution: "namada-chain-registry@https://github.com/anoma/namada-chain-registry.git#commit=e732cd0b238a50022b8d9d14c8b38149a4612a34" + checksum: 91f246faf7d57d2db88653ca2244c9c51313afda91a3c367538bc3fc80ec653e453eb1fec124913e7d4d2a3c9e0e520a1377c2bd98cd8de33e83168564723c3d languageName: node linkType: hard