Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interact with dao contract functions #104

Merged
merged 33 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dd2ed5b
chore: separate connected key and kit service
0xExp-po Dec 3, 2024
9946702
chore: check empty descriptions before submit
0xExp-po Dec 3, 2024
92c3af1
chore: add proposal name input
0xExp-po Dec 3, 2024
9ba0fca
chore: add create proposal function to new proposal page
0xExp-po Dec 3, 2024
8b7474c
fix: create proposal error
0xExp-po Dec 4, 2024
7886484
chore: add voting dates input
0xExp-po Dec 4, 2024
740f421
chore: update proposal data interface
0xExp-po Dec 4, 2024
2356f07
feat: fetch proposals from contract
0xExp-po Dec 4, 2024
677e55d
feat: fetch proposal data from contract
0xExp-po Dec 4, 2024
c37fc13
feat: implement vote function
0xExp-po Dec 4, 2024
e1cf39c
chore: define the response type, create contract error messages
0xExp-po Dec 4, 2024
c16daee
chore: add error handler to voting function
0xExp-po Dec 4, 2024
da95617
chore: change the response data type
0xExp-po Dec 4, 2024
e80c248
chore: add error handler to submit proposal function
0xExp-po Dec 4, 2024
820d203
chore: add error handler to commit hash function
0xExp-po Dec 4, 2024
bcac3df
chore: add error handler to register project function
0xExp-po Dec 4, 2024
ee71b0f
feat: add error handler to read contract functions
0xExp-po Dec 4, 2024
9713448
chore: remove demo proposal data
0xExp-po Dec 5, 2024
bd30995
fix: update check condition for proposal submit
0xExp-po Dec 5, 2024
773f2f5
chore: update contract response data type
0xExp-po Dec 6, 2024
d8a4955
chore: add process checker in submit proposal function
0xExp-po Dec 6, 2024
8a385b9
update stellar wallet kit version
0xExp-po Dec 9, 2024
473de08
chore: update submit proposal function
0xExp-po Dec 9, 2024
3b66ef1
fix: linting error
0xExp-po Dec 9, 2024
7258ee0
chore: add console log to check delegation
0xExp-po Dec 9, 2024
0bd0e37
Fix signing and sending
tupui Dec 9, 2024
08dd2f4
Merge branch 'main' of https://github.com/0xExp-po/soroban-versioning…
0xExp-po Dec 10, 2024
f13f3f3
Merge branch 'main' of https://github.com/0xExp-po/soroban-versioning…
0xExp-po Dec 11, 2024
970016c
feat: create challenge to submit proposal
0xExp-po Dec 11, 2024
3e8e2a6
fix: regular expression for markdown image
0xExp-po Dec 11, 2024
5e020db
chore: set delegation expire time as 1 min
0xExp-po Dec 11, 2024
3c1b4ab
chore: divide proof env data into two parts
0xExp-po Dec 12, 2024
0588b41
fix: linter error
0xExp-po Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dapp/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ SOROBAN_NETWORK="testnet | public"
PUBLIC_DEFAULT_FEE="100"
PUBLIC_DEFAULT_TIMEOUT=30

PUBLIC_VOTING_PERIOD=5 # in days

STORACHA_SING_PRIVATE_KEY=""
STORACHA_PROOF=""
4 changes: 2 additions & 2 deletions dapp/src/components/ConnectWallet.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

<script>
import { truncateMiddle } from "../utils/utils";
import { kit } from "./stellar-wallets-kit";
import {
initializeConnection,
kit,
loadedPublicKey,
setPublicKey,
} from "./stellar-wallets-kit";
} from "../service/walletService";

document.addEventListener("astro:page-load", () => {
initializeConnection();
Expand Down
56 changes: 52 additions & 4 deletions dapp/src/components/page/governance/ProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const ProposalForm: React.FC = () => {
const connectedAddress = useStore(connectedPublicKey);
const projectName = useStore(projectNameForGovernance);
const [projectMaintainers, setProjectMaintainers] = useState<string[]>([]);
const [proposalName, setProposalName] = useState("");

useEffect(() => {
setIsClient(true);
Expand Down Expand Up @@ -112,7 +113,31 @@ const ProposalForm: React.FC = () => {
},
};

const isDescriptionValid = (description: string) => {
return description.trim().split(/\s+/).length >= 3;
};

const submitProposal = async () => {
if (!proposalName) {
alert("Proposal name is required");
return;
}

if (!isDescriptionValid(approveDescription)) {
alert("Approved description must contain at least 3 words.");
return;
}

if (!isDescriptionValid(rejectDescription)) {
alert("Rejected description must contain at least 3 words.");
return;
}

if (!isDescriptionValid(cancelledDescription)) {
alert("Cancelled description must contain at least 3 words.");
return;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's more complicated. Only for approval it's a must to have a description. For reject and cancelled, description is only required if there is a XDR.

While we are here, if no XDR is provided or no description, then in the UI we don't need to show this specific outcome. I expect that a lot of proposals will just have an approve outcome and the rest will be empty. So we don't need to show empty outcomes.


if (!connectedAddress) {
alert("Please connect your wallet first");
return;
Expand Down Expand Up @@ -181,12 +206,25 @@ const ProposalForm: React.FC = () => {

const directoryCid = await client.uploadDirectory(files);

setIsLoading(false);
alert(
`Proposal submitted successfully! CID: ${getIpfsBasicLink(directoryCid.toString())}`,
const { createProposal } = await import("@service/WriteContractService");

const proposalId = await createProposal(
projectName,
proposalName,
directoryCid.toString(),
Date.now() + 86400000 * import.meta.env.PUBLIC_VOTING_PERIOD,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be configurable from the user side

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

);

window.location.href = `/governance?name=${projectName}`;
setIsLoading(false);
if (proposalId === -1) {
alert("Error submitting proposal");
} else {
alert(
`Proposal submitted successfully! Proposal ID: ${proposalId}, CID: ${getIpfsBasicLink(directoryCid.toString())}`,
);

window.location.href = `/governance?name=${projectName}`;
}
} catch (error) {
throw new Error("Error submitting proposal", {
cause: error,
Expand All @@ -196,6 +234,16 @@ const ProposalForm: React.FC = () => {

return (
<div>
<h3 className="text-base sm:text-lg md:text-2xl font-semibold py-2">
Proposal Name
</h3>
<input
type="text"
value={proposalName}
onChange={(e) => setProposalName(e.target.value)}
className="w-full p-2 border border-zinc-700 rounded-md focus:outline-none"
placeholder="Enter your proposal name here..."
/>
<h3 className="text-base sm:text-lg md:text-2xl font-semibold py-2">
Proposal Description
</h3>
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/components/page/project/Commit.astro
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import PrimaryButton from "../../utils/PrimaryButton.astro";
<script>
import { commitHash } from "../../../service/WriteContractService";
import { loadProjectInfo } from "../../../service/StateService";
import { loadedPublicKey } from "../../stellar-wallets-kit";
import { loadedPublicKey } from "../../../service/walletService";
import { latestCommit, projectInfoLoaded } from "../../../utils/store";

document.addEventListener("astro:page-load", () => {
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/components/page/project/ProjectInfo.astro
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ import DonateModal from "./DonateModal.astro";
<DonateModal />

<script>
import { loadedPublicKey } from "../../stellar-wallets-kit";
import { loadedPublicKey } from "../../../service/walletService";
import { updateConfig } from "../../../service/WriteContractService";
import { getProject } from "../../../service/ReadContractService";
import {
Expand Down
24 changes: 1 addition & 23 deletions dapp/src/components/stellar-wallets-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
FREIGHTER_ID,
StellarWalletsKit,
} from "@creit.tech/stellar-wallets-kit";
import { connectedPublicKey } from "utils/store";

const kit: StellarWalletsKit = new StellarWalletsKit({
modules: allowAllModules(),
Expand All @@ -12,25 +11,4 @@ const kit: StellarWalletsKit = new StellarWalletsKit({
selectedWalletId: FREIGHTER_ID,
});

const connectionState: { publicKey: string | undefined } = {
publicKey: undefined,
};

function loadedPublicKey(): string | undefined {
return connectionState.publicKey;
}

function setPublicKey(data: string): void {
connectionState.publicKey = data;
localStorage.setItem("publicKey", data);
connectedPublicKey.set(data);
}

function initializeConnection(): void {
const storedPublicKey = localStorage.getItem("publicKey");
if (storedPublicKey) {
setPublicKey(storedPublicKey);
}
}

export { kit, loadedPublicKey, setPublicKey, initializeConnection };
export { kit };
1 change: 1 addition & 0 deletions dapp/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface ImportMetaEnv {
readonly SOROBAN_NETWORK: string;
readonly PUBLIC_DEFAULT_FEE: string;
readonly PUBLIC_DEFAULT_TIMEOUT: number;
readonly PUBLIC_VOTING_PERIOD: number;
readonly STORACHA_SING_PRIVATE_KEY: string;
readonly STORACHA_PROOF: string;
}
Expand Down
3 changes: 2 additions & 1 deletion dapp/src/service/PaymentService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { kit, loadedPublicKey } from "../components/stellar-wallets-kit";
import { kit } from "../components/stellar-wallets-kit";
import { loadedPublicKey } from "./walletService";
import * as StellarSdk from "@stellar/stellar-sdk";

async function sendXLM(
Expand Down
42 changes: 40 additions & 2 deletions dapp/src/service/WriteContractService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { kit, loadedPublicKey } from "../components/stellar-wallets-kit";
import { kit } from "../components/stellar-wallets-kit";
import { loadedPublicKey } from "./walletService";
import Versioning from "../contracts/soroban_versioning";

import { loadedProjectId } from "./StateService";
Expand Down Expand Up @@ -123,4 +124,41 @@ async function updateConfig(
}
}

export { commitHash, registerProject, updateConfig };
async function createProposal(
project_key: string,
title: string,
ipfs: string,
voting_ends_at: number,
): Promise<number> {
const publicKey = loadedPublicKey();

if (!publicKey) {
alert("Please connect your wallet first");
return -1;
} else {
Versioning.options.publicKey = publicKey;
}

try {
const tx = await Versioning.create_proposal({
proposer: publicKey,
project_key: Buffer.from(project_key, "utf-8"),
title: title,
ipfs: ipfs,
voting_ends_at: BigInt(voting_ends_at),
});

const result = await tx.signAndSend({
signTransaction: async (xdr) => {
const { signedTxXdr } = await kit.signTransaction(xdr);
return signedTxXdr;
},
});
return result.result;
} catch (e) {
console.error(e);
return -1;
}
}

export { commitHash, registerProject, updateConfig, createProposal };
24 changes: 24 additions & 0 deletions dapp/src/service/walletService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { connectedPublicKey } from "utils/store";

const connectionState: { publicKey: string | undefined } = {
publicKey: undefined,
};

function loadedPublicKey(): string | undefined {
return connectionState.publicKey;
}

function setPublicKey(data: string): void {
connectionState.publicKey = data;
localStorage.setItem("publicKey", data);
connectedPublicKey.set(data);
}

function initializeConnection(): void {
const storedPublicKey = localStorage.getItem("publicKey");
if (storedPublicKey) {
setPublicKey(storedPublicKey);
}
}

export { loadedPublicKey, setPublicKey, initializeConnection };
Loading