-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathApp.tsx
More file actions
135 lines (124 loc) · 4.05 KB
/
App.tsx
File metadata and controls
135 lines (124 loc) · 4.05 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React, { PropsWithChildren, useCallback, useEffect, useRef } from 'react';
import { BrowserRouter } from 'react-router-dom';
import AlertBanner from '@components/AlertBanner/AlertBanner';
import { ChainStatus } from '@components/ConnectWallet';
import { Header } from '@components/Header';
import { AppInitProvider } from '@containers/AppInitialProvider';
import { useAccount } from '@containers/Web3';
import { useEthersProviderWithPublic, useEthersSigner } from '@hooks/useEthersProvider';
import { ChatBox, ChatBoxRef, SubqlProvider } from '@subql/components';
import { RainbowProvider } from './config/rainbowConf';
import { useChatBoxStore } from './stores/chatbox';
import {
IPFSProvider,
ProjectMetadataProvider,
ProjectRegistryProvider,
QueryApolloProvider,
SQTokenProvider,
} from './containers';
import RouterComponent from './router';
import './App.css';
// TODO: Remove SQTProvider
const Providers: React.FC<PropsWithChildren> = ({ children }) => {
return (
<IPFSProvider initialState={{ gateway: import.meta.env.VITE_IPFS_GATEWAY }}>
<QueryApolloProvider>
<RainbowProvider>
<AppInitProvider>
<ProjectMetadataProvider>
<ProjectRegistryProvider>
<SQTokenProvider>
<SubqlProvider theme={'light'} version="v2">
{children}
</SubqlProvider>
</SQTokenProvider>
</ProjectRegistryProvider>
</ProjectMetadataProvider>
</AppInitProvider>
</RainbowProvider>
</QueryApolloProvider>
</IPFSProvider>
);
};
const makeDebugInfo = (debugInfo: object) => {
window.debugInfo = debugInfo;
};
const RenderRouter: React.FC = () => {
const { address, connector, isConnected } = useAccount();
const { signer } = useEthersSigner();
const provider = useEthersProviderWithPublic();
const chatboxStore = useChatBoxStore();
const setChatBoxRef = useCallback((ref: ChatBoxRef) => {
chatboxStore.setChatBoxRef(ref as ChatBoxRef);
}, []);
useEffect(() => {
(async () => {
makeDebugInfo({
address,
walletName: connector?.name,
signerAddress: 'not collected',
signerChainId: 'not collected',
providerNetwork: provider.network?.name,
isConnected: isConnected,
});
const signerAddress = await signer?.getAddress();
const signerChainId = await signer?.getChainId();
const providerNetwork = await provider.getNetwork();
makeDebugInfo({
address,
walletName: connector?.name,
signerAddress,
signerChainId,
providerNetwork,
isConnected: isConnected,
});
})();
}, [address, connector, signer, provider]);
return (
<>
<BrowserRouter>
<div className="Main">
<div className="Header">
<Header />
</div>
<div className="Content">
<ChainStatus>
<RouterComponent></RouterComponent>
</ChainStatus>
</div>
</div>
</BrowserRouter>
<ChatBox
ref={setChatBoxRef}
chatUrl={import.meta.env.VITE_AI_URL}
prompt={address ? `My address is: ${address},use this for any further prompts.` : undefined}
onReaction={async (status, message, userQuestion) => {
await fetch(`${import.meta.env.VITE_AI_REACTION_URL}/react/message`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
status: status,
conversation_id: message.conversation_id,
id: message.id,
content: message.content as string,
user_question: userQuestion.content,
}),
});
}}
></ChatBox>
</>
);
};
export const App: React.FC = () => {
return (
<Providers>
<div className="App">
<RenderRouter />
</div>
</Providers>
);
};