Skip to content

Commit

Permalink
fix(wallet): refactor tx submission
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Oct 30, 2024
1 parent 4116180 commit 2d54392
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 320 deletions.
4 changes: 2 additions & 2 deletions packages/features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"webextension-polyfill": "0.12.0",
"xss": "1.0.15",
"yaml": "2.5.0",
"zod": "3.23.8",
"zustand": "4.5.4"
},
"devDependencies": {
Expand All @@ -103,7 +102,8 @@
"vite": "5.3.5",
"vite-plugin-node-polyfills": "0.17.0",
"vite-plugin-svgr": "4.2.0",
"vite-plugin-top-level-await": "1.4.2"
"vite-plugin-top-level-await": "1.4.2",
"zod": "3.23.8"
},
"peerDependencies": {
"@types/mocha": "10.0.1",
Expand Down
32 changes: 14 additions & 18 deletions packages/features/src/send/hooks/use-transaction-confirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChainOperationArgs } from "@palladxyz/key-management"
import { Mina } from "@palladxyz/mina-core"
import { Mina, TransactionType } from "@palladxyz/mina-core"
import { useVault } from "@palladxyz/vault"
import dayjs from "dayjs"
import type { SubmitHandler, UseFormReturn } from "react-hook-form"
Expand All @@ -11,6 +11,7 @@ import { useAccount } from "@/common/hooks/use-account"
import { useTransactionStore } from "@/common/store/transaction"
import { usePendingTransactionStore } from "@palladxyz/vault"

import type { SignedTransaction, TransactionBody } from "@mina-js/utils"
import { utf8ToBytes } from "@noble/hashes/utils"
import type { ConfirmTransactionSchema } from "../components/confirm-transaction-form.schema"

Expand Down Expand Up @@ -62,12 +63,19 @@ export const useTransactionConfirmation = ({
network: "Mina",
networkType: currentNetworkName === "Mainnet" ? "mainnet" : "testnet",
}
let txBody: TransactionBody
if (type === TransactionType.STAKE_DELEGATION) {
const { amount, ...txRest } = constructedTx
txBody = txRest
} else {
txBody = constructedTx
}
try {
signedTx = await sign(
{ transaction: constructedTx },
signedTx = (await sign(
{ transaction: txBody },
operationArgs,
getPassphrase,
)
)) as SignedTransaction
} catch (error: unknown) {
if (error instanceof Error) {
if (error.name === "AuthenticationError")
Expand All @@ -78,22 +86,10 @@ export const useTransactionConfirmation = ({
}
}
const submitTxArgs = {
signedTransaction: signedTx as never,
signedTransaction: signedTx,
type,
transactionDetails: {
fee: rawTransaction.fee,
to: rawTransaction.to,
from: rawTransaction.from,
nonce: rawTransaction.nonce,
memo: rawTransaction.memo,
amount: rawTransaction.amount,
validUntil: rawTransaction.validUntil,
},
}
const submittedTx = (await submitTx(submitTxArgs)) as any
const hash =
submittedTx?.sendPayment?.payment?.hash ??
submittedTx?.sendDelegation?.delegation?.hash
const hash = await submitTx(submitTxArgs as never)
addPendingTransaction({
hash,
expireAt: dayjs().add(8, "hours").toISOString(),
Expand Down
11 changes: 1 addition & 10 deletions packages/mina-core/src/Providers/tx-submit-provider/types.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import type { BorrowedTypes } from "../.."
import type { TransactionBody, TransactionType } from "../../Mina"
import type { TransactionType } from "../../Mina"
import type { Provider } from "../Provider"

export type SubmitTxArgs = {
signedTransaction:
| BorrowedTypes.SignedLegacy<BorrowedTypes.Payment>
| BorrowedTypes.SignedLegacy<BorrowedTypes.StakeDelegation>
type: TransactionType
transactionDetails: {
fee: TransactionBody["fee"]
to: TransactionBody["to"]
from: TransactionBody["from"]
nonce: TransactionBody["nonce"]
memo: TransactionBody["memo"]
validUntil: TransactionBody["validUntil"]
amount: TransactionBody["amount"]
}
}

interface TxResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ export type SubmitTxArgs = {
| BorrowedTypes.SignedLegacy<BorrowedTypes.Payment>
| BorrowedTypes.SignedLegacy<BorrowedTypes.StakeDelegation>
type: Mina.TransactionType
transactionDetails: {
fee: Mina.TransactionBody["fee"]
to: Mina.TransactionBody["to"]
from: Mina.TransactionBody["from"]
nonce: Mina.TransactionBody["nonce"]
memo: Mina.TransactionBody["memo"]
validUntil: Mina.TransactionBody["validUntil"]
amount: Mina.TransactionBody["amount"]
}
}

interface TxResult {
Expand Down
2 changes: 0 additions & 2 deletions packages/pallad-core/src/Pallad/providers/unified-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
import type { NodeStatus } from "./node-status-provider"
import type { HealthCheckResponse } from "./provider"
import type { TxStatus, TxStatusArgs } from "./tx-status-provider"
import type { SubmitTxArgs, SubmitTxResult } from "./tx-submit-provider"
import type { Tx } from "./types"

export type UnifiedChainProviderConfig = {
Expand All @@ -23,7 +22,6 @@ export interface UnifiedChainProviderType {
args: AccountInfoArgs,
): Promise<Record<string, AccountInfo> | undefined>
getTransactionStatus?(args: TxStatusArgs): Promise<TxStatus | undefined>
submitTransaction(args: SubmitTxArgs): Promise<SubmitTxResult | undefined>

// Methods related to ProviderArchive
getTransactions(args: TransactionsByAddressesArgs): Promise<Tx[] | undefined>
Expand Down
1 change: 0 additions & 1 deletion packages/providers/src/mina-node/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from "./account-info"
export * from "./chain-history"
export * from "./node-status"
export * from "./tx-submit"
export * from "./types"
1 change: 0 additions & 1 deletion packages/providers/src/mina-node/tx-submit/index.ts

This file was deleted.

167 changes: 0 additions & 167 deletions packages/providers/src/mina-node/tx-submit/mutations.ts

This file was deleted.

47 changes: 0 additions & 47 deletions packages/providers/src/mina-node/tx-submit/tx-submit-provider.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/providers/src/unified-providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from "./account-info-provider"
export * from "./chain-history-provider"
export * from "./node-status-provider"
export * from "./tx-submit-provider"
export * from "./types"
export * from "./unified-provider"
31 changes: 0 additions & 31 deletions packages/providers/src/unified-providers/tx-submit-provider.ts

This file was deleted.

Loading

0 comments on commit 2d54392

Please sign in to comment.