Skip to content

Commit

Permalink
Fix state with MPA
Browse files Browse the repository at this point in the history
  • Loading branch information
tupui committed Sep 2, 2024
1 parent a9f2403 commit 698f13e
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 130 deletions.
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ repos:
language: rust
pass_filenames: false
entry: cargo fmt --all --check
- id: dapp
name: dApp prettier
language: node
pass_filenames: false
entry: cd dapp && bun prettier . --write
- id: website
name: website prettier
language: node
pass_filenames: false
entry: cd website && yarn format:mdx
# - id: dapp
# name: dApp prettier
# language: node
# pass_filenames: false
# entry: bun prettier . --write
# - id: website
# name: website prettier
# language: node
# pass_filenames: false
# entry: yarn format:mdx

# our custom action
- id: soroban-versioning
Expand Down
3 changes: 2 additions & 1 deletion dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build": "astro check && astro build",
"dev": "astro dev",
"preview": "astro preview",
"start": "astro dev"
"start": "astro dev",
"linter": "prettier --write ."
},
"type": "module",
"version": "0.0.1",
Expand Down
54 changes: 28 additions & 26 deletions dapp/src/components/Commit.astro
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,37 @@ import Loading from "./Loading.astro";
<script>
import { commitHash } from "./project";

const commit_hash = document.getElementById(
"commit_hash",
) as HTMLInputElement;
document.addEventListener("astro:page-load", () => {
const commit_hash = document.getElementById(
"commit_hash",
) as HTMLInputElement;

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

button.addEventListener("click", async () => {
wrap_loader.style.display = "block";
wrap_button.style.display = "none";
try {
const commit_status = await commitHash(commit_hash.value);
button.addEventListener("click", async () => {
wrap_loader.style.display = "block";
wrap_button.style.display = "none";
try {
const commit_status = await commitHash(commit_hash.value);

wrap_loader.style.display = "none";
wrap_button.style.display = "block";
if (!commit_status) {
alert("Hash could not be committed! Please retry.");
} else {
wrap_button.innerHTML = "Hash committed!";
wrap_loader.style.display = "none";
wrap_button.style.display = "block";
if (!commit_status) {
alert("Hash could not be committed! Please retry.");
} else {
wrap_button.innerHTML = "Hash committed!";
}
} catch (e) {
console.error(e);
}
} catch (e) {
console.error(e);
}
});
});
</script>
58 changes: 31 additions & 27 deletions dapp/src/components/ConnectWallet.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,39 @@
<script>
import { kit, setPublicKey } from "./stellar-wallets-kit";

const ellipsis = document.querySelector(
"#connect-wrap .ellipsis",
) as HTMLDivElement;
const button = document.querySelector("[data-connect]") as HTMLButtonElement;
document.addEventListener("astro:page-load", () => {
const ellipsis = document.querySelector(
"#connect-wrap .ellipsis",
) as HTMLDivElement;
const button = document.querySelector(
"[data-connect]",
) as HTMLButtonElement;

async function setLoggedIn(publicKey: string) {
ellipsis.innerHTML = `Signed in as ${publicKey}`;
ellipsis.title = publicKey;
}
async function setLoggedIn(publicKey: string) {
ellipsis.innerHTML = `Signed in as ${publicKey}`;
ellipsis.title = publicKey;
}

button.addEventListener("click", async () => {
button.disabled = true;
button.addEventListener("click", async () => {
button.disabled = true;

try {
await kit.openModal({
onWalletSelected: async (option) => {
try {
kit.setWallet(option.id);
const { address } = await kit.getAddress();
setPublicKey(address);
await setLoggedIn(address);
button.disabled = false;
} catch (e) {
console.error(e);
}
},
});
} catch (e) {
console.error(e);
}
try {
await kit.openModal({
onWalletSelected: async (option) => {
try {
kit.setWallet(option.id);
const { address } = await kit.getAddress();
setPublicKey(address);
await setLoggedIn(address);
button.disabled = false;
} catch (e) {
console.error(e);
}
},
});
} catch (e) {
console.error(e);
}
});
});
</script>
42 changes: 22 additions & 20 deletions dapp/src/components/GetCommit.astro
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,29 @@ import Loading from "./Loading.astro";
<script>
import { getProjectHash } from "./project";

const wrap_loader = document.getElementById(
"wrap-get-hash-loader",
) as HTMLDivElement;
const wrap_button = document.getElementById(
"wrap-get-hash-button",
) as HTMLDivElement;
const button = document.querySelector(
"[data-project-get-hash]",
) as HTMLButtonElement;
document.addEventListener("astro:page-load", () => {
const wrap_loader = document.getElementById(
"wrap-get-hash-loader",
) as HTMLDivElement;
const wrap_button = document.getElementById(
"wrap-get-hash-button",
) as HTMLDivElement;
const button = document.querySelector(
"[data-project-get-hash]",
) as HTMLButtonElement;

button.addEventListener("click", async () => {
wrap_loader.style.display = "block";
wrap_button.style.display = "none";
try {
const project_hash = await getProjectHash();
button.addEventListener("click", async () => {
wrap_loader.style.display = "block";
wrap_button.style.display = "none";
try {
const project_hash = await getProjectHash();

wrap_loader.style.display = "none";
wrap_button.style.display = "block";
wrap_button.innerHTML = `${project_hash}`;
} catch (e) {
console.error(e);
}
wrap_loader.style.display = "none";
wrap_button.style.display = "block";
wrap_button.innerHTML = `${project_hash}`;
} catch (e) {
console.error(e);
}
});
});
</script>
68 changes: 36 additions & 32 deletions dapp/src/components/RegisterProject.astro
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,46 @@ import Loading from "./Loading.astro";
import { navigate } from "astro:transitions/client";
const SOROBAN_DOMAIN_CONTRACT_ID = `${import.meta.env.PUBLIC_SOROBAN_DOMAIN_CONTRACT_ID}`;

const maintainers = document.getElementById(
"maintainers",
) as HTMLInputElement;
document.addEventListener("astro:page-load", () => {
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 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;
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";
button.addEventListener("click", async () => {
wrap_loader.style.display = "block";
wrap_button.style.display = "none";

const register_status = await registerProject(
maintainers.value,
config_url.value,
config_hash.value,
SOROBAN_DOMAIN_CONTRACT_ID,
);
const register_status = await registerProject(
maintainers.value,
config_url.value,
config_hash.value,
SOROBAN_DOMAIN_CONTRACT_ID,
);

wrap_loader.style.display = "none";
wrap_button.style.display = "block";
if (!register_status) {
alert("Project could not be registered! Please retry.");
} else {
navigate("/commit");
}
wrap_loader.style.display = "none";
wrap_button.style.display = "block";
if (!register_status) {
alert("Project could not be registered! Please retry.");
} else {
navigate("/commit");
}
});
});
</script>
30 changes: 16 additions & 14 deletions dapp/src/components/SetProject.astro
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ const TANSU_CONTRACT_ID = import.meta.env.PUBLIC_TANSU_CONTRACT_ID;
import { setProjectId } from "./project";
import { navigate } from "astro:transitions/client";

const project_name = document.getElementById(
"set-project",
) as HTMLInputElement;
const button = document.querySelector(
"[data-set-project]",
) as HTMLButtonElement;
document.addEventListener("astro:page-load", () => {
const project_name = document.getElementById(
"set-project",
) as HTMLInputElement;
const button = document.querySelector(
"[data-set-project]",
) as HTMLButtonElement;

button.addEventListener("click", async () => {
button.disabled = true;
try {
setProjectId(project_name.value);
navigate("/commit");
} catch (e) {
console.error(e);
}
button.addEventListener("click", async () => {
button.disabled = true;
try {
setProjectId(project_name.value);
navigate("/commit");
} catch (e) {
console.error(e);
}
});
});
</script>

0 comments on commit 698f13e

Please sign in to comment.