import { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live"; import { getSerializedAddressParameters, updateTransaction, makeAccountBridgeReceive, makeScanAccounts, makeSync, } from "@ledgerhq/ledger-wallet-framework/bridge/jsHelpers"; import { SignerContext } from "@ledgerhq/ledger-wallet-framework/signer"; import getAddressWrapper from "@ledgerhq/ledger-wallet-framework/bridge/getAddressWrapper"; import { getTransactionStatus } from "./getTransactionStatus"; import { estimateMaxSpendable } from "./estimateMaxSpendable"; import { prepareTransaction } from "./prepareTransaction"; import { createTransaction } from "./createTransaction"; import { getAccountShape } from "./synchronisation"; import { buildSignOperation } from "./signOperation"; import { broadcast } from "./broadcast"; import resolver from "../signer"; import type { Transaction, VechainSigner } from "../types"; import { validateAddress } from "../common-logic/validateAddress"; export function buildCurrencyBridge(signerContext: SignerContext): CurrencyBridge { const getAddress = resolver(signerContext); const scanAccounts = makeScanAccounts({ getAccountShape, getAddressFn: getAddressWrapper(getAddress), }); return { preload: async () => Promise.resolve({}), hydrate: () => {}, scanAccounts, }; } const sync = makeSync({ getAccountShape }); export function buildAccountBridge( signerContext: SignerContext, ): AccountBridge { const getAddress = resolver(signerContext); const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress)); const signOperation = buildSignOperation(signerContext); return { estimateMaxSpendable, createTransaction, updateTransaction, getTransactionStatus, prepareTransaction, sync, receive, signOperation, signRawOperation: () => { throw new Error("signRawOperation is not supported"); }, broadcast, getSerializedAddressParameters, validateAddress, }; } export function createBridges(signerContext: SignerContext) { return { currencyBridge: buildCurrencyBridge(signerContext), accountBridge: buildAccountBridge(signerContext), }; }