Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/contracts/launchpad/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const ERR_112: &str =
pub const ERR_113: &str = "ERR_113: Listing can only be funded once";
pub const ERR_114: &str = "ERR_114: Cannot fund listing after sale start time";
pub const ERR_115: &str = "ERR_115: Intended project_owner did not authorize listing creation";

pub const ERR_116: &str = "ERR_116: Error checking allocation sold, division by zero";
/// Investor errors
pub const ERR_201: &str = "ERR_201: Storage deposit insufficient for this transaction";
pub const ERR_202: &str = "ERR_202: Storage deposited was less than minimum deposit";
Expand Down
15 changes: 11 additions & 4 deletions packages/contracts/launchpad/src/listing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,16 @@ impl Listing {
project_promise
}
ListingStatus::Funded => {
if env::block_timestamp() > self.final_sale_2_timestamp {
//Check All Allocations Sold and allow to withdraw funds
let all_allocation_sold = self.allocations_sold as u128
== (self
.total_amount_sale_project_tokens
.checked_div(self.token_allocation_size)
.unwrap_or_else(|| {
env::panic_str(ERR_116);
}));

if env::block_timestamp() > self.final_sale_2_timestamp || all_allocation_sold {
self.status = ListingStatus::SaleFinalized;
self.withdraw_project_funds()
} else {
Expand Down Expand Up @@ -493,9 +502,7 @@ impl Listing {
((self.token_allocation_size * self.fraction_cliff_release) / FRACTION_BASE) * allocations;
let final_release = self.token_allocation_size * allocations - initial_release - cliff_release;
let mut total_release = initial_release;
if timestamp >= self.cliff_timestamp
&& timestamp < self.end_cliff_timestamp
{
if timestamp >= self.cliff_timestamp && timestamp < self.end_cliff_timestamp {
total_release += (cliff_release * (timestamp - self.cliff_timestamp) as u128)
/ (self.end_cliff_timestamp - self.cliff_timestamp) as u128
} else if timestamp >= self.end_cliff_timestamp {
Expand Down
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@near-wallet-selector/core": "^7.0.3",
"@near-wallet-selector/meteor-wallet": "^7.0.3",
"@near-wallet-selector/near-wallet": "^7.0.3",
"@near-wallet-selector/sender": "^7.4.0",
"@near/apollo": "*",
"@near/ts": "*",
"@rollup/plugin-inject": "^4.0.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/no-children-prop */
import Big from "big.js";
import { isBefore, format } from "date-fns";
import { getUTCDate } from "@near/ts";
Expand Down
27 changes: 15 additions & 12 deletions packages/web/src/components/modules/launchpad/project-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,23 @@ export function ProjectInfo({

<div>
<div className="mb-[-4px]">
<span
className="text-white text-[24px] font-[800] tracking-[-0.04em]"
children={project_token_info?.name}
/>
<span className="text-white text-[24px] font-[800] tracking-[-0.04em]">
{project_token_info?.name}
</span>
</div>

<div>
<span
className="text-[20px] font-[600] text-white opacity-[0.5] leading-[6px] tracking-[-0.04em]"
children={project_token_info?.symbol}
/>
<span className="text-[20px] font-[600] text-white opacity-[0.5] leading-[6px] tracking-[-0.04em]">
{project_token_info?.symbol}
</span>
</div>
</div>
</div>

<div className="mb-[24px] pl-[54px] max-w-[622px]">
<span
children={description_project}
className="text-white text-[14px] font-[500]"
/>
<span className="text-white text-[14px] font-[500]">
{description_project}
</span>
</div>

<div className="flex justify-between pl-[54px]">
Expand All @@ -106,6 +103,9 @@ export function ProjectInfo({
<button
disabled={!!!website}
className="border border-[rgba(252,252,252,0.2)] py-[10px] px-[16px] rounded-[10px] flex items-center space-x-[4px] disabled:cursor-not-allowed hover:opacity-[0.8]"
onClick={() => {
window.open(website!, "_blank");
}}
>
<span className="font-[500] text-[14px] tracking-[-0.04em]">
Website
Expand All @@ -119,6 +119,9 @@ export function ProjectInfo({
<button
disabled={!!!whitepaper}
className="border border-[rgba(252,252,252,0.2)] py-[10px] px-[16px] rounded-[10px] flex items-center space-x-[4px] disabled:cursor-not-allowed hover:opacity-[0.8]"
onClick={() => {
window.open(whitepaper!, "_blank");
}}
>
<span className="font-[500] text-[14px] tracking-[-0.04em]">
Whitepaper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ export const ProjectInvestments = ({
<span
children={
accountId
? formatNumber(
allocationsAvailable.toNumber(),
project_token_info?.decimals
)
? allocationsAvailable.toNumber()
: CONNECT_WALLET_MESSAGE
}
className="font-[800] text-[24px] tracking-[-0.03em] text-[#E2E8F0]"
Expand Down
40 changes: 29 additions & 11 deletions packages/web/src/components/modules/launchpad/project-user-area.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
/* eslint-disable react/no-children-prop */
import Big from "big.js";
import { useMemo, useCallback } from "react";
Expand Down Expand Up @@ -32,8 +33,8 @@ export function ProjectUserArea({
listing_id,
price_token,
project_token,
price_token_info,
project_token_info,
price_token_info,
token_allocation_price,
open_sale_1_timestamp,
final_sale_2_timestamp,
Expand All @@ -51,11 +52,12 @@ export function ProjectUserArea({
const [tickets, setTickets] = useState(0);

const allocationsAvailable = useMemo(() => {
return new Big(investorAllowance ?? "0");
//TODO: Temp fix
return new Big(/* investorAllowance ?? */ "100000000000000000");
}, [investorAllowance]);

const onJoinProject = useCallback(
(amount: number) => {
async (amount: number) => {
if (typeof listing_id && price_token) {
buyTickets(
new Big(amount).mul(new Big(token_allocation_price || 0)).toString(),
Expand All @@ -69,6 +71,19 @@ export function ProjectUserArea({
[1, accountId, project_token, token_allocation_price]
);

/* async function TempFixJoinProject(amount: number) {
console.log("HERE");
if (typeof listing_id && price_token) {
await buyTickets(
new Big(amount).mul(new Big(token_allocation_price || 0)).toString(),
price_token,
listing_id,
accountId!,
selector
);
}
} */

const ticketsAmount = useMemo(() => {
return new Big(token_allocation_price! ?? 0).mul(
new Big(tickets.toString())
Expand Down Expand Up @@ -198,19 +213,23 @@ export function ProjectUserArea({
min={0}
value={tickets}
max={allocationsAvailable.toNumber()}
onChange={(value) => setTickets(value || 0)}
onChange={(value) => {
console.log(
"Allocation Balance:",
allocationsAvailable.toNumber()
);
console.log("input value:", value);
setTickets(value || 0);
}}
/>
</div>

<div>
{/* <div>
<span
children={`Your allocation balance: ${formatNumber(
allocationsAvailable.toNumber(),
project_token_info?.decimals
)}`}
children={`Your allocation balance: ${allocationsAvailable.toNumber()}`}
className="text-[14px] font-[600] tracking-[-0.03em] text-[rgba(255,255,255,0.75)]"
/>
</div>
</div> */}
</div>

<div className="bg-[rgba(252,252,252,0.2)] pl-[25px] pr-[19px] py-[18px] rounded-[20px] w-full flex justify-between items-center mb-[16px]">
Expand Down Expand Up @@ -256,7 +275,6 @@ export function ProjectUserArea({
For:{" "}
{formatNumber(
ticketsAmount,
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
new Big(price_token_info?.decimals! || "0")
)}{" "}
{price_token_info?.symbol}
Expand Down
11 changes: 5 additions & 6 deletions packages/web/src/components/shared/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ export function Header() {
/>
<div className="flex gap-x-4 items-center">
<JumpIcon />
<JumpTextIcon />
<div className="hidden sm:block">
<JumpTextIcon />
</div>
</div>

<div className="flex gap-x-6 items-center">
{/* GetTestnet Tokens Button */}
{testnetTokensButton}

{/* Wallet Button/Menu */}
<Wallet />

{/* Dark/Light Switch Button */}
{/* Dark/Light Switch Button */}
<Button
white
className="h-10 aspect-square p-0 hidden"
Expand All @@ -73,12 +73,11 @@ export function Header() {
{isStyleSchemeDark && <SunIcon className="h-3" />}
</Button>

{/* Mobile Hamburger Button */}
<Button white onClick={() => setIsOpen(true)} className="lg:hidden">
<Bars3Icon className="h-3.5" />
</Button>

<MobileNav isOpen={isOpen} onClose={() => setIsOpen(!isOpen)} />
<Wallet />
</div>
</header>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/components/shared/mobile-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ModalContent,
useColorModeValue,
} from "@chakra-ui/react";
import { Wallet } from "./wallet";
import { CloseIcon } from "@/assets/svg";
import { useTheme } from "@/hooks/theme";
import { useNavigate } from "react-router";
Expand Down
23 changes: 16 additions & 7 deletions packages/web/src/components/shared/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ import Big from "big.js";
import { CopyToClipboard } from "react-copy-to-clipboard";
import toast from "react-hot-toast";

const shortenAddress = (address: string, chars = 8): string =>
`${address.slice(0, chars)}...${address.slice(-chars)}`;
const shortenAddress = (address: string, chars = 8): string => {
if (!address) {
return "";
}
if (address.length <= chars * 2) {
return address;
}

return `${address.slice(0, chars)}...${address.slice(-chars)}`;
};

export const Wallet = () => {
const { token, xToken, accountId, toggleModal, signOut } =
Expand Down Expand Up @@ -54,20 +62,20 @@ export const Wallet = () => {
<Button
white
onClick={() => toggleModal()}
className="hidden md:flex text-3.5 font-semibold leading-4 tracking-tight text-purple gap-x-1"
className="font-semibold leading-4 tracking-tight text-purple gap-x-1"
>
<WalletIcon className="h-5" />
Connect Wallet
Connect
</Button>
);
}

return (
<Menu as="div" className="relative text-left hidden md:inline-block">
<Menu as="div" className="relative text-left inline-block">
<Menu.Button as="div">
<Button
white
className="hidden md:flex text-3.5 font-semibold leading-4 tracking-tight text-purple gap-x-1"
className="text-3.5 font-semibold leading-4 tracking-tight text-purple gap-x-1"
>
<span children={shortenAddress(accountId)} />

Expand All @@ -88,7 +96,8 @@ export const Wallet = () => {
as="div"
className="
absolute
right-0
right-0
max-w-[354px]
mt-2 w-[354px]
origin-top-right
rounded-[16px]
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/context/wallet-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setupWalletSelector } from "@near-wallet-selector/core";
import type { WalletSelector, AccountState } from "@near-wallet-selector/core";
import { setupNearWallet } from "@near-wallet-selector/near-wallet";
import { setupMeteorWallet } from "@near-wallet-selector/meteor-wallet";
/* import { setupSender } from "@near-wallet-selector/sender"; */
import { tokenMetadata } from "@/interfaces";
import { viewFunction } from "@/tools";

Expand Down Expand Up @@ -63,7 +64,7 @@ export const WalletSelectorContextProvider: React.FC<
const _selector = await setupWalletSelector({
network: import.meta.env.VITE_NEAR_NETWORK || "testnet",
debug: true,
modules: [setupNearWallet(), setupMeteorWallet()],
modules: [setupNearWallet(), setupMeteorWallet() /* setupSender() */],
});

const state = _selector.store.getState();
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/projects/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useLaunchPadProjectQuery } from "@near/apollo";
import { useNavigate, useParams } from "react-router";
import { BackButton } from "@/components/shared/back-button";
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.