forked from project-serum/spl-token-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
224 lines (215 loc) · 6.9 KB
/
App.js
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import React, { Suspense, useState } from 'react';
import { makeStyles, List, ListItem } from '@material-ui/core';
import CssBaseline from '@material-ui/core/CssBaseline';
import useMediaQuery from '@material-ui/core/useMediaQuery';
import {
ThemeProvider,
unstable_createMuiStrictModeTheme as createMuiTheme,
} from '@material-ui/core/styles';
import blue from '@material-ui/core/colors/blue';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
import DialogActions from '@material-ui/core/DialogActions';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import DialogForm from './components/DialogForm';
import NavigationFrame from './components/NavigationFrame';
import { ConnectionProvider } from './utils/connection';
import WalletPage from './pages/WalletPage';
import { useWallet, WalletProvider } from './utils/wallet';
import { ConnectedWalletsProvider } from './utils/connected-wallets';
import { TokenRegistryProvider } from './utils/tokens/names';
import LoadingIndicator from './components/LoadingIndicator';
import { SnackbarProvider } from 'notistack';
import PopupPage from './pages/PopupPage';
import LoginPage from './pages/LoginPage';
import ConnectionsPage from './pages/ConnectionsPage';
import { isExtension } from './utils/utils';
import { PageProvider, usePage } from './utils/page';
export default function App() {
// TODO: add toggle for dark mode
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
const theme = React.useMemo(
() =>
createMuiTheme({
palette: {
type: prefersDarkMode ? 'dark' : 'light',
primary: blue,
},
// TODO consolidate popup dimensions
ext: '450',
}),
[prefersDarkMode],
);
// Disallow rendering inside an iframe to prevent clickjacking.
if (window.self !== window.top) {
return null;
}
let appElement = (
<NavigationFrame>
<Suspense fallback={<LoadingIndicator />}>
<PageContents />
</Suspense>
</NavigationFrame>
);
if (isExtension) {
appElement = (
<ConnectedWalletsProvider>
<PageProvider>{appElement}</PageProvider>
</ConnectedWalletsProvider>
);
}
return (
<Suspense fallback={<LoadingIndicator />}>
<ThemeProvider theme={theme}>
<CssBaseline />
<ConnectionProvider>
<TokenRegistryProvider>
<SnackbarProvider maxSnack={5} autoHideDuration={8000}>
<WalletProvider>{appElement}</WalletProvider>
</SnackbarProvider>
</TokenRegistryProvider>
</ConnectionProvider>
</ThemeProvider>
</Suspense>
);
}
function PageContents() {
const wallet = useWallet();
const [page] = usePage();
const [showWalletSuggestion, setShowWalletSuggestion] = useState(true);
const suggestionKey = 'private-irgnore-wallet-suggestion';
const ignoreSuggestion = window.localStorage.getItem(suggestionKey);
if (!wallet) {
return (
<>
{!ignoreSuggestion && (
<WalletSuggestionDialog
open={showWalletSuggestion}
onClose={() => setShowWalletSuggestion(false)}
onIgnore={() => {
window.localStorage.setItem(suggestionKey, true);
setShowWalletSuggestion(false);
}}
/>
)}
<LoginPage />
</>
);
}
if (window.opener) {
return <PopupPage opener={window.opener} />;
}
if (page === 'wallet') {
return <WalletPage />;
} else if (page === 'connections') {
return <ConnectionsPage />;
}
}
const useStyles = makeStyles(() => ({
walletButton: {
width: '100%',
padding: '16px',
'&:hover': {
cursor: 'pointer',
},
},
}));
function WalletSuggestionDialog({ open, onClose, onIgnore }) {
const classes = useStyles();
return (
<DialogForm open={open} onClose={onClose} fullWidth>
<DialogTitle>Looking for a Wallet?</DialogTitle>
<DialogContent>
<Typography>
Sollet is an{' '}
<a
style={{ color: 'inherit' }}
href="https://github.com/project-serum/spl-token-wallet"
target="__blank"
>
{' '}
open source
</a>{' '}
wallet for advanced users and developers. For the best Solana
experience and user support, it is recommended to use <b>
Phantom
</b>{' '}
or <b>Solflare</b>.
</Typography>
<List disablePadding style={{ marginTop: '16px' }}>
<ListItem button disablePadding style={{ padding: 0 }}>
<div
className={classes.walletButton}
style={{ display: 'flex' }}
onClick={() => {
window.location = 'https://phantom.app/';
}}
>
<div>
<img
alt=""
style={{ height: '39px' }}
src="https://raw.githubusercontent.com/solana-labs/wallet-adapter/master/packages/wallets/icons/phantom.svg"
/>
</div>
<div>
<Typography
style={{
marginLeft: '16px',
display: 'flex',
justifyContent: 'center',
flexDirection: 'column',
height: '39px',
fontWeight: 'bold',
}}
>
Phantom
</Typography>
</div>
</div>
</ListItem>
<ListItem button disablePadding style={{ padding: 0 }}>
<div
onClick={() => {
window.location = 'https://solflare.com/';
}}
className={classes.walletButton}
style={{ display: 'flex' }}
>
<div>
<img
alt=""
style={{ height: '39px' }}
src="https://raw.githubusercontent.com/solana-labs/wallet-adapter/master/packages/wallets/icons/solflare.svg"
/>
</div>
<div>
<Typography
style={{
marginLeft: '16px',
display: 'flex',
justifyContent: 'center',
flexDirection: 'column',
height: '39px',
fontWeight: 'bold',
}}
>
Solflare
</Typography>
</div>
</div>
</ListItem>
</List>
</DialogContent>
<DialogActions>
<Button type="submit" color="primary" onClick={onIgnore}>
Ignore Future Dialog
</Button>
<Button type="submit" color="primary" onClick={onClose}>
Ok
</Button>
</DialogActions>
</DialogForm>
);
}