Skip to content

Commit f5e2013

Browse files
committed
bunch of shit
1 parent c547134 commit f5e2013

File tree

14 files changed

+161
-146
lines changed

14 files changed

+161
-146
lines changed

packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/node": "^12.0.0",
1818
"@types/react": "^17.0.0",
1919
"@types/react-dom": "^17.0.0",
20+
"axios": "^0.27.2",
2021
"history": "5",
2122
"react": "^17.0.2",
2223
"react-dom": "^17.0.2",

packages/app/src/_3d/scenes/skate_1.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ const Scene: FC<props> = (props) => {
2828
<OrbitControls
2929
autoRotate={true}
3030
autoRotateSpeed={7.5}
31+
minPolarAngle={Math.PI / 2}
32+
maxPolarAngle={Math.PI / 2}
3133
enableZoom={false}
32-
enableRotate={false}
34+
enableRotate={true}
3335
target={[0, 40, 0]}
3436
/>
3537
</>

packages/app/src/dapp/dapp.tsx

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import Pastille from "../_utils/components/stateless/pastille";
2525

2626
import ClickAwayListener from "@mui/material/ClickAwayListener";
2727
import Clickable from "../_utils/components/stateless/clickable";
28-
import { useSelector } from "./store/hooks";
28+
import { useDispatch, useSelector } from "./store/hooks";
2929
import SceneLoader from "@/_3d/scenes/skate_1";
30-
import { useGetNFTsForDropByAddressQuery } from "./store/services/drop";
30+
import { getAssetsOwned } from "./store/actions/app.actions";
3131

3232
const pastilles = [
3333
{
@@ -48,40 +48,35 @@ const pastilles = [
4848
},
4949
];
5050

51-
const Drop: FC = () => {
52-
const state = useSelector((state) => state.appState);
53-
const isConnected = state.signedIn;
54-
const nfts = state.walletAssets.nfts;
51+
const Drop: FC<{ dropId: number }> = ({ dropId }) => {
52+
// store
53+
const dispatch = useDispatch();
54+
const { auth, wallet } = useSelector((state) => state.appState);
5555

56-
const [currentItem, setItem] = React.useState(undefined as any);
56+
// fc state
57+
const [currentItem, setItem] = React.useState<{ collection: string; id: number; img: string }>();
5758
const [checked, setChecked] = React.useState(false);
59+
const handleChange = () => setChecked(!checked);
5860

59-
const handleChange = () => {
60-
if (checked === false) {
61-
setChecked(true);
62-
} else {
63-
setChecked(false);
61+
useEffect(() => {
62+
if (auth.signedIn) {
63+
dispatch(getAssetsOwned(dropId, auth.address));
6464
}
65-
};
65+
}, [auth.signedIn]);
6666

6767
const deckTexture = "/models/skate/textures/sublime-deck.png";
6868
const placeholderTexture = "/models/skate/textures/imgForMiddle.png";
6969

70-
const { data, error, isLoading } = useGetNFTsForDropByAddressQuery({
71-
dropId: 0,
72-
address: "0xcadaA91596F3E2aFA69a37F47a5C70a4e3765c00",
73-
});
74-
75-
console.log(data);
76-
77-
//
7870
return (
7971
<Fade duration={1500} triggerOnce>
8072
<Style.Root>
8173
<Style.Header></Style.Header>
82-
<Style.Part1>
83-
<SceneLoader deckTexture={deckTexture} placeholderTexture={placeholderTexture} _id={1} />
84-
{/* <My3DScene /> */}
74+
<Style.Body>
75+
<SceneLoader
76+
deckTexture={deckTexture}
77+
placeholderTexture={currentItem?.img || placeholderTexture}
78+
_id={1}
79+
/>
8580
<Style.LeftSide>
8681
<Style.HeaderLeftSide container spacing={0} alignItems="center">
8782
<Grid item xs={6}>
@@ -112,29 +107,29 @@ const Drop: FC = () => {
112107
</Grid>
113108
</Style.HeaderLeftSide>
114109
{/* */}
115-
<Style.BodyLeftSide connected={state.signedIn}>
110+
<Style.BodyLeftSide connected={auth.signedIn}>
116111
{/* */}
117112
<Style.InnerLeftSide>
118-
{nfts.length ? (
119-
nfts.map((list, index1) => (
113+
{wallet.nfts.length ? (
114+
wallet.nfts.map((collection, index1) => (
120115
<div key={index1}>
121-
<Style.CollectionName>{list.collection}</Style.CollectionName>
116+
<Style.CollectionName>{collection.collectionName}</Style.CollectionName>
122117
<ImageList cols={4} gap={4} style={{ marginBottom: "20px" }}>
123-
{list.list.map((item, index) => (
118+
{collection.assets.map((item, index) => (
124119
<ImageListItem
125120
key={index}
126121
style={{
127122
border:
128123
currentItem &&
129-
currentItem.collection === list.collection &&
124+
currentItem.collection === collection.collectionName &&
130125
currentItem.id === item.id
131126
? "3px solid #2AFE00"
132127
: "3px solid white",
133128
cursor: "pointer",
134129
}}
135130
onClick={() => {
136131
setItem({
137-
collection: list.collection,
132+
collection: collection.collectionName,
138133
id: item.id,
139134
img: item.img,
140135
});
@@ -143,15 +138,15 @@ const Drop: FC = () => {
143138
<img
144139
src={`${item.img}?w=248&fit=crop&auto=format`}
145140
srcSet={`${item.img}?w=248&fit=crop&auto=format&dpr=2 2x`}
146-
alt={item.title}
141+
alt={"item.id"}
147142
loading="lazy"
148143
/>
149144
</ImageListItem>
150145
))}
151146
</ImageList>
152147
</div>
153148
))
154-
) : state.signedIn ? (
149+
) : auth.signedIn ? (
155150
<Style.InnerLeftSideNoNfts>You do not own any NFTs :'(</Style.InnerLeftSideNoNfts>
156151
) : (
157152
<Style.InnerLeftSideNoNfts>You are not connected :'(</Style.InnerLeftSideNoNfts>
@@ -248,14 +243,8 @@ const Drop: FC = () => {
248243
</Style.InnerContainerInfo>
249244
</Style.ContainerInfo>
250245
</ClickAwayListener>
251-
</Style.Part1>
252-
<Style.Overlay>
253-
<Style.InnerOverlay container justifyContent="space-evenly">
254-
<Style.InnerOverlayLeft item></Style.InnerOverlayLeft>
255-
<Style.InnerOverlayCenter item></Style.InnerOverlayCenter>
256-
<Style.InnerOverlayRight item></Style.InnerOverlayRight>
257-
</Style.InnerOverlay>
258-
</Style.Overlay>
246+
</Style.Body>
247+
<Style.Footer></Style.Footer>
259248
</Style.Root>
260249
</Fade>
261250
);

packages/app/src/dapp/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const Index: FC<props> = ({ children }) => {
1212
return (
1313
<Provider store={store}>
1414
<Navbar />
15-
<DApp />
15+
16+
{/* */}
17+
<DApp dropId={0} />
1618
</Provider>
1719
);
1820
};

packages/app/src/dapp/navbar/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ import { useDispatch, useSelector } from "../store/hooks";
1414
import { signIn } from "../store/actions/app.actions";
1515

1616
export const NavbarComponent: FC = () => {
17-
const state = useSelector((state) => state.appState);
17+
const { auth, wallet } = useSelector((state) => state.appState);
1818
const dispatch = useDispatch();
1919

20-
const drips = state.walletAssets.drips;
21-
2220
const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null);
2321
const handlePopoverOpen = (event: React.MouseEvent<HTMLElement>) => {
2422
setAnchorEl(event.currentTarget);
@@ -57,7 +55,7 @@ export const NavbarComponent: FC = () => {
5755
alignItems="center"
5856
>
5957
<Grid item>
60-
<Clickable activated={state.signedIn} onClick={handlePopoverOpen}>
58+
<Clickable activated={auth.signedIn} onClick={handlePopoverOpen}>
6159
<AccountBalanceWalletIcon
6260
style={{
6361
fontSize: "40px",
@@ -79,9 +77,9 @@ export const NavbarComponent: FC = () => {
7977
>
8078
<ClickAwayListener onClickAway={handlePopoverClose}>
8179
<Style.WalletView>
82-
{drips.length ? (
80+
{wallet.drips.length ? (
8381
<Grid container>
84-
{drips.map((drip, index) => (
82+
{wallet.drips.map((drip, index) => (
8583
<Grid item key={index}>
8684
<Grid container>
8785
<Grid item xs={2}>
@@ -171,7 +169,7 @@ export const NavbarComponent: FC = () => {
171169
</Popover>
172170
</Grid>
173171
<Grid item>
174-
{state.signedIn ? (
172+
{auth.signedIn ? (
175173
<Style.Wallet container>
176174
<Grid
177175
item
@@ -191,7 +189,7 @@ export const NavbarComponent: FC = () => {
191189
<Style.WalletENS>bonjour.eth</Style.WalletENS>
192190
</Grid>
193191
<Grid item xs={12}>
194-
<Style.WalletAddy>{state.reducedAddress}</Style.WalletAddy>
192+
<Style.WalletAddy>{auth.reducedAddress}</Style.WalletAddy>
195193
</Grid>
196194
</Grid>
197195
</Grid>
Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,56 @@
11
import { RootState } from "..";
22
import { sdk } from "../../sdk";
3+
import { AssetsOwned } from "@sshlabs/typings";
4+
import axios from "axios";
35

4-
/////////////
5-
// SIGN_IN //
6-
/////////////
76
export const SIGN_IN = "SIGN_IN";
8-
export interface ActionInit {
7+
export interface ActionSignIn {
98
type: typeof SIGN_IN;
109
payload: {
1110
signedIn: boolean;
1211
address: string;
1312
};
1413
}
1514

15+
export const GET_ASSETS_OWNED = "GET_ASSETS_OWNED";
16+
export interface ActionGetAssetOwned {
17+
type: typeof GET_ASSETS_OWNED;
18+
payload: AssetsOwned;
19+
}
20+
export const getAssetsOwned = (dropId: number, address: string) => {
21+
const toDispatch = (payload: ActionGetAssetOwned["payload"]): ActionGetAssetOwned => {
22+
return {
23+
type: GET_ASSETS_OWNED,
24+
payload: payload,
25+
};
26+
};
27+
28+
return async (dispatch: any, getState: () => RootState) => {
29+
try {
30+
const result = (await axios.get(`http://localhost:3001/drop/${dropId}/${address}`))
31+
.data as AssetsOwned;
32+
33+
return dispatch(toDispatch(result));
34+
} catch (e) {}
35+
};
36+
};
37+
1638
export const signIn = () => {
17-
const toDispatch = (payload: ActionInit["payload"]): ActionInit => {
39+
const toDispatch = (payload: ActionSignIn["payload"]): ActionSignIn => {
1840
return {
1941
type: SIGN_IN,
2042
payload: payload,
2143
};
2244
};
2345

24-
//
2546
return async (dispatch: any, getState: () => RootState) => {
2647
try {
2748
await sdk.connect();
2849
const { address } = sdk.getInfo();
2950

3051
return dispatch(toDispatch({ signedIn: true, address: address }));
31-
} catch (e) {
32-
return dispatch(toDispatch({ signedIn: false, address: "" }));
33-
}
52+
} catch (e) {}
3453
};
3554
};
3655

37-
export type AppActionTypes = ActionInit;
56+
export type AppActionTypes = ActionSignIn | ActionGetAssetOwned;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { configureStore } from "@reduxjs/toolkit";
22
import { IAppState, reducers } from "./reducers/index";
3-
import { dropApi } from "./services/drop";
43
import { combineReducers } from "redux";
54

65
export const store = configureStore({
76
reducer: combineReducers({
8-
[dropApi.reducerPath]: dropApi.reducer,
97
...reducers,
108
}),
11-
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(dropApi.middleware),
129
});
1310

1411
export type RootState = IAppState;

packages/app/src/dapp/store/reducers/app.reducer.tsx

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,48 @@
1-
import { AppActionTypes } from "../actions/app.actions";
2-
import { SIGN_IN } from "../actions/app.actions";
1+
import { AppActionTypes, SIGN_IN, GET_ASSETS_OWNED } from "../actions/app.actions";
2+
import { NFTs, NFTsByCollection } from "@sshlabs/typings";
33

4-
export type appState = {
5-
// login info
6-
signedIn: boolean;
7-
address: string;
8-
reducedAddress: string;
4+
const defaultAuthState = { signedIn: false, address: "", reducedAddress: "" };
5+
type authState = typeof defaultAuthState;
96

10-
walletAssets: {
11-
//
12-
drips: {
13-
collection: string;
14-
id: number;
15-
img: string;
16-
}[];
7+
const defaultWalletState: { nfts: NFTsByCollection; drips: NFTs } = { nfts: [], drips: [] };
8+
type walletState = typeof defaultWalletState;
179

18-
//
19-
nfts: {
20-
collection: string;
21-
list: { img: string; title: string; id: number }[];
22-
}[];
23-
};
10+
export type appState = {
11+
auth: authState;
12+
wallet: walletState;
2413
};
2514

2615
const appStateReducer = (
2716
state: appState = {
28-
signedIn: false,
29-
address: "",
30-
reducedAddress: "",
31-
32-
//
33-
walletAssets: {
34-
drips: [],
35-
nfts: [],
36-
},
17+
auth: defaultAuthState,
18+
wallet: defaultWalletState,
3719
},
3820
action: AppActionTypes
3921
): appState => {
4022
switch (action.type) {
4123
case SIGN_IN:
4224
return {
4325
...state,
26+
auth: {
27+
...state.auth,
28+
signedIn: action.payload.signedIn,
29+
address: action.payload.address,
30+
reducedAddress:
31+
action.payload.address.slice(0, 6) + "..." + action.payload.address.slice(-4),
32+
},
33+
};
4434

45-
signedIn: action.payload.signedIn,
46-
address: action.payload.address,
47-
reducedAddress:
48-
action.payload.address.slice(0, 6) + "..." + action.payload.address.slice(-4),
35+
case GET_ASSETS_OWNED:
36+
console.log(action.payload);
37+
return {
38+
...state,
39+
wallet: {
40+
...state.wallet,
41+
drips: action.payload.drips,
42+
nfts: action.payload.nfts,
43+
},
4944
};
45+
5046
default:
5147
return {
5248
...state,

0 commit comments

Comments
 (0)