From 49fd0108fb5408d21d238057234ea017687ac27f Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:37:28 +0200 Subject: [PATCH] Adapt lib to new types --- lib/multisigHelpers.ts | 26 +++++++------------------- lib/txMsgHelpers.ts | 8 ++++---- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/lib/multisigHelpers.ts b/lib/multisigHelpers.ts index 8314161..5e04c95 100644 --- a/lib/multisigHelpers.ts +++ b/lib/multisigHelpers.ts @@ -1,16 +1,13 @@ import { ChainInfo } from "@/context/ChainsContext/types"; +import { DbMultisigDraft } from "@/graphql"; import { - createMultisigThresholdPubkey, MultisigThresholdPubkey, + createMultisigThresholdPubkey, pubkeyToAddress, } from "@cosmjs/amino"; import { Account, StargateClient } from "@cosmjs/stargate"; +import { createDbMultisig, getDbMultisig } from "./api"; import { checkAddress, explorerLinkAccount } from "./displayHelpers"; -import { requestJson } from "./request"; - -export interface CreateMultisigAccountResponse { - readonly address: string; -} /** * Turns array of compressed Secp256k1 pubkeys @@ -39,25 +36,18 @@ export const createMultisigFromCompressedSecp256k1Pubkeys = async ( const multisigAddress = pubkeyToAddress(multisigPubkey, addressPrefix); // save multisig to relational offchain database - const multisig = { + const multisig: DbMultisigDraft = { address: multisigAddress, pubkeyJSON: JSON.stringify(multisigPubkey), creator, chainId, }; - const { address }: CreateMultisigAccountResponse = await requestJson( - `/api/chain/${chainId}/multisig`, - { body: multisig }, - ); + const dbMultisigAddress = await createDbMultisig(multisig, chainId); - return address; + return dbMultisigAddress; }; -export interface GetMultisigAccountResponse { - readonly pubkeyJSON: string; -} - export type HostedMultisig = | { readonly hosted: "nowhere"; @@ -92,9 +82,7 @@ export const getHostedMultisig = async ( hostedMultisig = await (async () => { try { - const { pubkeyJSON }: GetMultisigAccountResponse = await requestJson( - `/api/chain/${chainId}/multisig/${multisigAddress}`, - ); + const { pubkeyJSON } = await getDbMultisig(multisigAddress, chainId); const pubkeyOnDb = JSON.parse(pubkeyJSON); return { hosted: "db", pubkeyOnDb }; diff --git a/lib/txMsgHelpers.ts b/lib/txMsgHelpers.ts index 2b176dd..97f84aa 100644 --- a/lib/txMsgHelpers.ts +++ b/lib/txMsgHelpers.ts @@ -1,4 +1,4 @@ -import { DbTransactionJsonObj } from "@/types/db"; +import { DbTransactionParsedDataJson } from "@/graphql"; import { MsgCodecs, MsgTypeUrl, MsgTypeUrls } from "@/types/txMsg"; import { EncodeObject } from "@cosmjs/proto-signing"; @@ -74,10 +74,10 @@ const importMsgFromJson = (msg: EncodeObject): EncodeObject => { throw new Error("Unknown msg type"); }; -export const dbTxFromJson = (txJson: string): DbTransactionJsonObj | null => { +export const dbTxFromJson = (txJson: string): DbTransactionParsedDataJson | null => { try { - const dbTx: DbTransactionJsonObj = JSON.parse(txJson); - dbTx.msgs = dbTx.msgs.map(importMsgFromJson); + const parsedDbTx: DbTransactionParsedDataJson = JSON.parse(txJson); + const dbTx = { ...parsedDbTx, msgs: parsedDbTx.msgs.map(importMsgFromJson) }; return dbTx; } catch (error) {