Skip to content

Commit

Permalink
Added Contract Calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ummarikram committed Dec 31, 2021
1 parent 90668d7 commit ed9ad0d
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import React from "react";
// reactstrap components
import { Spinner } from "reactstrap";

import logo from "./Amortize-load2.gif";
// import logo from "./Amortize-load2.gif";


// core components

export default function PageChange(props) {
return (
<div>
<img src={logo} alt="loading..." />
{/* <div className="page-transition-wrapper-div">
{/* <img src={logo} alt="loading..." /> */}
<div className="page-transition-wrapper-div">
<div className="page-transition-icon-wrapper mb-3">
<Spinner
color="white"
Expand All @@ -23,7 +23,7 @@ export default function PageChange(props) {
<h4 className="title text-white">
Loading page contents for: {props.path}
</h4>
</div> */}
</div>
</div>
);
}
100 changes: 100 additions & 0 deletions Front-End/nextjs-argon-dashboard-master/components/contractCalls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { networkType, myStxAddress, userSession } from "./auth";
import {
callReadOnlyFunction,
cvToJSON,
standardPrincipalCV,
stringAsciiCV,
bufferCV,
responseErrorCV,
responseOkCV,
trueCV,
falseCV,
uintCV,
intCV,
FungibleConditionCode,
makeStandardSTXPostCondition,
} from "@stacks/transactions";

import { openContractCall } from "@stacks/connect";

const ContractAddress = "ST2C20XGZBAYFZ1NYNHT1J6MGMM0EW9X7PFZZEXA6";

export default async function appCallReadOnlyFunction(optionsProps) {
if (!optionsProps)
return new Promise((resolve, reject) => reject("no arguments provided"));

const options = {
...optionsProps,
network: networkType(),
senderAddress: myStxAddress(),
};

return callReadOnlyFunction(options)
.then((response) => {
const responseJson = cvToJSON(response);

return new Promise((resolve, reject) => resolve(responseJson));
})
.catch((e) => {
return new Promise((resolve, reject) => reject(e));
});
}

async function appCallPublicFunction(optionsProps) {

if (!optionsProps)
return new Promise((resolve, reject) => reject("no arguments provided"));

const options = {
...optionsProps,
network: networkType(),
appDetails: {
name: "Amortize",
icon: window.location.origin + "/img/Logo.svg",
},
senderAddress: myStxAddress(),
};


openContractCall(options);

};

export async function LockEquity(beneficiary, unlock, amount) {

const postConditionAddress = myStxAddress();
const postConditionCode = FungibleConditionCode.GreaterEqual;
const postConditionAmount = uintCV(amount).value;
const postConditions = [
makeStandardSTXPostCondition(postConditionAddress, postConditionCode, postConditionAmount),
];

appCallPublicFunction({
contractAddress: "STYMF4ARBZEVT61CKV8RBQHC6NCGCAF7AQWH979K",
contractName: "lock",
functionName: "lock",
postConditions,
functionArgs: [
// enter all your function arguments here but cast them to CV first
standardPrincipalCV(beneficiary),
uintCV(unlock),
uintCV(amount)
],
});

};

export function AddBeneficiary(beneficiary) {
const functionArgs = [
standardPrincipalCV(beneficiary)
];

appCallPublicFunction("equity-multi-claim", "add-beneficiary", functionArgs);
}

export function ClaimEquity() {
const functionArgs = [
];

appCallPublicFunction("equity-multi-claim", "multi-claim", functionArgs);
}
Loading

0 comments on commit ed9ad0d

Please sign in to comment.