Skip to content

Commit c547134

Browse files
committed
add rtk query
1 parent 668b5e8 commit c547134

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

packages/app/src/dapp/dapp.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const pastilles = [
5050

5151
const Drop: FC = () => {
5252
const state = useSelector((state) => state.appState);
53-
53+
const isConnected = state.signedIn;
5454
const nfts = state.walletAssets.nfts;
5555

5656
const [currentItem, setItem] = React.useState(undefined as any);
@@ -67,7 +67,10 @@ const Drop: FC = () => {
6767
const deckTexture = "/models/skate/textures/sublime-deck.png";
6868
const placeholderTexture = "/models/skate/textures/imgForMiddle.png";
6969

70-
const { data, error, isLoading } = useGetNFTsForDropByAddressQuery({ dropId: 0, address: "0x" });
70+
const { data, error, isLoading } = useGetNFTsForDropByAddressQuery({
71+
dropId: 0,
72+
address: "0xcadaA91596F3E2aFA69a37F47a5C70a4e3765c00",
73+
});
7174

7275
console.log(data);
7376

packages/app/src/dapp/store/services/drop.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
2-
import { NFTsForDropByAddress } from "../types";
2+
import { NFTsByCollection } from "../types";
33

44
export const dropApi = createApi({
55
reducerPath: "dropApi",
66
baseQuery: fetchBaseQuery({ baseUrl: "http://localhost:3001/" }),
77
endpoints: (builder) => ({
8-
getNFTsForDropByAddress: builder.query<
9-
NFTsForDropByAddress,
10-
{ dropId: number; address: string }
11-
>({
8+
getNFTsForDropByAddress: builder.query<NFTsByCollection, { dropId: number; address: string }>({
129
query: ({ dropId, address }) => `drop/${dropId}/${address}`,
1310
}),
11+
getDripsByAddress: builder.query<NFTsByCollection, { address: string }>({
12+
query: ({ address }) => `drip/${address}`,
13+
}),
1414
}),
1515
});
1616

packages/app/src/dapp/store/types/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
export type NFT = {
2+
contract: string;
3+
img: string;
4+
id: number;
5+
};
6+
export type NFTs = NFT[];
7+
export type NFTsByCollection = { [collectionName: string]: NFTs };
18
export type Collection = {
29
name: string;
310
contract: string;
@@ -9,5 +16,3 @@ export type Drop = {
916
};
1017

1118
export type Drops = Drop[];
12-
13-
export type NFTsForDropByAddress = { [collectionName: string]: { id: number; img: string }[] };

packages/server/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"typescript": "^4.5.4"
1313
},
1414
"dependencies": {
15+
"@types/cors": "^2.8.12",
1516
"@types/express": "^4.17.13",
1617
"@types/node": "^17.0.8",
1718
"axios": "^0.24.0",
19+
"cors": "^2.8.5",
1820
"dotenv": "^16.0.0",
1921
"express": "^4.17.2",
2022
"ts-node-dev": "^1.1.8",

packages/server/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import "dotenv/config";
33
import express, { Application, Request, Response } from "express";
44
import axios from "axios";
55
import { env } from "process";
6+
import cors from "cors";
67

78
// Env setup
89
const apiKey = env["apiKey"];
910

1011
// Express server
1112
const app: Application = express();
13+
app.use(cors());
1214
const port = 3001;
1315

1416
// Axios setup
@@ -20,11 +22,14 @@ app.use(express.urlencoded({ extended: true }));
2022
app.use(express.static(__dirname + "/../public"));
2123

2224
type NFT = {
25+
contract: string;
2326
img: string;
2427
id: number;
2528
};
2629

27-
type NFTs = { [contract: string]: NFT[] };
30+
type NFTs = NFT[];
31+
32+
type NFTsByCollection = { [collectionName: string]: NFTs };
2833

2934
type Collection = {
3035
name: string;
@@ -57,7 +62,7 @@ app.get("/drop/:drop/:address", async (req: Request, res: Response): Promise<Res
5762
const drop = DROPS[req.params.drop as any as number];
5863
const address = req.params.address;
5964

60-
let nftsForDropByAddress: NFTs = {};
65+
let nftsForDropByAddress: NFTsByCollection = {};
6166

6267
for (let collection of drop.collections) {
6368
const resq = await axios.get(
@@ -67,12 +72,13 @@ app.get("/drop/:drop/:address", async (req: Request, res: Response): Promise<Res
6772
let nfts: NFT[] = [];
6873
for (let asset of resq.data.assets) {
6974
nfts.push({
75+
contract: collection.contract,
7076
img: asset.image_url,
7177
id: asset.token_id,
7278
});
7379
}
7480

75-
nftsForDropByAddress[collection.contract] = nfts;
81+
nftsForDropByAddress[collection.name] = nfts;
7682
}
7783

7884
return res.status(200).send(nftsForDropByAddress);

packages/server/yarn.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@
481481
dependencies:
482482
"@types/node" "*"
483483

484+
"@types/cors@^2.8.12":
485+
version "2.8.12"
486+
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080"
487+
integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==
488+
484489
"@types/express-serve-static-core@^4.17.18":
485490
version "4.17.28"
486491
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz#c47def9f34ec81dc6328d0b1b5303d1ec98d86b8"
@@ -1340,7 +1345,7 @@ core-util-is@~1.0.0:
13401345
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
13411346
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==
13421347

1343-
cors@^2.8.1:
1348+
cors@^2.8.1, cors@^2.8.5:
13441349
version "2.8.5"
13451350
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
13461351
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==

0 commit comments

Comments
 (0)