Skip to content

Commit

Permalink
Merge pull request #126 from P4-Games/develop
Browse files Browse the repository at this point in the history
merge develop into main
  • Loading branch information
dappsar authored Oct 5, 2024
2 parents d8c211a + 12f0d70 commit 2e1cc6e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 55 deletions.
2 changes: 1 addition & 1 deletion scripts/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ docker build \
--build-arg RECAPTCHA_API_KEY="$RECAPTCHA_API_KEY" \
--build-arg NEXT_PUBLIC_RECAPTCHA_SITE_KEY="$NEXT_PUBLIC_RECAPTCHA_SITE_KEY" \
--build-arg NEXT_PUBLIC_NFT_IMAGE_REPOSITORY="$NEXT_PUBLIC_NFT_IMAGE_REPOSITORY" \
--BUILD-ARG NEXT_PUBLIC_NFT_MARKETPLACE_URL="$NEXT_PUBLIC_NFT_MARKETPLACE_URL" \
--build-arg NEXT_PUBLIC_NFT_MARKETPLACE_URL="$NEXT_PUBLIC_NFT_MARKETPLACE_URL" \
-t my-nextjs-app ..
6 changes: 0 additions & 6 deletions src/app/api/_data/blk-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ export async function getConversationRates(): Promise<any> {
return result
}

/*
export async function getNftById(nftId: string): Promise<any> {
return fetchNftById(nftId)
}
*/

// ---------------------------------------------------------------------------------------------

async function getBalances(walletAddress: string): Promise<any[]> {
Expand Down
50 changes: 6 additions & 44 deletions src/app/api/_data/data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,57 +179,19 @@ export async function getWalletNfts(wallet: string): Promise<INFT[] | undefined>
return nfts
}

export async function getNftById(nftId: number): Promise<INFT[] | undefined> {
export async function getNftById(id: string): Promise<INFT | undefined> {
const client = await getClientPromise()
const db = client.db(DB_CHATTERPAY_NAME)

const cursor: INFTDB[] | null = await db
.collection(SCHEMA_NFTS)
.aggregate([
{
$match: {
id: nftId
}
},
{
$project: {
_id: 1, // bddId
id: 1, // nftId
channel_user_id: 1,
wallet: 1,
trxId: 1,
metadata: 1
}
}
])
.toArray()
const nft: INFT | null = await db.collection(SCHEMA_NFTS).findOne({
id
})

if (!cursor || cursor.length === 0) {
if (!nft) {
return undefined
}

const default_image_url = {
gcp: '/assets/images/nfts/default_nft.png',
ipfs: '/assets/images/nfts/default_nft.png',
icp: '/assets/images/nfts/default_nft.png'
}

const nfts: INFT[] = cursor.map(({ _id, id, metadata, ...rest }) => {
const { image_url, ...metadataRest } = metadata || {}
const formatted_image_url = image_url || default_image_url

return {
bddId: getFormattedId(_id),
nftId: id,
metadata: {
...metadataRest,
image_url: formatted_image_url
},
...rest
}
})

return nfts
return nft
}

export async function getWalletNft(wallet: string, nftId: string): Promise<INFT | undefined> {
Expand Down
8 changes: 5 additions & 3 deletions src/app/api/v1/nft/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ export async function GET(request: Request, { params }: { params: IParams }) {
}

try {
const response: INFT[] | undefined = await getNftById(parseInt(params.id, 10))
if (response && response.length > 0 && response[0].metadata.image_url) {
return NextResponse.json(response[0])
const nft: INFT | undefined = await getNftById(params.id)
console.log('3', params, nft)

if (nft) {
return NextResponse.json(nft)
}

return new NextResponse(JSON.stringify(errorMessage), {
Expand Down
2 changes: 1 addition & 1 deletion src/sections/nfts/nft-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { useTranslate } from 'src/locales'
import {
NFT_SHARE,
UI_API_URL,
NFT_MARKETPLACE_URL,
NFT_TRX_EXPLORER,
NFT_MARKETPLACE_URL,
NFT_IMAGE_REPOSITORY
} from 'src/config-global'

Expand Down

0 comments on commit 2e1cc6e

Please sign in to comment.