Skip to content

Commit

Permalink
Add register
Browse files Browse the repository at this point in the history
  • Loading branch information
tupui committed Aug 26, 2024
1 parent cb2e487 commit df4e0fb
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dapp/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
PUBLIC_SOROBAN_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
PUBLIC_SOROBAN_RPC_URL="https://soroban-testnet.stellar.org:443"

TANSU_CONTRACT_ID=
TANSU_CONTRACT_ID="CAP52ERGUZ65UNPHP36CQBHYUPEUG2TT4NPVEV7CREWRT7UCPD7PRWEE"
SOROBAN_DOMAIN_CONTRACT_ID="CDODLZIO3OY5ZBCNYQALDZWLW2NN533WIDZUDNW2NRWJGLTWSABGSMH7"

SOROBAN_ACCOUNT="alice"
SOROBAN_NETWORK="testnet"
1 change: 1 addition & 0 deletions dapp/src/components/GetCommit.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Loading from "./Loading.astro";
<div id="wrap-get-hash-button" class="space-y-8 md:w-full">
<button
data-project-get-hash
aria-controls="get-hash"
class="w-full py-5 bg-zinc-900 rounded-[14px] justify-center gap-2.5 inline-flex"
>
<span class="text-center text-white text-xl font-normal leading-7"
Expand Down
115 changes: 115 additions & 0 deletions dapp/src/components/RegisterProject.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
import Topic from "./Topic.astro";
import Loading from "./Loading.astro";
const SOROBAN_DOMAIN_CONTRACT_ID = import.meta.env.SOROBAN_DOMAIN_CONTRACT_ID;
---

<div class="relative flex flex-col items-center md:flex-row">
<Topic title="Register" description="Register a new project on-chain" />
</div>

<div
class="relative flex flex-col items-center md:flex-row my-6 bg-zinc-100 rounded-[45px]"
>
<div class="row items-center py-12 px-4 md:px-20 md:w-8/12 md:py-10">
<div class="space-y-8 md:w-full">

<label class="block mb-2 text-base font-medium text-black">
Maintainers
<input
type="text"
id="maintainers"
name="config_hash"
class="block p-3 w-full text-base text-black bg-white rounded-lg border shadow-sm focus:ring-black focus:border-black"
placeholder="List of maintainers' addresses as G...,G..."
required
/>
</label>

<label class="block mb-2 text-base font-medium text-black">
URL
<input
type="text"
id="config_url"
name="config_hash"
class="block p-3 w-full text-base text-black bg-white rounded-lg border shadow-sm focus:ring-black focus:border-black"
placeholder="Information file URL"
required
/>
</label>

<label class="block mb-2 text-base font-medium text-black">
Information file hash
<input
type="text"
id="config_hash"
name="config_hash"
class="block p-3 w-full text-base text-black bg-white rounded-lg border shadow-sm focus:ring-black focus:border-black"
placeholder="Information file hash"
required
minlength="40"
maxlength="40"
/>
</label>

<div id="wrap-register-button">
<button
data-register-project
aria-controls="register-project"
class="w-full py-5 bg-zinc-900 rounded-[14px] justify-center gap-2.5 inline-flex"
>
<span class="text-center text-white text-xl font-normal leading-7"
>Register on-chain</span
>
</button>
</div>
</div>
<div id="wrap-register-loader" class="hidden">
<Loading />
</div>
</div>
</div>

<script>
import {registerProject} from "./project";

const maintainers = document.getElementById(
"maintainers",
) as HTMLInputElement;

const config_url = document.getElementById(
"config_url",
) as HTMLInputElement;
const config_hash = document.getElementById(
"config_hash",
) as HTMLInputElement;

const wrap_loader = document.getElementById(
"wrap-register-loader",
) as HTMLDivElement;
const wrap_button = document.getElementById(
"wrap-register-button",
) as HTMLDivElement;
const button = document.querySelector(
"[data-register-project]",
) as HTMLButtonElement;

button.addEventListener("click", async () => {
wrap_loader.style.display = "block";
wrap_button.style.display = "none";
try {
const register_status = await registerProject(maintainers.value, config_url.value, config_hash.value, "CDODLZIO3OY5ZBCNYQALDZWLW2NN533WIDZUDNW2NRWJGLTWSABGSMH7");

wrap_loader.style.display = "none";
wrap_button.style.display = "block";
if (!register_status) {
alert("Project could not be registered! Please retry.");
} else {
wrap_button.innerHTML = "Project registered!";
}
} catch (e) {
console.error(e);
}
});
</script>
1 change: 1 addition & 0 deletions dapp/src/components/SetProject.astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const TANSU_CONTRACT_ID = import.meta.env.TANSU_CONTRACT_ID;
<div id="wrap-set-project-button">
<button
data-set-project
aria-controls="set-project"
class="w-full py-5 bg-zinc-900 rounded-[14px] justify-center gap-2.5 inline-flex"
>
<span class="text-center text-white text-xl font-normal leading-7"
Expand Down
41 changes: 40 additions & 1 deletion dapp/src/components/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,43 @@ async function commitHash(commit_hash: string): Promise<boolean> {
}
}

export { commitHash, getProjectHash, loadedProjectId, setProjectId };
async function registerProject(maintainers: string, config_url: string, config_hash: string, domain_contract_id: string): Promise<boolean> {
if (!projectState.project_id) {
alert("No project defined");
return false;
}
const publicKey = loadedPublicKey();

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

const maintainers_ = maintainers.split(",");

const tx = await Versioning.register({
// @ts-ignore
name: projectState.project_name,
maintainer: publicKey,
maintainers: maintainers_,
url: config_url,
hash: config_hash,
domain_contract_id: domain_contract_id,
});
try {
await tx.signAndSend({
signTransaction: async (xdr) => {
const { signedTxXdr } = await kit.signTransaction(xdr);
return signedTxXdr;
},
});
return true;
} catch (e) {
console.error(e);
return false;
}
}

export { commitHash, getProjectHash, loadedProjectId, registerProject, setProjectId };
5 changes: 5 additions & 0 deletions dapp/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/// <reference types="astro/client" />

interface ImportMetaEnv {
readonly SOROBAN_DOMAIN_CONTRACT_ID: string;
readonly TANSU_CONTRACT_ID: string;
readonly SOROBAN_NETWORK: string;
readonly SOROBAN_NETWORK_PASSPHRASE: string;
readonly SOROBAN_RPC_URL: string;
readonly SOROBAN_SOURCE_ACCOUNT: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
2 changes: 2 additions & 0 deletions dapp/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SetProject from "../components/SetProject.astro";
import GetCommit from "../components/GetCommit.astro";
import Commit from "../components/Commit.astro";
import Container from "../components/Container.astro";
import RegisterProject from "../components/RegisterProject.astro";
---

<script is:inline>
Expand All @@ -14,6 +15,7 @@ import Container from "../components/Container.astro";
<main class="space-y-20">
<Container>
<SetProject />
<RegisterProject />
<GetCommit />
<Commit />
</Container>
Expand Down

0 comments on commit df4e0fb

Please sign in to comment.