Skip to content

Commit

Permalink
Adding getRegistrationPrice feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Hide on bush authored and hide-on-bush-x committed Nov 2, 2022
1 parent c4bf96d commit 1bfd6a4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
39 changes: 38 additions & 1 deletion src/soulNames/create.ts
@@ -1,5 +1,42 @@
import Masa from "../masa";
import { PaymentMethod } from "../contracts";
import { ethers } from "ethers";

export const getRegistrationPrice = async (
masa: Masa,
soulName: string,
duration: number,
paymentMethod: PaymentMethod
) => {
const identityContracts = await masa.contracts.loadIdentityContracts();

let price;
const prices = await masa.contracts.service.price(
identityContracts,
soulName,
duration
);

switch (paymentMethod) {
case "eth":
price = ethers.utils.formatEther(prices.priceInETH);
break;
case "stable":
price = ethers.utils.formatUnits(prices.priceInStableCoin, 6);
price = Number.parseFloat(price).toFixed(2).toString();
break;
case "utility":
price = ethers.utils.formatUnits(prices.priceInUtilityToken);
price = Number.parseFloat(price).toFixed(2).toString();
break;
default:
price = prices.priceInETH;
}

console.log(`Soulname price is ${price} ${paymentMethod}.`);

return price;
};

const purchaseSoulname = async (
masa: Masa,
Expand Down Expand Up @@ -30,7 +67,7 @@ const purchaseSoulname = async (
const result = await tx.wait();

const purchasedEvent = result.events?.find(
(e) => e.event === "SoulNamePurchased"
(e: any) => e.event === "SoulNamePurchased"
);

let tokenId;
Expand Down
7 changes: 6 additions & 1 deletion src/soulNames/soulNames.ts
Expand Up @@ -2,10 +2,15 @@ import { BigNumber } from "ethers";
import { PaymentMethod } from "../contracts";
import Masa from "../masa";
import { burnSoulName } from "./burn";
import { createSoulName } from "./create";
import { createSoulName, getRegistrationPrice } from "./create";
import { listSoulnames, loadSoulNamesByIdentityId } from "./list";

export const soulNames = (masa: Masa) => ({
getRegistrationPrice: (
soulName: string,
duration: number,
paymentMethod: PaymentMethod
) => getRegistrationPrice(masa, soulName, duration, paymentMethod),
list: (address?: string) => listSoulnames(masa, address),
loadSoulNamesByIdentityId: (identityId: BigNumber) =>
loadSoulNamesByIdentityId(masa, identityId),
Expand Down

0 comments on commit 1bfd6a4

Please sign in to comment.