-
Notifications
You must be signed in to change notification settings - Fork 1
/
issue.tsx
27 lines (26 loc) · 1004 Bytes
/
issue.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { TransactionReceipt } from "@ethersproject/providers";
import { connect } from "@govtechsg/document-store";
import { Dispatch } from "react";
import { getSigner } from "./wallet";
export const issueCertificateHash = async (
documentStoreAddress: string,
certificateHash: string,
log?: Dispatch<string>
): Promise<TransactionReceipt | undefined> => {
try {
log ? log("Decrypting wallet.") : null;
const signer = await getSigner();
log ? log("Wallet successfully decrypted.") : null;
const documentStore = await connect(documentStoreAddress, signer);
log ? log(`Please confirm transaction at MetaMask extension.`) : null;
const transaction = await documentStore.issue(certificateHash);
log ? log(`Waiting for transaction ${transaction.hash} to be processed.`) : null;
return transaction.wait();
} catch (e) {
if (e instanceof Error) {
log ? log(e.message) : null;
} else {
log ? log("Unable to issue certificate") : null;
}
}
};