Adapt lib to new types
This commit is contained in:
+7
-19
@@ -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 };
|
||||
|
||||
+4
-4
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user