diff --git a/src/cadence/scripts/GetFTDetails.ts b/src/cadence/scripts/GetFTDetails.ts new file mode 100644 index 0000000..2876b43 --- /dev/null +++ b/src/cadence/scripts/GetFTDetails.ts @@ -0,0 +1,29 @@ +import * as fcl from "@onflow/fcl"; + + +export type FTDetailType = Record + +export const getFTDetails = async () => { + const code = ` + import BasketTokenV2 from 0xf88c87364f7f298e + +pub fun main(): {String: BasketTokenV2.TokenInfo} { + let tokens = BasketTokenV2.getTokens() + return tokens +} + ` + const data = await fcl.query({ + cadence: code + }) + console.log(data) + return data +} diff --git a/src/cadence/scripts/GetUnderlyingTokens.ts b/src/cadence/scripts/GetUnderlyingTokens.ts new file mode 100644 index 0000000..c2b4204 --- /dev/null +++ b/src/cadence/scripts/GetUnderlyingTokens.ts @@ -0,0 +1,38 @@ +import * as fcl from "@onflow/fcl"; + +export const GetUnderlyingTokens = (contractName: string) => { +return ` +import ${contractName} from 0xf88c87364f7f298e + +pub struct UnderLyingTokenData { + pub let tokenIdentifier: String + pub let amount: UFix64 + + init(tokenIdentifier: String, amount: UFix64) { + self.tokenIdentifier = tokenIdentifier + self.amount = amount + } +} + +pub fun main(): [UnderLyingTokenData] { + let tokens = ${contractName}.getUnderlyingTokens() + let amounts = ${contractName}.getUnderlyingTokensAmount() + + let data: [UnderLyingTokenData] = [] + for i, _ in tokens { + let d = UnderLyingTokenData(tokenIdentifier :tokens[i], amount: amounts[i]) + data.append(d) + } + + return data +} +` +} + +export const getUnderlyingTokensData = async (contractName: string) => { + const data = await fcl.query({ + cadence: GetUnderlyingTokens(contractName) + }) + + return data +} \ No newline at end of file diff --git a/src/cadence/scripts/getTokenSupply.ts b/src/cadence/scripts/getTokenSupply.ts new file mode 100644 index 0000000..3ce5eda --- /dev/null +++ b/src/cadence/scripts/getTokenSupply.ts @@ -0,0 +1,16 @@ +import * as fcl from "@onflow/fcl"; + +export const getTokenTotalSupply = async (contractName: string, adminAddress: string) => { + const code = ` + import ${contractName} from ${adminAddress} + + pub fun main(): UFix64 { + return ${contractName}.totalSupply + } + ` + const data = await fcl.query({ + cadence: code + }) + + return data +} \ No newline at end of file diff --git a/src/pages/ExploreBasket.tsx b/src/pages/ExploreBasket.tsx index 03c7d0b..8e32f17 100644 --- a/src/pages/ExploreBasket.tsx +++ b/src/pages/ExploreBasket.tsx @@ -1,17 +1,44 @@ import Dashboard_Navbar from "../components/Dashboard_Navbar" import logo from '../assets/react.svg' -import { allTokens, getTokenBySymbol } from "../utils/getTokenDetails"; -import { useNavigate } from "react-router-dom"; -import { TokenDetails } from "./ExploreDashboard"; -import { useState } from "react"; +import { allTokens, getTokenByIdentifier, getTokenBySymbol } from "../utils/getTokenDetails"; +import { useNavigate, useParams } from "react-router-dom"; +// import { TokenDetails } from "./ExploreDashboard"; +import { useEffect, useState } from "react"; import IssueTokenModal from "../components/IssueModal"; +import { useRecoilValue } from "recoil"; +import { BasketData, basketsAtom } from "./ExploreDashboard"; +import { GetUnderlyingTokens, getUnderlyingTokensData } from "../cadence/scripts/GetUnderlyingTokens"; +import { ftTokens } from "../App"; +import RedeemTokenModal from "../components/RedeemModal"; + function ExploreBasket() { const [showIssueModal, setShowIssueModal] = useState(false) const [showRedeemModal, setShowRedeemModal] = useState(false) + const [basketDetails, setBasketDetails] = useState() + const ftTokenList = useRecoilValue(ftTokens) + + const baskets = useRecoilValue(basketsAtom) + const { contractName } = useParams() + + useEffect(() => { + if (contractName && baskets) + setBasketDetails(baskets.find((b) => b.basketContratName == contractName)) + }, [contractName]) + + // useEffect(() => { + // const getUnderlyingTokensNames = async (contractName: string) => { + // const data = await getUnderlyingTokensData(contractName) + // console.log(data) + // } + + // if (basketDetails) { + // getUnderlyingTokensNames(basketDetails.basketContratName) + // } + // }, [basketDetails]) const navigate = useNavigate() - const data = allTokens[0] + console.log(basketDetails) return ( <>
@@ -20,10 +47,10 @@ function ExploreBasket() {
navigate("/")} className="font-semibold text-base cursor-pointer mb-7 px-1 text-gray-400">{"<"} Back to explore
- +
-

{data.name}

-

{data.symbol}

+

{basketDetails?.basketName}

+

${basketDetails?.basketSymbol}

@@ -38,16 +65,16 @@ function ExploreBasket() {

- +
Underlying Tokens
{ - data.underlyingTokens.map(s => getTokenBySymbol(s)).map((token) => ( + basketDetails?.underlyingTokens.map(s => ({ amount: s.amount , token: getTokenByIdentifier(s.tokenIdentifier)})).map((t) => (
- -

10 {token?.symbol}

+ +

{t.amount} {t.token?.symbol}

)) } @@ -71,7 +98,7 @@ function ExploreBasket() { className="absolute top-0 left-0 w-screen h-screen bg-gray-600 opacity-50" >
- setShowIssueModal(false)} /> + setShowIssueModal(false)} />
)} @@ -82,7 +109,7 @@ function ExploreBasket() { className="absolute top-0 left-0 w-screen h-screen bg-gray-600 opacity-50" >
- setShowRedeemModal(false)} /> + setShowRedeemModal(false)} />
)} @@ -91,35 +118,35 @@ function ExploreBasket() { } -type TokenDetailCardProps = { - tokenDetails: TokenDetails -} +// type TokenDetailCardProps = { +// tokenDetails: TokenDetails +// } -const TokenDetailCard = ({ tokenDetails }: TokenDetailCardProps) => { - return ( - <> -
-
-
- -

{tokenDetails.name}

-
-
-

{tokenDetails.symbol}

-
- -

BTC

- -

BTC

- + 3 more -
-
-

{tokenDetails.supply}

-

{tokenDetails.company}

-
- - ) -} +// const TokenDetailCard = ({ tokenDetails }: TokenDetailCardProps) => { +// return ( +// <> +//
+//
+//
+// +//

{tokenDetails.name}

+//
+//
+//

{tokenDetails.symbol}

+//
+// +//

BTC

+// +//

BTC

+// + 3 more +//
+//
+//

{tokenDetails.supply}

+//

{tokenDetails.company}

+//
+// +// ) +// } type TokenIconProps = { symbol?: string, diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 1a9fcd4..29bdb56 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,5 +1,32 @@ import { baseToken } from "../globalTypes"; +import { singerAuth } from "./authz"; +export const AllTokens: Record = { + "A.e45c64ecfe31e465.stFlowToken": { + symbol: "stFlow", + name: "st Flow Token", + logo: "https://cdn.jsdelivr.net/gh/FlowFans/flow-token-list@main/token-registry/A.d6f80565193ad727.stFlowToken/logo.svg", + decimals: 8, + }, + "A.a983fecbed621163.FiatToken": { + symbol: "USDC", + name: "Fiat Token", + logo: "https://cdn.jsdelivr.net/gh/FlowFans/flow-token-list@main/token-registry/A.b19436aae4d94622.FiatToken/logo.svg", + decimals: 8, + }, + "A.e223d8a629e49c68.FUSD": { + symbol: "FUSD", + name: "Flow USD", + logo: "https://cdn.jsdelivr.net/gh/FlowFans/flow-token-list@main/token-registry/A.3c5959b568896393.FUSD/logo.svg", + decimals: 8, + }, + "A.40212f3e288efd03.MyToken": { + symbol: "MY", + name: "My Token", + logo: "https://cdn.jsdelivr.net/gh/FlowFans/flow-token-list@main/token-registry/A.348fe2042c8a70d8.MyToken/logo.svg", + + } +} export const tempTokens: baseToken[] = [ { @@ -36,4 +63,24 @@ export const tempTokens: baseToken[] = [ export const pinataTokenJWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiI2NTBhNDU2NS02ZjM0LTQ1YTYtYmVmOS04ZmIxMGE0NmVlN2EiLCJlbWFpbCI6ImdhdXJhdmRoYWxsYTE0OTNAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInBpbl9wb2xpY3kiOnsicmVnaW9ucyI6W3siaWQiOiJGUkExIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9LHsiaWQiOiJOWUMxIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9XSwidmVyc2lvbiI6MX0sIm1mYV9lbmFibGVkIjpmYWxzZSwic3RhdHVzIjoiQUNUSVZFIn0sImF1dGhlbnRpY2F0aW9uVHlwZSI6InNjb3BlZEtleSIsInNjb3BlZEtleUtleSI6Ijk2ZmUyNTE3MTViNTU4NGE0MTk1Iiwic2NvcGVkS2V5U2VjcmV0IjoiMWM1MjFiMDRiMjUyODM5MGU4MTkwNDU0NDk4MmYyNjJlMmZkY2JkNzc0YjI1YzI2YjQxM2RjM2VjODgzNzk1YSIsImlhdCI6MTY3NzQzNTY2N30.w8elVwSZ_U62af_MVKlVcawik9dQ-eLsoUVE4osqzlc" export const pinataApiKey = "96fe251715b5584a4195" -export const pinataApiSecret = "1c521b04b2528390e81904544982f262e2fdcbd774b25c26b413dc3ec883795a" \ No newline at end of file +export const pinataApiSecret = "1c521b04b2528390e81904544982f262e2fdcbd774b25c26b413dc3ec883795a" + +export const ACCESS_NODE_URLS = { + 'local': 'http://localhost:8888', + 'testnet': 'https://rest-testnet.onflow.org', + 'mainnet': 'https://rest-mainnet.onflow.org' +} + +export const BLOCK_EXPLORER_URLS = { + 'testnet': 'https://testnet.flowscan.org', + 'mainnet': 'https://flowscan.org' +} + +export const admin = "0xf88c87364f7f298e"; +export const adminKey ="88896b6ab053cba07d4835fb1bfa7db771871da5703798a03a60f1697f0771f3"; + +export function getTimestamp10MinutesAfterCurrentTime(): number { + const currentTime = new Date(); + const tenMinutesLater = new Date(currentTime.getTime() + 10 * 60 * 1000); // Adding 10 minutes in milliseconds + return Math.floor(tenMinutesLater.getTime() / 1000); // Converting to UNIX timestamp (seconds since epoch) + } \ No newline at end of file diff --git a/src/utils/getTokenDetails.ts b/src/utils/getTokenDetails.ts index 4f60c28..dfdd5c8 100644 --- a/src/utils/getTokenDetails.ts +++ b/src/utils/getTokenDetails.ts @@ -1,5 +1,5 @@ import { baseToken } from "../globalTypes" -import { tempTokens } from "./constants" +import { AllTokens, tempTokens } from "./constants" import index1 from "../images/index-1.svg"; import index2 from "../images/index-2.png"; import index3 from "../images/index-3.svg"; @@ -52,4 +52,8 @@ export const allTokens = [ export const getTokenBySymbol = (symbol: string): baseToken | undefined => { return tempTokens.find((token) => token.symbol == symbol) -} \ No newline at end of file +} + +export const getTokenByIdentifier = (identifier: any) => { + return AllTokens[identifier] +}