-
Notifications
You must be signed in to change notification settings - Fork 4
/
TokenScene.tsx
72 lines (60 loc) · 1.72 KB
/
TokenScene.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { useToggleEffectContract } from "../web3/contract";
import Profile from "../web3/Profile";
import { ModificationsWithStatus } from "./Config/types/modifications";
import { useActiveEffects, useTokenScene } from "./lib/queries";
import SceneRenderer from "./SceneRenderer";
const TokenScene = () => {
const { tokenId } = useParams<{
tokenId: string;
}>();
const tokenScene = useTokenScene(tokenId);
const tokenEffects = useActiveEffects(tokenId);
// @ts-ignore
const { toggleEffect, applied } = useToggleEffectContract();
const [modifications, setModifications] = useState<ModificationsWithStatus>(
{}
);
useEffect(() => {
if (!tokenEffects) {
setModifications({});
return;
}
const combined = Object.entries(tokenEffects).reduce(
(acc: ModificationsWithStatus, [key, tokenEffect]) => {
// return {
// ...acc,
// [key]: {
// }
const appliedOfKey = applied[key];
const result: ModificationsWithStatus = {
...acc,
[key]: {
modification: tokenEffect.modification,
applied: {
applied: tokenEffect.active,
processing: !!appliedOfKey?.processing,
error: !!appliedOfKey?.error,
},
},
};
return result;
},
{}
);
setModifications(combined);
}, [tokenEffects, applied]);
return (
<>
<Profile />
<SceneRenderer
{...tokenScene}
modifications={modifications}
toggleApplied={toggleEffect}
tokenId={tokenId}
/>
</>
);
};
export default TokenScene;