From d952e561e7a6d7396af088a7977d20d8d8ef42f0 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Sun, 4 Sep 2022 09:30:24 -0700 Subject: [PATCH] refactor(wallet-ui)!: remove Solo wallet support --- .../components/ConnectionSettingsDialog.jsx | 223 +++--------------- packages/wallet/ui/src/contexts/Provider.jsx | 17 +- packages/wallet/ui/src/util/connections.js | 13 - 3 files changed, 38 insertions(+), 215 deletions(-) diff --git a/packages/wallet/ui/src/components/ConnectionSettingsDialog.jsx b/packages/wallet/ui/src/components/ConnectionSettingsDialog.jsx index 149a1454bc7..d584f556e2f 100644 --- a/packages/wallet/ui/src/components/ConnectionSettingsDialog.jsx +++ b/packages/wallet/ui/src/components/ConnectionSettingsDialog.jsx @@ -1,30 +1,23 @@ -import { useMemo, useState } from 'react'; -import { v4 as uuid } from 'uuid'; -import { makeStyles } from '@mui/styles'; import Autocomplete from '@mui/material/Autocomplete'; -import TextField from '@mui/material/TextField'; +import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; -import DialogTitle from '@mui/material/DialogTitle'; import Dialog from '@mui/material/Dialog'; +import DialogActions from '@mui/material/DialogActions'; import DialogContent from '@mui/material/DialogContent'; -import Box from '@mui/material/Box'; -import TabList from '@mui/lab/TabList'; -import Tab from '@mui/material/Tab'; -import TabContext from '@mui/lab/TabContext'; -import TabPanel from '@mui/lab/TabPanel'; +import DialogTitle from '@mui/material/DialogTitle'; import FormControl from '@mui/material/FormControl'; -import DialogActions from '@mui/material/DialogActions'; -import Select from '@mui/material/Select'; -import MenuItem from '@mui/material/MenuItem'; import InputLabel from '@mui/material/InputLabel'; +import MenuItem from '@mui/material/MenuItem'; +import Select from '@mui/material/Select'; +import TextField from '@mui/material/TextField'; +import { makeStyles } from '@mui/styles'; +import { useMemo, useState } from 'react'; +import { v4 as uuid } from 'uuid'; import { deepEquals } from '../util/DeepEquals'; import { withApplicationContext } from '../contexts/Application'; -import { - ConnectionConfigType, - SmartConnectionMethod, -} from '../util/connections'; -import { maybeSave, maybeLoad } from '../util/storage'; +import { SmartConnectionMethod } from '../util/connections'; +import { maybeSave } from '../util/storage'; const useStyles = makeStyles(_ => ({ centeredText: { @@ -39,11 +32,6 @@ const Errors = { SMART_CONNECTION_METHOD_UNSPECIFIED: 'smart wallet connection unspecified', }; -const Tabs = { - SMART: 'smart', - SOLO: 'solo', -}; - const ErrorLabel = ({ children }) => { return ( { ); }; -const getAccessToken = () => { - // Fetch the access token from the window's URL. - const accessTokenParams = `?${window.location.hash.slice(1)}`; - let accessToken = new URLSearchParams(accessTokenParams).get('accessToken'); - - try { - if (accessToken) { - // Store the access token for later use. - maybeSave('accessToken', accessToken); - } else { - // Try reviving it from localStorage. - accessToken = maybeLoad('accessToken'); - } - } catch (e) { - console.log('Error fetching accessToken', e); - } - - // Now that we've captured it, clear out the access token from the URL bar. - window.location.hash = ''; - - window.addEventListener('hashchange', _ev => { - // See if we should update the access token params. - const atp = `?${window.location.hash.slice(1)}`; - const at = new URLSearchParams(atp).get('accessToken'); - - if (at) { - // We have new params, so replace them. - accessToken = at; - maybeSave('accessToken', accessToken); - } - - // Keep it clear. - window.location.hash = ''; - }); - - return accessToken; -}; - const ConnectionSettingsDialog = ({ onClose, open, @@ -110,42 +60,9 @@ const ConnectionSettingsDialog = ({ tryKeplrConnect, }) => { const classes = useStyles(); - const smartConnectionHrefs = allConnectionConfigs - .filter(({ type }) => type === ConnectionConfigType.SMART) - .map(({ href }) => href); - - const soloConnectionHrefs = allConnectionConfigs - .filter(({ type }) => type === ConnectionConfigType.SOLO) - .map(({ href }) => href); - - const [smartWalletConfig, setSmartWalletConfig] = useState( - connectionConfig?.type === ConnectionConfigType.SMART - ? connectionConfig - : { - type: ConnectionConfigType.SMART, - href: smartConnectionHrefs[0], - smartConnectionMethod: SmartConnectionMethod.KEPLR, - }, - ); - - const [soloWalletConfig, setSoloWalletConfig] = useState( - connectionConfig?.type === ConnectionConfigType.SOLO - ? connectionConfig - : { - type: ConnectionConfigType.SOLO, - href: soloConnectionHrefs[0], - accessToken: getAccessToken(), - }, - ); - - const [currentTab, setCurrentTab] = useState( - connectionConfig && connectionConfig.type === ConnectionConfigType.SOLO - ? Tabs.SOLO - : Tabs.SMART, - ); + const smartConnectionHrefs = allConnectionConfigs.map(({ href }) => href); - const config = - currentTab === Tabs.SMART ? smartWalletConfig : soloWalletConfig; + const [config, setConfig] = useState(connectionConfig); const [selectInputId] = useState(uuid()); @@ -158,20 +75,14 @@ const ConnectionSettingsDialog = ({ errors.add(Errors.INVALID_URL); } - if (config.type === ConnectionConfigType.SMART) { - if ( - config.smartConnectionMethod === SmartConnectionMethod.READ_ONLY && - !config.publicAddress - ) { - errors.add(Errors.INVALID_ADDRESS); - } - if (config.smartConnectionMethod === undefined) { - errors.add(Errors.SMART_CONNECTION_METHOD_UNSPECIFIED); - } + if ( + config.smartConnectionMethod === SmartConnectionMethod.READ_ONLY && + !config.publicAddress + ) { + errors.add(Errors.INVALID_ADDRESS); } - - if (config.type === ConnectionConfigType.SOLO && !config.accessToken) { - errors.add(Errors.INVALID_ACCESS_TOKEN); + if (config.smartConnectionMethod === undefined) { + errors.add(Errors.SMART_CONNECTION_METHOD_UNSPECIFIED); } const hasChanges = useMemo( @@ -208,19 +119,15 @@ const ConnectionSettingsDialog = ({ onClose(); }; - const handleTabChange = (_ev, value) => { - setCurrentTab(value); - }; - const smartWalletConfigForm = ( <> - setSmartWalletConfig(swConfig => ({ + setConfig(swConfig => ({ ...swConfig, href: newValue, })) @@ -248,12 +155,12 @@ const ConnectionSettingsDialog = ({ Connection Method