Skip to content

Commit

Permalink
feat(wallet-ui): preview mode
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 4, 2022
1 parent caf2b00 commit fedf049
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 30 deletions.
35 changes: 21 additions & 14 deletions packages/wallet/ui/src/components/NavMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import DashboardIcon from '@mui/icons-material/Dashboard';
import Apps from '@mui/icons-material/Apps';
import People from '@mui/icons-material/People';
import AddCircle from '@mui/icons-material/AddCircle';
import { withApplicationContext } from '../contexts/Application';

const useStyles = makeStyles(theme => ({
nav: {
Expand Down Expand Up @@ -69,7 +70,7 @@ const ListItemLink = ({ icon, primary, to, onClick }) => {
);
};

const NavMenu = ({ setDrawerOpened }) => {
const NavMenu = ({ setDrawerOpened, previewEnabled }) => {
const styles = useStyles(useTheme());
const onLinkClick = () => {
if (setDrawerOpened) {
Expand All @@ -93,21 +94,27 @@ const NavMenu = ({ setDrawerOpened }) => {
primary="Dapps"
icon={<Apps />}
/>
<ListItemLink
onClick={onLinkClick}
to="/contacts"
primary="Contacts"
icon={<People />}
/>
<ListItemLink
onClick={onLinkClick}
to="/issuers"
primary="Asset Issuers"
icon={<AddCircle />}
/>
{previewEnabled && (
<ListItemLink
onClick={onLinkClick}
to="/contacts"
primary="Contacts"
icon={<People />}
/>
)}
{previewEnabled && (
<ListItemLink
onClick={onLinkClick}
to="/issuers"
primary="Asset Issuers"
icon={<AddCircle />}
/>
)}
</List>
</nav>
);
};

export default NavMenu;
export default withApplicationContext(NavMenu, context => ({
previewEnabled: context.previewEnabled,
}));
39 changes: 23 additions & 16 deletions packages/wallet/ui/src/components/Purses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import Loading from './Loading';
import './Purses.scss';

// Exported for testing only.
export const PursesWithoutContext = ({ purses, pendingTransfers }) => {
export const PursesWithoutContext = ({
purses,
pendingTransfers,
previewEnabled,
}) => {
const [openPurse, setOpenPurse] = useState(null);

const handleClickOpen = purse => {
Expand All @@ -36,21 +40,23 @@ export const PursesWithoutContext = ({ purses, pendingTransfers }) => {
/>
</ErrorBoundary>
</div>
<div className="Right">
{pendingTransfers.has(purse.id) ? (
<div className="PurseProgressWrapper">
<CircularProgress size={30} />
</div>
) : (
<Button
variant="outlined"
size="small"
onClick={() => handleClickOpen(purse)}
>
Send
</Button>
)}
</div>
{previewEnabled && (
<div className="Right">
{pendingTransfers.has(purse.id) ? (
<div className="PurseProgressWrapper">
<CircularProgress size={30} />
</div>
) : (
<Button
variant="outlined"
size="small"
onClick={() => handleClickOpen(purse)}
>
Send
</Button>
)}
</div>
)}
</CardItem>
);
};
Expand All @@ -69,4 +75,5 @@ export const PursesWithoutContext = ({ purses, pendingTransfers }) => {
export default withApplicationContext(PursesWithoutContext, context => ({
purses: context.purses,
pendingTransfers: context.pendingTransfers,
previewEnabled: context.previewEnabled,
}));
1 change: 1 addition & 0 deletions packages/wallet/ui/src/components/Transfer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export const TransferInternal = ({
value={type}
onChange={handleTypeChange}
>
{/* TODO by default hide "within wallet" until https://github.com/Agoric/agoric-sdk/issues/6126 */}
<FormControlLabel
value={transferTypes.WITHIN_WALLET}
control={<Radio color="primary" />}
Expand Down
2 changes: 2 additions & 0 deletions packages/wallet/ui/src/components/tests/Purses.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const pendingTransfers = new Set([0]);
const withApplicationContext =
(Component, _) =>
({ ...props }) => {
// Test the preview features
props.previewEnabled = true;
return (
<Component
purses={purses}
Expand Down
5 changes: 5 additions & 0 deletions packages/wallet/ui/src/contexts/Provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ const Provider = ({ children }) => {
const [schemaActions, setSchemaActions] = useState(null);
const [connectionComponent, setConnectionComponent] = useState(null);
const [backendErrorHandler, setBackendErrorHandler] = useState(null);
const [previewEnabled, setPreviewEnabled] = useState(false);
// expose for development
window.setPreviewEnabled = setPreviewEnabled;

const RESTORED_CONNECTION_CONFIGS = [...DEFAULT_CONNECTION_CONFIGS];
const userConnectionConfigs = maybeLoad('userConnectionConfigs');
Expand Down Expand Up @@ -435,6 +438,7 @@ const Provider = ({ children }) => {
setBackendErrorHandler,
keplrConnection,
tryKeplrConnect,
previewEnabled,
};

useDebugLogging(state, [
Expand All @@ -451,6 +455,7 @@ const Provider = ({ children }) => {
pendingOffers,
declinedOffers,
closedOffers,
previewEnabled,
]);

return (
Expand Down

0 comments on commit fedf049

Please sign in to comment.