feature: filter pools by not expired
This commit is contained in:
1
app/javascript/src/abi/sousChef.json
Normal file
1
app/javascript/src/abi/sousChef.json
Normal file
File diff suppressed because one or more lines are too long
@@ -7,6 +7,9 @@ import { getApr } from "../../utils/apr";
|
|||||||
import { getPriceInBusd } from "../../utils/getPrice";
|
import { getPriceInBusd } from "../../utils/getPrice";
|
||||||
import { getTotalStaked } from "../../utils/getTotalStaked";
|
import { getTotalStaked } from "../../utils/getTotalStaked";
|
||||||
import { StakeOrderModal } from "./StakeOrderModal";
|
import { StakeOrderModal } from "./StakeOrderModal";
|
||||||
|
import { ethers } from "ethers";
|
||||||
|
import sousChef from "../../abi/sousChef.json"
|
||||||
|
import { getEndBlock } from "../../utils/getEndBlock";
|
||||||
|
|
||||||
type PoolProps = {
|
type PoolProps = {
|
||||||
pool: PoolConfig;
|
pool: PoolConfig;
|
||||||
@@ -29,6 +32,14 @@ export const Pool: FC<PoolProps> = ({ pool, balance }) => {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
|
const chef = new ethers.Contract(
|
||||||
|
pool.contractAddress[56],
|
||||||
|
new ethers.utils.Interface(sousChef),
|
||||||
|
provider
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
const stakingPrice = await getPriceInBusd(router, pool.stakingToken);
|
const stakingPrice = await getPriceInBusd(router, pool.stakingToken);
|
||||||
const earningPrice = await getPriceInBusd(router, pool.earningToken);
|
const earningPrice = await getPriceInBusd(router, pool.earningToken);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
import { graphql } from "babel-plugin-relay/macro";
|
import { graphql } from "babel-plugin-relay/macro";
|
||||||
import React from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
import { useLazyLoadQuery } from "react-relay";
|
import { useLazyLoadQuery } from "react-relay";
|
||||||
|
|
||||||
import { pools } from "../../constants/Pools";
|
import { pools } from "../../constants/Pools";
|
||||||
|
import { useBsc } from "../../contexts/BscProvider";
|
||||||
|
import { PoolConfig } from "../../types";
|
||||||
import { Pool } from "./Pool";
|
import { Pool } from "./Pool";
|
||||||
|
import { ethers } from "ethers";
|
||||||
|
import sousChef from "../../abi/sousChef.json"
|
||||||
|
import { getEndBlock } from "../../utils/getEndBlock";
|
||||||
import type { PoolListingQuery } from "./__generated__/PoolListingQuery.graphql";
|
import type { PoolListingQuery } from "./__generated__/PoolListingQuery.graphql";
|
||||||
|
|
||||||
export const PoolListing = () => {
|
export const PoolListing = () => {
|
||||||
|
const {
|
||||||
|
provider
|
||||||
|
} = useBsc();
|
||||||
|
const [validPools, setValidPools] = useState<PoolConfig[]>([])
|
||||||
|
|
||||||
const { currentUser } = useLazyLoadQuery<PoolListingQuery>(
|
const { currentUser } = useLazyLoadQuery<PoolListingQuery>(
|
||||||
graphql`
|
graphql`
|
||||||
query PoolListingQuery {
|
query PoolListingQuery {
|
||||||
@@ -22,9 +32,43 @@ export const PoolListing = () => {
|
|||||||
|
|
||||||
const balance = currentUser?.balance.amount ?? "0";
|
const balance = currentUser?.balance.amount ?? "0";
|
||||||
|
|
||||||
|
const getChef = (pool: PoolConfig) => {
|
||||||
|
return new ethers.Contract(
|
||||||
|
pool.contractAddress[56],
|
||||||
|
new ethers.utils.Interface(sousChef),
|
||||||
|
provider
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async() => {
|
||||||
|
const blockNumber = await provider.getBlockNumber()
|
||||||
|
console.log(blockNumber)
|
||||||
|
const valids: PoolConfig[] = []
|
||||||
|
|
||||||
|
for(let pool of pools) {
|
||||||
|
if(pool.sousId === 0) {
|
||||||
|
valids.push(pool)
|
||||||
|
setValidPools([...valids])
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const chef = getChef(pool)
|
||||||
|
const endBlock = await getEndBlock(chef)
|
||||||
|
if(endBlock >= blockNumber) {
|
||||||
|
valids.push(pool)
|
||||||
|
setValidPools([...valids])
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 place-items-center w-full gap-8 py-4 -mt-16 overflow-x-hidden">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 place-items-center w-full gap-8 py-4 -mt-16 overflow-x-hidden">
|
||||||
{pools
|
{validPools
|
||||||
.filter((pool) => !pool.isFinished)
|
.filter((pool) => !pool.isFinished)
|
||||||
.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
|
.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
|
||||||
.map((pool) => (
|
.map((pool) => (
|
||||||
|
|||||||
14
app/javascript/src/utils/getEndBlock.ts
Normal file
14
app/javascript/src/utils/getEndBlock.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
import type { Contract } from "ethers";
|
||||||
|
import { ethers } from "ethers";
|
||||||
|
|
||||||
|
import { tokens } from "../constants/pancake/Tokens";
|
||||||
|
import type { Token } from "../constants/pancake/Tokens";
|
||||||
|
|
||||||
|
export const getEndBlock = async (sousChef: Contract) => {
|
||||||
|
try {
|
||||||
|
return sousChef.bonusEndBlock();
|
||||||
|
} catch {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
2
erd.svg
2
erd.svg
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
<!-- Generated by graphviz version 2.48.0 (0)
|
<!-- Generated by graphviz version 2.43.0 (0)
|
||||||
-->
|
-->
|
||||||
<!-- Title: XStake Pages: 1 -->
|
<!-- Title: XStake Pages: 1 -->
|
||||||
<svg width="606pt" height="674pt"
|
<svg width="606pt" height="674pt"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user