Skip to content

Commit

Permalink
fix: set the correct donate input amount
Browse files Browse the repository at this point in the history
  • Loading branch information
0xExp-po committed Sep 18, 2024
1 parent 5ddcd80 commit cfa4e55
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions dapp/src/components/DonateModal.astro
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@

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

document.addEventListener("astro:page-load", () => {
const amountButtons = document.querySelectorAll('.amount-button');
const amountInputContainer = document.getElementById('amount-input-container');
const platformTipInput = document.querySelector('input[type="number"]');
const platformTipText = document.querySelector('span:last-of-type');
const amountInput = document.getElementById('amount-input') as HTMLInputElement;
const platformTipInput = document.getElementById('tip-amount-input') as HTMLInputElement;
let selectedAmount = 10; // Default amount

amountButtons.forEach((button) => {
button.addEventListener('click', () => {
Expand All @@ -110,24 +111,19 @@ import { getAddressFromDomain } from "../service/SorobanDomainContractService";
button.classList.remove('bg-zinc-200','border-zinc-300', 'text-zinc-600');
button.classList.add('bg-zinc-800','border-zinc-800', 'text-white');

if (button.textContent?.trim() === 'Other') {
const buttonText = button.textContent?.trim();
if (buttonText === 'Other') {
amountInputContainer?.classList.remove('hidden');
amountInputContainer?.classList.add('flex');
selectedAmount = parseFloat(amountInput.value) || 0;
} else {
amountInputContainer?.classList.remove('flex');
amountInputContainer?.classList.add('hidden');
selectedAmount = buttonText === '100 XLM' ? 100 : 10;
}
});
});

if (platformTipInput) {
platformTipInput.addEventListener('input', (e) => {
if (platformTipText) {
platformTipText.textContent = `${(e.target as HTMLInputElement).value} XLM`;
}
});
}

const modal = document.getElementById('donate-modal');
const closeButton = document.getElementById('close-donate-modal');

Expand All @@ -140,17 +136,27 @@ import { getAddressFromDomain } from "../service/SorobanDomainContractService";
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 = amountInputContainer?.classList.contains('flex')
? parseFloat(amountInput.value) || 0
: selectedAmount;
const tipAmount = parseFloat(platformTipInput.value) || 0;

const amount = parseFloat(amountInput.value) || 0;
const tipAmount = parseFloat(tipAmountInput.value) || 0;
if (amount < 1) {
amountInput.style.border = '2px solid red';
const minAmountText = document.querySelector('#amount-input-container p') as HTMLElement;
if (minAmountText) {
minAmountText.style.color = 'red';
}
setTimeout(() => {
amountInput.style.border = '';
if (minAmountText) {
minAmountText.style.color = '';
}
}, 2000);
return;
}

const payment = await sendXLM(amount.toString(), tipAmount.toString(), import.meta.env.PUBLIC_TANSU_CONTRACT_ID);
const payment = await sendXLM(amount.toString(), import.meta.env.PUBLIC_TANSU_CONTRACT_ID, tipAmount.toString());
console.log("donate:", payment);
});
}
Expand Down

0 comments on commit cfa4e55

Please sign in to comment.