axios reassignment bug fix
This commit is contained in:
@@ -84,10 +84,10 @@ class MultiSigForm extends React.Component {
|
||||
compressedPubkeys,
|
||||
this.state.threshold
|
||||
);
|
||||
this.props.router.push(`/multi/${multisigAddress}`);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log("Failed to creat multisig: ", error);
|
||||
}
|
||||
this.props.router.push(`/multi/${multisigAddress}`);
|
||||
};
|
||||
|
||||
render() {
|
||||
|
||||
@@ -68,6 +68,8 @@ export default class TransactionSigning extends React.Component {
|
||||
this.props.tx.memo,
|
||||
signerData
|
||||
);
|
||||
// save body bytes to the tx
|
||||
// save/create the signature in the db
|
||||
console.log(bodyBytes, signatures);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
+37
-7
@@ -1,10 +1,37 @@
|
||||
import axios from "axios";
|
||||
|
||||
// Graphql base request for Faunadb
|
||||
const graphqlReq = axios;
|
||||
graphqlReq.defaults.baseURL = "https://graphql.fauna.com/graphql";
|
||||
graphqlReq.defaults.headers.common = {
|
||||
Authorization: `Bearer ${process.env.FAUNADB_SECRET}`,
|
||||
const graphqlReq = axios.create({
|
||||
baseURL: "https://graphql.fauna.com/graphql",
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.FAUNADB_SECRET}`,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates multisig record in faunadb
|
||||
*
|
||||
* @param {object} multisig an object with address (string) and pubkey JSON
|
||||
* @return Returns async function that makes a request to the faunadb graphql endpoint
|
||||
*/
|
||||
const createMultisig = async (multisig) => {
|
||||
console.log(multisig);
|
||||
return graphqlReq({
|
||||
method: "POST",
|
||||
data: {
|
||||
query: `
|
||||
mutation {
|
||||
createMultisig(data: {
|
||||
address: "${multisig.address}"
|
||||
pubkeyJSON: ${JSON.stringify(multisig.pubkeyJSON)}
|
||||
}) {
|
||||
_id
|
||||
address
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -82,13 +109,16 @@ const findTransactionByID = async (id) => {
|
||||
* @param {object} transaction The base transaction
|
||||
* @return Returns async function that makes a request to the faunadb graphql endpoint
|
||||
*/
|
||||
const createSignature = async (transaction) => {
|
||||
const createSignature = async (signature, transactionId) => {
|
||||
return graphqlReq({
|
||||
method: "POST",
|
||||
data: {
|
||||
query: `
|
||||
mutation {
|
||||
createTransaction(data: {dataJSON: ${JSON.stringify(transaction)}}) {
|
||||
createSignature(data: {
|
||||
transaction: {connect: ${transactionId}},
|
||||
dataJSON:
|
||||
}) {
|
||||
_id
|
||||
}
|
||||
}
|
||||
@@ -97,4 +127,4 @@ const createSignature = async (transaction) => {
|
||||
});
|
||||
};
|
||||
|
||||
export { getMultisig, createTransaction, findTransactionByID };
|
||||
export { createMultisig, getMultisig, createTransaction, findTransactionByID };
|
||||
|
||||
+20
-16
@@ -16,23 +16,27 @@ const createMultisigFromCompressedSecp256k1Pubkeys = async (
|
||||
compressedPubkeys,
|
||||
threshold
|
||||
) => {
|
||||
let pubkeys = compressedPubkeys.map((compressedPubkey) => {
|
||||
return {
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
value: compressedPubkey,
|
||||
try {
|
||||
let pubkeys = compressedPubkeys.map((compressedPubkey) => {
|
||||
return {
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
value: compressedPubkey,
|
||||
};
|
||||
});
|
||||
const multisigPubkey = createMultisigThresholdPubkey(pubkeys, threshold);
|
||||
const multisigAddress = pubkeyToAddress(multisigPubkey, "cosmos");
|
||||
|
||||
// save multisig to fauna
|
||||
const multisig = {
|
||||
address: multisigAddress,
|
||||
pubkeyJSON: JSON.stringify(multisigPubkey),
|
||||
};
|
||||
});
|
||||
|
||||
const multisigPubkey = createMultisigThresholdPubkey(pubkeys, threshold);
|
||||
const multisigAddress = pubkeyToAddress(multisigPubkey, "cosmos");
|
||||
|
||||
// save multisig to fauna
|
||||
const multisig = {
|
||||
address: multisigAddress,
|
||||
pubkeyJSON: JSON.stringify(multisigPubkey),
|
||||
};
|
||||
await axios.post("/api/multisig", multisig);
|
||||
return multisigAddress;
|
||||
const res = await axios.post("/api/multisig", multisig);
|
||||
console.log(res.data);
|
||||
return res.data.address;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
import faunadb from "faunadb";
|
||||
import { createMultisig } from "../../../lib/graphqlHelpers";
|
||||
|
||||
export default async function (req, res) {
|
||||
return new Promise(async (resolve) => {
|
||||
switch (req.method) {
|
||||
case "POST":
|
||||
const q = faunadb.query;
|
||||
const client = new faunadb.Client({
|
||||
secret: process.env.FAUNADB_SECRET,
|
||||
});
|
||||
try {
|
||||
const data = req.body;
|
||||
console.log("Function `createMultisig` invoked", data);
|
||||
const multisig = {
|
||||
data: data,
|
||||
};
|
||||
const faunaRes = await client.query(
|
||||
q.Create(q.Collection("Multisig"), multisig)
|
||||
);
|
||||
console.log("success", faunaRes);
|
||||
res.status(200).send(faunaRes);
|
||||
const saveRes = await createMultisig(data);
|
||||
console.log("success", saveRes.data);
|
||||
res.status(200).send(saveRes.data.data.createMultisig);
|
||||
return resolve();
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
Reference in New Issue
Block a user