Skip to content

Commit

Permalink
feat: implement donate function
Browse files Browse the repository at this point in the history
  • Loading branch information
0xExp-po committed Sep 18, 2024
1 parent 7187a38 commit c15c2c4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dapp/src/components/DonateModal.astro
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
</div>

<script>
import { sendXLM } from "../service/PaymentService";
import { getAddressFromDomain } from "../service/SorobanDomainContractService";

document.addEventListener("astro:page-load", () => {
const amountButtons = document.querySelectorAll('.amount-button');
const amountInputContainer = document.getElementById('amount-input-container');
Expand Down Expand Up @@ -133,5 +136,23 @@
modal.classList.add('hidden');
});
}

const contributeButton = document.getElementById('contribute-button');
if (contributeButton) {
contributeButton.addEventListener('click', async () => {
console.log('Contribute button clicked');
const domainAddress = await getAddressFromDomain("tansu");
console.log("domainAddress:", domainAddress);

const amountInput = document.getElementById('amount-input') as HTMLInputElement;
const tipAmountInput = document.getElementById('tip-amount-input') as HTMLInputElement;

const amount = parseFloat(amountInput.value) || 0;
const tipAmount = parseFloat(tipAmountInput.value) || 0;

const payment = await sendXLM(amount.toString(), tipAmount.toString(), import.meta.env.PUBLIC_TANSU_CONTRACT_ID);
console.log("donate:", payment);
});
}
});
</script>
28 changes: 28 additions & 0 deletions dapp/src/service/SorobanDomainContractService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Record } from '@creit.tech/sorobandomains-sdk';
import { Domain404Error } from '@creit.tech/sorobandomains-sdk';
import sdk from '../contracts/soroban_domain_sdk';

async function getAddressFromDomain (
domainName: string,
) {
try {
const domainRecord: Record = await sdk.searchDomain({ domain: domainName });
return domainRecord;
} catch (e) {
if (e instanceof Error && e.name === Domain404Error.name) {
return {
"error": true,
"message": "SDK error",
}
} else {
return {
"error": true,
"message": "Simulation error",
}
}
}
}

export {
getAddressFromDomain,
}

0 comments on commit c15c2c4

Please sign in to comment.