Skip to content

Commit

Permalink
move generateAnchor to untils
Browse files Browse the repository at this point in the history
  • Loading branch information
Sworzen1 committed Mar 8, 2024
1 parent b43240f commit a7828f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
42 changes: 15 additions & 27 deletions govtool/frontend/src/context/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
} from "react";
import {
Address,
Anchor,
AnchorDataHash,
BigNum,
Certificate,
CertificatesBuilder,
Expand All @@ -33,7 +31,6 @@ import {
TransactionUnspentOutput,
TransactionUnspentOutputs,
TransactionWitnessSet,
URL,
Value,
VoteDelegation,
Voter,
Expand All @@ -59,20 +56,21 @@ import { PATHS } from "@consts";
import { CardanoApiWallet, VoterInfo, Protocol } from "@models";
import type { StatusModalState } from "@organisms";
import {
getPubDRepID,
WALLET_LS_KEY,
DELEGATE_TRANSACTION_KEY,
REGISTER_TRANSACTION_KEY,
checkIsMaintenanceOn,
DELEGATE_TO_KEY,
PROTOCOL_PARAMS_KEY,
DELEGATE_TRANSACTION_KEY,
generateAnchor,
getItemFromLocalStorage,
setItemToLocalStorage,
removeItemFromLocalStorage,
getPubDRepID,
openInNewTab,
PROTOCOL_PARAMS_KEY,
REGISTER_SOLE_VOTER_TRANSACTION_KEY,
REGISTER_TRANSACTION_KEY,
removeItemFromLocalStorage,
SANCHO_INFO_KEY,
setItemToLocalStorage,
VOTE_TRANSACTION_KEY,
checkIsMaintenanceOn,
REGISTER_SOLE_VOTER_TRANSACTION_KEY,
WALLET_LS_KEY,
} from "@utils";
import { getEpochParams, getTransactionStatus } from "@services";
import {
Expand Down Expand Up @@ -1096,9 +1094,7 @@ function CardanoProvider(props: Props) {
let dRepRegCert;
// If there is an anchor
if (cip95MetadataURL && cip95MetadataHash) {
const url = URL.new(cip95MetadataURL);
const hash = AnchorDataHash.from_hex(cip95MetadataHash);
const anchor = Anchor.new(url, hash);
const anchor = generateAnchor(cip95MetadataURL, cip95MetadataHash);
// Create cert object using one Ada as the deposit
dRepRegCert = DrepRegistration.new_with_anchor(
dRepCred,
Expand Down Expand Up @@ -1141,9 +1137,7 @@ function CardanoProvider(props: Props) {
let dRepUpdateCert;
// If there is an anchor
if (cip95MetadataURL && cip95MetadataHash) {
const url = URL.new(cip95MetadataURL);
const hash = AnchorDataHash.from_hex(cip95MetadataHash);
const anchor = Anchor.new(url, hash);
const anchor = generateAnchor(cip95MetadataURL, cip95MetadataHash);
// Create cert object using one Ada as the deposit
dRepUpdateCert = DrepUpdate.new_with_anchor(dRepCred, anchor);
} else {
Expand Down Expand Up @@ -1217,9 +1211,7 @@ function CardanoProvider(props: Props) {

let votingProcedure;
if (cip95MetadataURL && cip95MetadataHash) {
const url = URL.new(cip95MetadataURL);
const hash = AnchorDataHash.from_hex(cip95MetadataHash);
const anchor = Anchor.new(url, hash);
const anchor = generateAnchor(cip95MetadataURL, cip95MetadataHash);
// Create cert object using one Ada as the deposit
votingProcedure = VotingProcedure.new_with_anchor(
votingChoice,
Expand Down Expand Up @@ -1259,9 +1251,7 @@ function CardanoProvider(props: Props) {
const infoAction = InfoAction.new();
const infoGovAct = GovernanceAction.new_info_action(infoAction);
// Create an anchor
const anchorURL = URL.new(url);
const anchorHash = AnchorDataHash.from_hex(hash);
const anchor = Anchor.new(anchorURL, anchorHash);
const anchor = generateAnchor(url, hash);

const rewardAddr = RewardAddress.from_address(
Address.from_bech32(rewardAddress)
Expand Down Expand Up @@ -1315,9 +1305,7 @@ function CardanoProvider(props: Props) {
const treasuryGovAct =
GovernanceAction.new_treasury_withdrawals_action(treasuryAction);
// Create an anchor
const anchorURL = URL.new(url);
const anchorHash = AnchorDataHash.from_hex(hash);
const anchor = Anchor.new(anchorURL, anchorHash);
const anchor = generateAnchor(url, hash);

const rewardAddr = RewardAddress.from_address(
Address.from_bech32(rewardAddress)
Expand Down
9 changes: 9 additions & 0 deletions govtool/frontend/src/utils/generateAnchor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Anchor, AnchorDataHash, URL } from "@emurgo/cardano-serialization-lib-asmjs";

export const generateAnchor = (url: string, hash: string) => {
const metadataUrl = URL.new(url);
const urlHash = AnchorDataHash.from_hex(hash);
const anchor = Anchor.new(metadataUrl, urlHash);

return anchor;
};
1 change: 1 addition & 0 deletions govtool/frontend/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./callAll";
export * from "./checkIsMaintenanceOn";
export * from "./checkIsWalletConnected";
export * from "./formatDate";
export * from "./generateAnchor";
export * from "./getDRepID";
export * from "./getGovActionId";
export * from "./getLengthInBytes";
Expand Down

0 comments on commit a7828f4

Please sign in to comment.