Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(ui): update packages and improve UX/UI #16

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions contract-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -13,11 +13,11 @@ crate-type = ["cdylib", "rlib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.7.0", features = ["legacy"] }

[dev-dependencies]
near-sdk = { version = "5.0.0", features = ["unit-testing"] }
near-workspaces = { version = "0.10.0", features = ["unstable"] }
near-sdk = { version = "5.7.0", features = ["unit-testing"] }
near-workspaces = { version = "0.16.0", features = ["unstable"] }
tokio = { version = "1.12.0", features = ["full"] }
serde_json = "1"

6 changes: 3 additions & 3 deletions contract-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Find all our documentation at https://docs.near.org
use near_sdk::store::UnorderedMap;
use near_sdk::store::IterableMap;
use near_sdk::{near, AccountId, NearToken, PanicOnDefault};

mod donation;
@@ -8,7 +8,7 @@ mod donation;
#[derive(PanicOnDefault)]
pub struct Contract {
pub beneficiary: AccountId,
pub donations: UnorderedMap<AccountId, NearToken>,
pub donations: IterableMap<AccountId, NearToken>,
}

#[near]
@@ -18,7 +18,7 @@ impl Contract {
pub fn init(beneficiary: AccountId) -> Self {
Self {
beneficiary,
donations: UnorderedMap::new(b"d"),
donations: IterableMap::new(b"d"),
}
}

32 changes: 24 additions & 8 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -12,22 +12,38 @@
"lint": "next lint"
},
"dependencies": {
"@near-wallet-selector/core": "^8.9.11",
"@near-wallet-selector/here-wallet": "^8.9.11",
"@near-wallet-selector/modal-ui": "^8.9.11",
"@near-wallet-selector/my-near-wallet": "^8.9.11",
"@near-js/providers": "^1.0.1",
"@near-wallet-selector/bitte-wallet": "^8.9.14",
"@near-wallet-selector/core": "^8.9.14",
"@near-wallet-selector/ethereum-wallets": "^8.9.14",
"@near-wallet-selector/here-wallet": "^8.9.14",
"@near-wallet-selector/ledger": "^8.9.14",
"@near-wallet-selector/meteor-wallet": "^8.9.14",
"@near-wallet-selector/modal-ui": "^8.9.14",
"@near-wallet-selector/my-near-wallet": "^8.9.14",
"@near-wallet-selector/near-mobile-wallet": "^8.9.14",
"@near-wallet-selector/sender": "^8.9.14",
"@near-wallet-selector/welldone-wallet": "^8.9.14",
"@web3modal/wagmi": "^5.1.11",
"bootstrap": "^5",
"bootstrap-icons": "^1.11.3",
"near-api-js": "^4.0.3",
"next": "14.2.3",
"near-api-js": "^5.0.1",
"next": "14.2.5",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"wagmi": "^2.13.3"
},
"overrides": {
"@near-wallet-selector/ethereum-wallets": {
"near-api-js": "4.0.3"
}
},
"resolutions": {
"near-api-js": "4.0.3"
},
"devDependencies": {
"eslint": "^8",
"encoding": "^0.1.13",
"eslint": "^9",
"eslint-config-next": "14.2.3"
}
}
42 changes: 21 additions & 21 deletions frontend/src/components/DonationBox.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { useContext } from "react";
import DonationForm from "./DonationForm";
import { NearContext } from '@/context';
import { NearContext } from "@/context";

const DonationBox = () => {
const { signedAccountId, wallet } = useContext(NearContext);
const DonationBox = ({ setMyDonation }) => {
const { signedAccountId } = useContext(NearContext);

return (
<div className="card mt-4">
<div className="p-3 text-center">
<h4>
<strong>Donate to</strong>
</h4>
</div>
<div className="bg-light p-3">
{signedAccountId ? (
<DonationForm />
) : (
<p className="mb-3">
Please # with your NEAR wallet to make a donation.
</p>
)}
</div>
</div>
);
return (
<div className="card mt-4">
<div className="p-3 text-center">
<h4>
<strong>Donate to</strong>
</h4>
</div>
<div className="bg-light p-3">
{signedAccountId ? (
<DonationForm setMyDonation={setMyDonation} />
) : (
<p className="mb-3">
Please # with your NEAR wallet to make a donation.
</p>
)}
</div>
</div>
);
};

export default DonationBox;
134 changes: 66 additions & 68 deletions frontend/src/components/DonationForm.jsx
Original file line number Diff line number Diff line change
@@ -4,78 +4,76 @@ import { useState, useContext } from "react";
import { NearContext } from "@/context";
import { DonationNearContract } from "@/config";

const DonationForm = () => {
const { wallet } = useContext(NearContext);
const [amount, setAmount] = useState(0);
const DonationForm = ({ setMyDonation }) => {
const { wallet } = useContext(NearContext);
const [amount, setAmount] = useState(0);

const setDonation = async (amount) => {
let data = await fetch(
"https://api.coingecko.com/api/v3/simple/price?ids=near&vs_currencies=usd",
).then((response) => response.json());
const near2usd = data["near"]["usd"];
const amount_in_near = amount / near2usd;
const rounded_two_decimals = Math.round(amount_in_near * 100) / 100;
setAmount(rounded_two_decimals);
};
const setDonation = async (amount) => {
let data = await fetch(
"https://api.coingecko.com/api/v3/simple/price?ids=near&vs_currencies=usd",
).then((response) => response.json());
const near2usd = data["near"]["usd"];
const amount_in_near = amount / near2usd;
const rounded_two_decimals = Math.round(amount_in_near * 100) / 100;
setAmount(rounded_two_decimals);
};

const handleSubmit = async (event) => {
event.preventDefault();
const handleSubmit = async (event) => {
event.preventDefault();

try {
let deposit = utils.format.parseNearAmount(amount.toString());
await wallet.callMethod({
contractId: DonationNearContract,
method: "donate",
deposit,
});
} catch (e) {
alert(
"Something went wrong! " +
"Maybe you need to sign out and back in? " +
"Check your browser console for more info.",
);
throw e;
}
};
let deposit = utils.format.parseNearAmount(amount.toString());

return (
<>
<div className="row mb-3">
{[10, 20, 50, 100].map((amount) => (
<div className="col-3" key={amount}>
<button
className="btn btn-outline-primary btn-block"
onClick={() => setDonation(amount)}
>
$ {amount}
</button>
</div>
))}
</div>
<form onSubmit={handleSubmit}>
<div className="mb-3">
<label htmlFor="donation" className="form-label">
Donation amount (in Ⓝ)
</label>
<div className="input-group">
<input
id="donation"
value={amount}
type="number"
min="0"
step="0.01"
onChange={(e) => setAmount(e.target.value)}
className="form-control"
/>
<span className="input-group-text">Ⓝ</span>
</div>
</div>
<button type="submit" className="btn btn-primary">
Donate
</button>
</form>
</>
);
wallet
.callMethod({
contractId: DonationNearContract,
method: "donate",
deposit,
})
.catch(() => {
setMyDonation(-Number(amount));
});

setMyDonation(amount);
};

return (
<>
<div className="row mb-3">
{[10, 20, 50, 100].map((amount) => (
<div className="col-3" key={amount}>
<button
className="btn btn-outline-primary btn-block"
onClick={() => setDonation(amount)}
>
$ {amount}
</button>
</div>
))}
</div>
<form onSubmit={handleSubmit}>
<div className="mb-3">
<label htmlFor="donation" className="form-label">
Donation amount (in Ⓝ)
</label>
<div className="input-group">
<input
id="donation"
value={amount}
type="number"
min="0"
step="0.01"
onChange={(e) => setAmount(e.target.value)}
className="form-control"
/>
<span className="input-group-text">Ⓝ</span>
</div>
</div>
<button type="submit" className="btn btn-primary">
Donate
</button>
</form>
</>
);
};

export default DonationForm;
Loading
Loading