From 03656ca02d71cac4a4661f9996478ab94e2fc6f6 Mon Sep 17 00:00:00 2001 From: aidan-starke Date: Wed, 17 Nov 2021 14:38:18 +1300 Subject: [PATCH 1/7] show full owner address on hover --- .../[seriesId]/[serialNumber].tsx | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx b/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx index cc545fc..8cf80e4 100644 --- a/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx +++ b/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx @@ -96,6 +96,7 @@ const NFTDetail: React.FC<{}> = () => { React.useState(undefined); const [listingInfo, setListingInfo] = React.useState(); const [txMessage, setTxMessage] = React.useState(); + const [fullAddress, showFullAddress] = React.useState(false); React.useEffect(() => { if (!web3Context.api) { @@ -673,14 +674,27 @@ const NFTDetail: React.FC<{}> = () => { )} -
+
showFullAddress(true)} + onMouseLeave={() => showFullAddress(false)} + > Owner - - {nft.owner.substr(0, 8)}...{nft.owner.substr(-8)}{" "} - {web3Context.selectedAccount === nft.owner - ? "(You)" - : null} - + {fullAddress ? ( + + {nft.owner}{" "} + {web3Context.selectedAccount === nft.owner + ? "(You)" + : null} + + ) : ( + + {nft.owner.substr(0, 8)}...{nft.owner.substr(-8)}{" "} + {web3Context.selectedAccount === nft.owner + ? "(You)" + : null} + + )} {editableSerialNumber !== undefined && (
Date: Thu, 23 Dec 2021 12:51:48 +1300 Subject: [PATCH 2/7] add support for DAI/USDC, wip --- components/SupportedAssetsProvider.tsx | 12 ++++++ components/sell/Select.tsx | 7 ++++ components/wallet/ConnectedWalletModal.tsx | 3 ++ .../[seriesId]/[serialNumber].tsx | 39 +++++++++++++------ public/dai-logo.svg | 13 +++++++ public/ethereum-logo.svg | 1 + public/usdc-logo.svg | 5 +++ 7 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 public/dai-logo.svg create mode 100644 public/ethereum-logo.svg create mode 100644 public/usdc-logo.svg diff --git a/components/SupportedAssetsProvider.tsx b/components/SupportedAssetsProvider.tsx index e17551a..d9d737f 100644 --- a/components/SupportedAssetsProvider.tsx +++ b/components/SupportedAssetsProvider.tsx @@ -7,10 +7,20 @@ const SupportedAssetIds = process.env.NEXT_PUBLIC_SUPPORTED_ASSETS && process.env.NEXT_PUBLIC_SUPPORTED_ASSETS.split(","); +const tokenLogoURLs = { + CENNZ: "/cennznet-logo.svg", + CPAY: "/cpay-logo.svg", + cUSD: "/cusd-logo.svg", + ETH: "/ethereum-logo.svg", + DAI: "/dai-logo.svg", + USDC: "/usdc-logo.svg", +}; + export type SupportedAssetInfo = { id: number; symbol: string; decimals: number; + logoURL: string; }; const SupportedAssetsProvider = ({ children }) => { @@ -38,6 +48,7 @@ const SupportedAssetsProvider = ({ children }) => { id: Number(tokenId), symbol: u8aToString(symbol), decimals: decimalPlaces.toNumber(), + logoURL: tokenLogoURLs[u8aToString(symbol)], }; }); } else { @@ -47,6 +58,7 @@ const SupportedAssetsProvider = ({ children }) => { id: tokenId.toString(), symbol: u8aToString(symbol), decimals: decimalPlaces.toNumber(), + logoURL: tokenLogoURLs[symbol], }; }); } diff --git a/components/sell/Select.tsx b/components/sell/Select.tsx index 25b3166..d6ab87e 100644 --- a/components/sell/Select.tsx +++ b/components/sell/Select.tsx @@ -50,6 +50,13 @@ const TokenSelect: React.FC = ({ }} key={token.symbol} > +
+ CENNZ balance +
{token.symbol} diff --git a/components/wallet/ConnectedWalletModal.tsx b/components/wallet/ConnectedWalletModal.tsx index 28d4ad2..341ef71 100644 --- a/components/wallet/ConnectedWalletModal.tsx +++ b/components/wallet/ConnectedWalletModal.tsx @@ -26,6 +26,9 @@ const ConnectedWalletModal: React.FC = ({ CENNZ: "/cennznet-logo.svg", CPAY: "/cpay-logo.svg", cUSD: "/cusd-logo.svg", + ETH: "/ethereum-logo.svg", + DAI: "/dai-logo.svg", + USDC: "/usdc-logo.svg", }; return ( diff --git a/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx b/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx index 8cf80e4..2f7f5da 100644 --- a/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx +++ b/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx @@ -12,7 +12,9 @@ import Loader from "../../../../components/Loader"; import getMetadata from "../../../../utils/getMetadata"; import NFTRenderer from "../../../../components/nft/NFTRenderer"; import NFT from "../../../../components/nft"; +import TokenSelect from "../../../../components/sell/Select"; import axios from "axios"; +import { SupportedAssetInfo } from "../../../../components/SupportedAssetsProvider"; const buyWithFixedPrice = async (api, account, signer, listingId) => { const buyExtrinsic = await api.tx.nft.buy(listingId); @@ -97,6 +99,9 @@ const NFTDetail: React.FC<{}> = () => { const [listingInfo, setListingInfo] = React.useState(); const [txMessage, setTxMessage] = React.useState(); const [fullAddress, showFullAddress] = React.useState(false); + const [selectedToken, setSelectedToken] = React.useState( + supportedAssets[0] + ); React.useEffect(() => { if (!web3Context.api) { @@ -332,7 +337,10 @@ const NFTDetail: React.FC<{}> = () => { const paymentAsset = useMemo(() => { let paymentAssetId = undefined; if (listingInfo && listingInfo.fixedPriceInfo) { - paymentAssetId = listingInfo.fixedPriceInfo.paymentAsset; + paymentAssetId = + selectedToken === supportedAssets[0] + ? listingInfo.fixedPriceInfo.paymentAsset + : selectedToken.id; } if (listingInfo && listingInfo.auctionInfo) { paymentAssetId = listingInfo.auctionInfo.paymentAsset; @@ -647,16 +655,25 @@ const NFTDetail: React.FC<{}> = () => {
)} {listingInfo.fixedPriceInfo && ( -
- -
+ <> +
+ +
+
+ +
+ )}
)} diff --git a/public/dai-logo.svg b/public/dai-logo.svg new file mode 100644 index 0000000..2ae2e32 --- /dev/null +++ b/public/dai-logo.svg @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/public/ethereum-logo.svg b/public/ethereum-logo.svg new file mode 100644 index 0000000..45b3820 --- /dev/null +++ b/public/ethereum-logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/usdc-logo.svg b/public/usdc-logo.svg new file mode 100644 index 0000000..5dfea92 --- /dev/null +++ b/public/usdc-logo.svg @@ -0,0 +1,5 @@ + + + + + From fd433e26643d2300941255b34b20ca1569f64c84 Mon Sep 17 00:00:00 2001 From: aidan-starke Date: Mon, 10 Jan 2022 15:34:04 +1300 Subject: [PATCH 3/7] add support for ETH,DAI on Nikau --- .env.development | 2 +- components/Web3.tsx | 21 +++--- components/sell/FixedPrice.tsx | 30 ++++---- components/sell/TimedAuction.tsx | 28 ++++---- .../[seriesId]/[serialNumber].tsx | 72 ++++++++----------- utils/currencyHelpers.ts | 24 +++++++ 6 files changed, 91 insertions(+), 86 deletions(-) create mode 100644 utils/currencyHelpers.ts diff --git a/.env.development b/.env.development index 6e59c78..f3a004b 100644 --- a/.env.development +++ b/.env.development @@ -2,7 +2,7 @@ NEXT_PUBLIC_CENNZ_API_ENDPOINT=wss://nikau.centrality.me/public/ws NEXT_PUBLIC_NFT_STORAGE_API_KEY= NEXT_PUBLIC_PINATA_PIN_ENDPOINT=https://api.pinata.cloud NEXT_PUBLIC_PINATA_JWT= -NEXT_PUBLIC_SUPPORTED_ASSETS=16000,16001 +NEXT_PUBLIC_SUPPORTED_ASSETS=16000,16001,17001,17002 NEXT_PUBLIC_IMAGE_CDN=https://ik.imagekit.io/i4ryln6htzn NEXT_PUBLIC_PINATA_GATEWAY=https://litho.mypinata.cloud NEXT_FEATURED_COLLECTION_ID=226 diff --git a/components/Web3.tsx b/components/Web3.tsx index b24f497..7ad1795 100644 --- a/components/Web3.tsx +++ b/components/Web3.tsx @@ -81,10 +81,11 @@ const Web3: React.FC> = ({ children }) => { const tokenMap = {}; assets.forEach((asset) => { const [tokenId, { symbol, decimalPlaces }] = asset; - tokenMap[tokenId] = { - symbol: hexToString(symbol.toJSON()), - decimalPlaces: decimalPlaces.toNumber(), - }; + if (hexToString(symbol.toJSON()) !== "") + tokenMap[tokenId] = { + symbol: hexToString(symbol.toJSON()), + decimalPlaces: decimalPlaces.toNumber(), + }; }); const balanceSubscriptionArg = Object.keys(tokenMap).map( (tokenId, index) => { @@ -98,11 +99,13 @@ const Web3: React.FC> = ({ children }) => { const userBalances = {}; Object.keys(tokenMap).forEach((tokenId) => { const token = tokenMap[tokenId]; - userBalances[token.symbol] = { - balance: balances[token.index] / Math.pow(10, token.decimalPlaces), - tokenId, - decimalPlaces: token.decimalPlaces, - }; + if (balances[token.index] / Math.pow(10, token.decimalPlaces) > 0) + userBalances[token.symbol] = { + balance: + balances[token.index] / Math.pow(10, token.decimalPlaces), + tokenId, + decimalPlaces: token.decimalPlaces, + }; }); setBalances(userBalances); diff --git a/components/sell/FixedPrice.tsx b/components/sell/FixedPrice.tsx index 0eac0e0..4ee78f8 100644 --- a/components/sell/FixedPrice.tsx +++ b/components/sell/FixedPrice.tsx @@ -1,6 +1,5 @@ import React, { useCallback, useMemo } from "react"; import Link from "next/link"; - import Text from "../Text"; import Web3Context from "../Web3Context"; import Image from "next/image"; @@ -12,6 +11,7 @@ import { isValidAddressPolkadotAddress } from "../../utils/chainHelper"; import dayjs from "dayjs"; import { BLOCK_TIME } from "../../pages/sell"; import TxStatusModal from "./TxStatusModal"; +import { coinGeckoIds, convertToUSD } from "../../utils/currencyHelpers"; const sell = async ( api, @@ -78,23 +78,18 @@ const FixedPrice: React.FC = ({ }, [supportedAssets]); React.useEffect(() => { - const price = web3Context.cennzUSDPrice; - if ( - fixedPrice !== "-1" && - price && - paymentAsset && - paymentAsset.symbol === "CENNZ" - ) { - const conversionRateCal = Number(fixedPrice) * price; - let conversionRate = "-1"; - if (!isNaN(conversionRateCal)) { - conversionRate = conversionRateCal.toFixed(2); + if (fixedPrice !== "-1" && paymentAsset) { + const coinGeckoId = coinGeckoIds[paymentAsset.symbol]; + if (coinGeckoId) { + (async () => { + let converted = await convertToUSD(coinGeckoId, fixedPrice); + setConvertedRate(converted); + })(); + } else { + setConvertedRate("-1"); } - setConvertedRate(conversionRate); - } else if (paymentAsset && paymentAsset.symbol !== "CENNZ") { - setConvertedRate("-1"); } - }, [fixedPrice, paymentAsset, web3Context.cennzUSDPrice]); + }, [fixedPrice, paymentAsset]); const tokenId = useMemo(() => { if (web3Context.api) { @@ -123,6 +118,7 @@ const FixedPrice: React.FC = ({ } const priceInUnit = +price.value * 10 ** paymentAsset.decimals; + if (priceInUnit <= 0) { setError("Please provide a proper price"); return; @@ -159,7 +155,7 @@ const FixedPrice: React.FC = ({ tokenId, buyerAddress, paymentAsset.id, - priceInUnit, + String(priceInUnit), duration ); setTxMessage("New listing created"); diff --git a/components/sell/TimedAuction.tsx b/components/sell/TimedAuction.tsx index 6090202..a343943 100644 --- a/components/sell/TimedAuction.tsx +++ b/components/sell/TimedAuction.tsx @@ -11,6 +11,7 @@ import { SupportedAssetInfo } from "../SupportedAssetsProvider"; import dayjs from "dayjs"; import { BLOCK_TIME } from "../../pages/sell"; import TxStatusModal from "./TxStatusModal"; +import { coinGeckoIds, convertToUSD } from "../../utils/currencyHelpers"; const openAuction = async ( api, @@ -75,23 +76,18 @@ const TimedAuction: React.FC = ({ }, [supportedAssets]); React.useEffect(() => { - const price = web3Context.cennzUSDPrice; - if ( - reservedPrice !== "-1" && - price && - paymentAsset && - paymentAsset.symbol === "CENNZ" - ) { - const conversionRateCal = Number(reservedPrice) * price; - let conversionRate = "-1"; - if (!isNaN(conversionRateCal)) { - conversionRate = conversionRateCal.toFixed(2); + if (reservedPrice !== "-1" && paymentAsset) { + const coinGeckoId = coinGeckoIds[paymentAsset.symbol]; + if (coinGeckoId) { + (async () => { + let converted = await convertToUSD(coinGeckoId, reservedPrice); + setConvertedRate(converted); + })(); + } else { + setConvertedRate("-1"); } - setConvertedRate(conversionRate); - } else if (paymentAsset && paymentAsset.symbol !== "CENNZ") { - setConvertedRate("-1"); } - }, [reservedPrice, paymentAsset, web3Context.cennzUSDPrice]); + }, [reservedPrice, paymentAsset]); const tokenId = useMemo(() => { if (web3Context.api) { @@ -147,7 +143,7 @@ const TimedAuction: React.FC = ({ web3Context.signer, tokenId, paymentAsset.id, - priceInUnit, + String(priceInUnit), duration ); setModalState("success"); diff --git a/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx b/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx index 2f7f5da..d9e9374 100644 --- a/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx +++ b/pages/nft/[collectionId]/[seriesId]/[serialNumber].tsx @@ -1,7 +1,6 @@ import React, { useCallback, useEffect, useMemo } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; - import Web3Context from "../../../../components/Web3Context"; import Text from "../../../../components/Text"; import SupportedAssetsContext from "../../../../components/SupportedAssetsContext"; @@ -12,9 +11,9 @@ import Loader from "../../../../components/Loader"; import getMetadata from "../../../../utils/getMetadata"; import NFTRenderer from "../../../../components/nft/NFTRenderer"; import NFT from "../../../../components/nft"; -import TokenSelect from "../../../../components/sell/Select"; import axios from "axios"; import { SupportedAssetInfo } from "../../../../components/SupportedAssetsProvider"; +import { coinGeckoIds, convertToUSD } from "../../../../utils/currencyHelpers"; const buyWithFixedPrice = async (api, account, signer, listingId) => { const buyExtrinsic = await api.tx.nft.buy(listingId); @@ -99,9 +98,6 @@ const NFTDetail: React.FC<{}> = () => { const [listingInfo, setListingInfo] = React.useState(); const [txMessage, setTxMessage] = React.useState(); const [fullAddress, showFullAddress] = React.useState(false); - const [selectedToken, setSelectedToken] = React.useState( - supportedAssets[0] - ); React.useEffect(() => { if (!web3Context.api) { @@ -337,10 +333,7 @@ const NFTDetail: React.FC<{}> = () => { const paymentAsset = useMemo(() => { let paymentAssetId = undefined; if (listingInfo && listingInfo.fixedPriceInfo) { - paymentAssetId = - selectedToken === supportedAssets[0] - ? listingInfo.fixedPriceInfo.paymentAsset - : selectedToken.id; + paymentAssetId = listingInfo.fixedPriceInfo.paymentAsset; } if (listingInfo && listingInfo.auctionInfo) { paymentAssetId = listingInfo.auctionInfo.paymentAsset; @@ -370,24 +363,26 @@ const NFTDetail: React.FC<{}> = () => { if ( paymentAsset && paymentAsset.symbol && - paymentAsset.symbol === "CENNZ" && - listingInfo + listingInfo && + conversionRate === -1 ) { - const price = web3Context.cennzUSDPrice; - if (conversionRate === -1) { - try { - let conversionRateCal = - (listingInfo.valueForConversion / 10 ** paymentAsset.decimals) * - price; - conversionRateCal = Number(conversionRateCal.toFixed(2)); - setConversionRate(conversionRateCal); - } catch (e) { - console.log("Error setting conversion rate"); - } + try { + const coinGeckoId = coinGeckoIds[paymentAsset.symbol]; + (async () => { + let converted; + if (reservePrice === 0) { + converted = await convertToUSD(coinGeckoId, fixedPrice); + } else if (fixedPrice === 0) { + converted = await convertToUSD(coinGeckoId, reservePrice); + } + setConversionRate(+converted); + })(); + } catch (e) { + console.log("Error setting conversion rate"); } } //return undefined; - }, [listingInfo, paymentAsset, web3Context.cennzUSDPrice]); + }, [listingInfo, paymentAsset]); const endTime = useMemo(() => { if (listingInfo && web3Context.api) { @@ -460,7 +455,7 @@ const NFTDetail: React.FC<{}> = () => { web3Context.selectedAccount, web3Context.signer, listingInfo.listingId, - priceInUnit + String(priceInUnit) ); setTxMessage("Bid placed"); setModalState("success"); @@ -655,25 +650,16 @@ const NFTDetail: React.FC<{}> = () => {
)} {listingInfo.fixedPriceInfo && ( - <> -
- -
-
- -
- +
+ +
)} )} diff --git a/utils/currencyHelpers.ts b/utils/currencyHelpers.ts new file mode 100644 index 0000000..140abb6 --- /dev/null +++ b/utils/currencyHelpers.ts @@ -0,0 +1,24 @@ +import axios from "axios"; + +const coinGeckoIds = { + CENNZ: "centrality", + ETH: "ethereum", + USDC: "usd-coin", + DAI: "dai", +}; + +function convertToUSD(coinGeckoId, priceToConvert) { + let conversionRate = "-1"; + const coinGeckoUrl = `https://api.coingecko.com/api/v3/simple/price?ids=${coinGeckoId}&vs_currencies=usd`; + return axios.get(coinGeckoUrl).then(function (response) { + const { data } = response; + const price = data[coinGeckoId].usd; + const conversionRateCal = Number(priceToConvert) * price; + if (!isNaN(conversionRateCal)) { + conversionRate = conversionRateCal.toFixed(2); + } + return conversionRate; + }); +} + +export { coinGeckoIds, convertToUSD }; From 526c4d906ed74953af1b1047d5f5d0d3232f4be1 Mon Sep 17 00:00:00 2001 From: aidan-starke Date: Tue, 11 Jan 2022 08:18:01 +1300 Subject: [PATCH 4/7] add USDC for Nikau --- .env.development | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.env.development b/.env.development index f3a004b..8a6f29f 100644 --- a/.env.development +++ b/.env.development @@ -1,8 +1,8 @@ NEXT_PUBLIC_CENNZ_API_ENDPOINT=wss://nikau.centrality.me/public/ws -NEXT_PUBLIC_NFT_STORAGE_API_KEY= +NEXT_PUBLIC_NFT_STORAGE_API_KEY=4da6a75d1a04694efd83 NEXT_PUBLIC_PINATA_PIN_ENDPOINT=https://api.pinata.cloud -NEXT_PUBLIC_PINATA_JWT= -NEXT_PUBLIC_SUPPORTED_ASSETS=16000,16001,17001,17002 +NEXT_PUBLIC_PINATA_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiIyOTA1OTAzMi05NzAwLTQ5N2MtYmFmNC03ZjFhYmZjZmFjNmIiLCJlbWFpbCI6InN0YXJrZS5haWRhbkBnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwicGluX3BvbGljeSI6eyJyZWdpb25zIjpbeyJpZCI6IkZSQTEiLCJkZXNpcmVkUmVwbGljYXRpb25Db3VudCI6MX1dLCJ2ZXJzaW9uIjoxfSwibWZhX2VuYWJsZWQiOmZhbHNlfSwiYXV0aGVudGljYXRpb25UeXBlIjoic2NvcGVkS2V5Iiwic2NvcGVkS2V5S2V5IjoiNGRhNmE3NWQxYTA0Njk0ZWZkODMiLCJzY29wZWRLZXlTZWNyZXQiOiI3YmFmMWVhMzgwMmQzYTY4MzY1YjVhMzNhNzhiZDc1MzU3MDI5NDczZWFhOTM1ZmY2NTY4MGQwMTllYjc1ZWExIiwiaWF0IjoxNjQwMjA2OTg3fQ.jNY2VL_lXiZg3_aquHvo9yKvw-QA9TgBT8WyPMZbSPI +NEXT_PUBLIC_SUPPORTED_ASSETS=16000,16001,17001,17002,17004 NEXT_PUBLIC_IMAGE_CDN=https://ik.imagekit.io/i4ryln6htzn NEXT_PUBLIC_PINATA_GATEWAY=https://litho.mypinata.cloud NEXT_FEATURED_COLLECTION_ID=226 From c4ff1bb9683a9523b912b75b9832ec87985353d4 Mon Sep 17 00:00:00 2001 From: Aidan Starke <52016903+aidan-starke@users.noreply.github.com> Date: Tue, 11 Jan 2022 08:25:27 +1300 Subject: [PATCH 5/7] clear pinata keys --- .env.development | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.development b/.env.development index 8a6f29f..e52d404 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,7 @@ NEXT_PUBLIC_CENNZ_API_ENDPOINT=wss://nikau.centrality.me/public/ws -NEXT_PUBLIC_NFT_STORAGE_API_KEY=4da6a75d1a04694efd83 +NEXT_PUBLIC_NFT_STORAGE_API_KEY= NEXT_PUBLIC_PINATA_PIN_ENDPOINT=https://api.pinata.cloud -NEXT_PUBLIC_PINATA_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiIyOTA1OTAzMi05NzAwLTQ5N2MtYmFmNC03ZjFhYmZjZmFjNmIiLCJlbWFpbCI6InN0YXJrZS5haWRhbkBnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwicGluX3BvbGljeSI6eyJyZWdpb25zIjpbeyJpZCI6IkZSQTEiLCJkZXNpcmVkUmVwbGljYXRpb25Db3VudCI6MX1dLCJ2ZXJzaW9uIjoxfSwibWZhX2VuYWJsZWQiOmZhbHNlfSwiYXV0aGVudGljYXRpb25UeXBlIjoic2NvcGVkS2V5Iiwic2NvcGVkS2V5S2V5IjoiNGRhNmE3NWQxYTA0Njk0ZWZkODMiLCJzY29wZWRLZXlTZWNyZXQiOiI3YmFmMWVhMzgwMmQzYTY4MzY1YjVhMzNhNzhiZDc1MzU3MDI5NDczZWFhOTM1ZmY2NTY4MGQwMTllYjc1ZWExIiwiaWF0IjoxNjQwMjA2OTg3fQ.jNY2VL_lXiZg3_aquHvo9yKvw-QA9TgBT8WyPMZbSPI +NEXT_PUBLIC_PINATA_JWT= NEXT_PUBLIC_SUPPORTED_ASSETS=16000,16001,17001,17002,17004 NEXT_PUBLIC_IMAGE_CDN=https://ik.imagekit.io/i4ryln6htzn NEXT_PUBLIC_PINATA_GATEWAY=https://litho.mypinata.cloud From cd96806a1898404e811ac93b682d053dc627597b Mon Sep 17 00:00:00 2001 From: aidan-starke Date: Tue, 11 Jan 2022 08:28:02 +1300 Subject: [PATCH 6/7] remove CENNZusdPrice var from web3context --- components/Web3.tsx | 15 --------------- components/Web3Context.tsx | 1 - 2 files changed, 16 deletions(-) diff --git a/components/Web3.tsx b/components/Web3.tsx index 7ad1795..b804090 100644 --- a/components/Web3.tsx +++ b/components/Web3.tsx @@ -73,7 +73,6 @@ const Web3: React.FC> = ({ children }) => { React.useState(false); const [isRefresh, setIsRefresh] = React.useState(false); const [api, setAPI] = React.useState(null); - const [cennzUSDPrice, setCennzUSDPrice] = React.useState(null); const getAccountAssets = async (address: string) => { await api.isReady; @@ -237,19 +236,6 @@ const Web3: React.FC> = ({ children }) => { useEffect(() => { if (!wallet) { setWallet(store.get("CENNZNET-EXTENSION")); - if (cennzUSDPrice === null) { - try { - const coinGeckoUrl = - "https://api.coingecko.com/api/v3/simple/price?ids=centrality&vs_currencies=usd"; - axios.get(coinGeckoUrl).then(function (response) { - const { data } = response; - const price = data.centrality.usd; - setCennzUSDPrice(price); - }); - } catch (e) { - console.log("Error setting conversion rate"); - } - } } }); @@ -265,7 +251,6 @@ const Web3: React.FC> = ({ children }) => { accounts, selectedAccount, api, - cennzUSDPrice, }} > {children} diff --git a/components/Web3Context.tsx b/components/Web3Context.tsx index 5d330d5..9dc5eee 100644 --- a/components/Web3Context.tsx +++ b/components/Web3Context.tsx @@ -11,7 +11,6 @@ const Web3Context = React.createContext({ signer: null, accounts: null, api: null, - cennzUSDPrice: null, }); export default Web3Context; From af06bad33a67080c9db2bec547e65c95c7cf3047 Mon Sep 17 00:00:00 2001 From: aidan-starke Date: Tue, 11 Jan 2022 12:21:48 +1300 Subject: [PATCH 7/7] refactor tokenLogoURLs --- components/SupportedAssetsProvider.tsx | 10 +--------- components/sell/FixedPrice.tsx | 2 +- components/sell/TimedAuction.tsx | 2 +- components/wallet/ConnectedWalletModal.tsx | 11 +---------- .../nft/[collectionId]/[seriesId]/[serialNumber].tsx | 3 +-- public/cusd-logo.svg | 1 - utils/{currencyHelpers.ts => assetHelpers.ts} | 10 +++++++++- 7 files changed, 14 insertions(+), 25 deletions(-) delete mode 100644 public/cusd-logo.svg rename utils/{currencyHelpers.ts => assetHelpers.ts} (74%) diff --git a/components/SupportedAssetsProvider.tsx b/components/SupportedAssetsProvider.tsx index d9d737f..17e11b5 100644 --- a/components/SupportedAssetsProvider.tsx +++ b/components/SupportedAssetsProvider.tsx @@ -2,20 +2,12 @@ import React, { useEffect, useState } from "react"; import Web3Context from "./Web3Context"; import SupportedAssetsContext from "./SupportedAssetsContext"; import { u8aToString } from "@polkadot/util"; +import { tokenLogoURLs } from "../utils/assetHelpers"; const SupportedAssetIds = process.env.NEXT_PUBLIC_SUPPORTED_ASSETS && process.env.NEXT_PUBLIC_SUPPORTED_ASSETS.split(","); -const tokenLogoURLs = { - CENNZ: "/cennznet-logo.svg", - CPAY: "/cpay-logo.svg", - cUSD: "/cusd-logo.svg", - ETH: "/ethereum-logo.svg", - DAI: "/dai-logo.svg", - USDC: "/usdc-logo.svg", -}; - export type SupportedAssetInfo = { id: number; symbol: string; diff --git a/components/sell/FixedPrice.tsx b/components/sell/FixedPrice.tsx index 4ee78f8..b9fe266 100644 --- a/components/sell/FixedPrice.tsx +++ b/components/sell/FixedPrice.tsx @@ -11,7 +11,7 @@ import { isValidAddressPolkadotAddress } from "../../utils/chainHelper"; import dayjs from "dayjs"; import { BLOCK_TIME } from "../../pages/sell"; import TxStatusModal from "./TxStatusModal"; -import { coinGeckoIds, convertToUSD } from "../../utils/currencyHelpers"; +import { coinGeckoIds, convertToUSD } from "../../utils/assetHelpers"; const sell = async ( api, diff --git a/components/sell/TimedAuction.tsx b/components/sell/TimedAuction.tsx index a343943..8cd0995 100644 --- a/components/sell/TimedAuction.tsx +++ b/components/sell/TimedAuction.tsx @@ -11,7 +11,7 @@ import { SupportedAssetInfo } from "../SupportedAssetsProvider"; import dayjs from "dayjs"; import { BLOCK_TIME } from "../../pages/sell"; import TxStatusModal from "./TxStatusModal"; -import { coinGeckoIds, convertToUSD } from "../../utils/currencyHelpers"; +import { coinGeckoIds, convertToUSD } from "../../utils/assetHelpers"; const openAuction = async ( api, diff --git a/components/wallet/ConnectedWalletModal.tsx b/components/wallet/ConnectedWalletModal.tsx index 341ef71..c904875 100644 --- a/components/wallet/ConnectedWalletModal.tsx +++ b/components/wallet/ConnectedWalletModal.tsx @@ -5,6 +5,7 @@ import Modal from "../Modal"; import Text from "../Text"; import Web3Context from "../Web3Context"; import copyTextToClipboard from "../../utils/copyTextToClipboard"; +import { tokenLogoURLs } from "../../utils/assetHelpers"; interface Props { closeModal: () => void; @@ -21,16 +22,6 @@ const ConnectedWalletModal: React.FC = ({ 8 )}...${web3Context.selectedAccount.substr(-8)}`; - // web3Context.accounts - const tokenLogoURLs = { - CENNZ: "/cennznet-logo.svg", - CPAY: "/cpay-logo.svg", - cUSD: "/cusd-logo.svg", - ETH: "/ethereum-logo.svg", - DAI: "/dai-logo.svg", - USDC: "/usdc-logo.svg", - }; - return ( { const buyExtrinsic = await api.tx.nft.buy(listingId); diff --git a/public/cusd-logo.svg b/public/cusd-logo.svg deleted file mode 100644 index d095888..0000000 --- a/public/cusd-logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/utils/currencyHelpers.ts b/utils/assetHelpers.ts similarity index 74% rename from utils/currencyHelpers.ts rename to utils/assetHelpers.ts index 140abb6..6df5316 100644 --- a/utils/currencyHelpers.ts +++ b/utils/assetHelpers.ts @@ -1,5 +1,13 @@ import axios from "axios"; +const tokenLogoURLs = { + CENNZ: "/cennznet-logo.svg", + CPAY: "/cpay-logo.svg", + ETH: "/ethereum-logo.svg", + DAI: "/dai-logo.svg", + USDC: "/usdc-logo.svg", +}; + const coinGeckoIds = { CENNZ: "centrality", ETH: "ethereum", @@ -21,4 +29,4 @@ function convertToUSD(coinGeckoId, priceToConvert) { }); } -export { coinGeckoIds, convertToUSD }; +export { tokenLogoURLs, coinGeckoIds, convertToUSD };