Skip to content

Commit

Permalink
integrate marketplace contract in frontend, gallery page fetch curren…
Browse files Browse the repository at this point in the history
…t on sale NFTs
  • Loading branch information
EdwardsVO committed Apr 23, 2022
1 parent f777284 commit 1800490
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
28 changes: 25 additions & 3 deletions frontend/components/Gallery/GalleryInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,33 @@ import SearchBarDesktop from '../Searchbar/SearchBarDesktop';
import Token from '../../models/Token';
import { initContract } from '../near/near';
import { ViewGridIcon, ViewListIcon } from '../icons';
import Sale from '../../models/Sale';

export default function GalleryInfo() {
const [tokens, setTokens] = React.useState<Array<Token>>(null);
const [loaded, setLoaded] = React.useState<boolean>(false)
const [sales, setSales] = React.useState<Array<Sale>>(null);
const [searchBarTokens, setSearchBarTokens] =
React.useState<Array<Token>>(null);
const [page, setPage] = React.useState<number>(0);
const [view, setView] = React.useState('grid');


const getGalleryData = async () => {
const { contracts } = await initContract();
// @ts-ignore: Unreachable code error
var currentSales:Array<Sale> = await contracts.marketContract.get_sales_by_nft_contract_id({nft_contract_id: contracts.nftContract.contractId, from_index: "0", limit:10})
var currentTokens: Array<Token> = [];
currentSales.map(async token => {
// @ts-ignore: Unreachable code error
let tokenIterable = await contracts.nftContract.nft_token({token_id: token.token_id});
currentTokens.push(tokenIterable);
})
setTokens(currentTokens);
setLoaded(true);
//setSales(currentSales);
// setTokens(await contract.obtener_pagina_v2({ from_index: 0, limit: 16 }));

};

const initSearchBar = async () => {
Expand All @@ -28,7 +43,7 @@ export default function GalleryInfo() {
};

React.useEffect(() => {
//getGalleryData();
getGalleryData();
//initSearchBar();
}, []);

Expand Down Expand Up @@ -106,7 +121,10 @@ export default function GalleryInfo() {
: 'text-center md:grid md:grid-cols-3 md:gap-3 lg:grid lg:grid-cols-5 lg:gap-6'
} text-center`}
>
{tokens ? (
<button onClick={() => {console.log(tokens)}}>
Ver tokens
</button>
{tokens && loaded ? (
tokens.map((nft, i) => (
<div className={`${view === 'grid' ? '' : 'py-4 md:py-0'}`}>
<NFTGalleryPreview
Expand All @@ -121,7 +139,11 @@ export default function GalleryInfo() {
</div>
))
) : (
<div>Nothing to show yet...</div>
<div>Nothing to show yet...
<button onClick={()=> {console.log(sales)}}>
VER SALES
</button>
</div>
)}
</div>

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/near/near.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const initContract = async () => {
nearConfig.contractName[1], //1 for the marketplace contract
{
// View methods are read-only – they don't modify the state, but usually return some value
viewMethods: [],
viewMethods: ['get_supply_sales', 'get_supply_by_nft_contract_id', 'get_sales_by_nft_contract_id'],
// Change methods can modify the state, but you don't receive the returned value when called
changeMethods: [],
// Sender is the account ID to initialize transactions.
Expand Down
4 changes: 2 additions & 2 deletions frontend/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const nftContractName = process.env.CONTRACT_NAME || 'dev-1650414768928-98132935878888'
export const marketContractName = process.env.CONTRACT_NAME
export const nftContractName = process.env.CONTRACT_NAME || 'dev-1650414768928-98132935878888';
export const marketContractName = process.env.CONTRACT_NAME || 'dev-1650675719272-23920946077227';


export function getConfig(env: string) {
Expand Down
7 changes: 7 additions & 0 deletions frontend/models/Sale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default interface Sale {
account_id: string;
approval_id: string;
nft_contract_id: string;
token_id: string;
sale_conditions: string;
}
2 changes: 0 additions & 2 deletions frontend/models/TokenMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export default interface TokenMetada {
media_hash?: string, // Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
copies?: number, //u64 // number of copies of this set of metadata in existence when token was minted.
issued_at?: string, // ISO 8601 datetime when token was issued or minted
price?: string, // is the price in yoctos
creator?: string, // is the creator
on_sale?: boolean, // sale status
expires_at?: string, // ISO 8601 datetime when token expires
starts_at?: string, // ISO 8601 datetime when token starts being valid
Expand Down

0 comments on commit 1800490

Please sign in to comment.