Skip to content

Commit

Permalink
Merge pull request #925 from nymtech/feature/ui-enhancements
Browse files Browse the repository at this point in the history
Feature/UI enhancements for Desktop Wallet
  • Loading branch information
tommyv1987 authored Dec 1, 2021
2 parents eb93b42 + 04b6f83 commit 0f93dde
Show file tree
Hide file tree
Showing 56 changed files with 3,283 additions and 2,979 deletions.
7 changes: 7 additions & 0 deletions nym-wallet/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"semi": false
}
17 changes: 17 additions & 0 deletions nym-wallet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions nym-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
},
"dependencies": {
"@babel/preset-typescript": "^7.15.0",
"@emotion/react": "^11.7.0",
"@emotion/styled": "^11.6.0",
"@hookform/resolvers": "^2.8.0",
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.60",
"@material-ui/styles": "^4.11.4",
"@mui/icons-material": "^5.2.0",
"@mui/material": "^5.2.2",
"@mui/styles": "^5.2.2",
"@types/react-dom": "^17.0.9",
"bs58": "^4.0.1",
"clsx": "^1.1.1",
Expand Down Expand Up @@ -48,8 +49,8 @@
"html-webpack-plugin": "^5.3.2",
"style-loader": "^3.2.1",
"url-loader": "^4.1.1",
"webpack": "^5.50.0",
"webpack": "^5.64.3",
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.1.0"
"webpack-dev-server": "^4.5.0"
}
}
8 changes: 8 additions & 0 deletions nym-wallet/public/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap"
rel="stylesheet"
/>
<title>Nym Wallet</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion nym-wallet/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tauri-build = { version = "1.0.0-beta.4" }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-beta.8", features = [] }
tauri = { version = "1.0.0-beta.8", features = ["shell-open"] }
tokio = { version = "1.10", features = ["sync"] }
dirs = "4.0"
bip39 = "1.0"
Expand Down
9 changes: 6 additions & 3 deletions nym-wallet/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@
"updater": {
"active": false
},
"allowlist": {},
"allowlist": {
"shell": {
"open": true
}
},
"windows": [
{
"title": "nym-wallet",
"width": 1268,
"height": 768,
"resizable": true,
"fullscreen": false
"resizable": true
}
],
"security": {
Expand Down
21 changes: 8 additions & 13 deletions nym-wallet/src/components/AdminForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import {
Paper,
Slide,
TextField,
Theme,
} from '@material-ui/core'
import { useTheme } from '@material-ui/styles'
} from '@mui/material'

import { ClientContext } from '../context/main'
import { NymCard } from '.'
import { getContractParams, setContractParams } from '../requests'
Expand Down Expand Up @@ -77,13 +76,9 @@ const AdminForm: React.FC<{
onCancel()
}

const theme: Theme = useTheme()

return (
<FormControl fullWidth>
<div
style={{ padding: theme.spacing(3, 5), maxWidth: 700, minWidth: 400 }}
>
<Box sx={{ padding: [3, 5], maxWidth: 700, minWidth: 400 }}>
<Grid container spacing={3}>
<Grid item xs={12}>
<TextField
Expand Down Expand Up @@ -190,15 +185,15 @@ const AdminForm: React.FC<{
/>
</Grid>
</Grid>
</div>
</Box>
<Grid
container
spacing={1}
justifyContent="flex-end"
style={{
borderTop: `1px solid ${theme.palette.grey[200]}`,
background: theme.palette.grey[100],
padding: theme.spacing(2),
sx={{
borderTop: (theme) => `1px solid ${theme.palette.grey[200]}`,
background: (theme) => theme.palette.grey[100],
padding: 2,
}}
>
<Grid item>
Expand Down
95 changes: 95 additions & 0 deletions nym-wallet/src/components/AppBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, { useContext, useEffect } from 'react'
import {
AppBar as MuiAppBar,
Divider,
Grid,
IconButton,
Toolbar,
Typography,
useMediaQuery,
} from '@mui/material'
import { Box } from '@mui/system'
import { Logout } from '@mui/icons-material'
import { ClientContext } from '../context/main'
import { CopyToClipboard } from '.'

export const AppBar = () => {
const { userBalance, logOut, clientDetails } = useContext(ClientContext)
const matches = useMediaQuery('(min-width: 769px)')

return (
<MuiAppBar
position="sticky"
sx={{ boxShadow: 'none', bgcolor: 'nym.background.light' }}
>
<Toolbar>
<Grid
container
justifyContent="space-between"
alignItems="center"
flexWrap="nowrap"
>
<Grid container item alignItems="center">
<Grid item>
<AppBarItem
primaryText="Balance"
secondaryText={userBalance.balance?.printable_balance}
/>
</Grid>
{matches && (
<>
<Divider
orientation="vertical"
variant="middle"
flexItem
sx={{ mr: 1 }}
/>

<Grid item>
<AppBarItem
primaryText="Address"
secondaryText={clientDetails?.client_address}
Action={
<CopyToClipboard
text={clientDetails?.client_address}
iconButton
/>
}
/>
</Grid>
</>
)}
</Grid>
<Grid item>
<IconButton onClick={logOut} sx={{ color: 'nym.background.dark' }}>
<Logout />
</IconButton>
</Grid>
</Grid>
</Toolbar>
</MuiAppBar>
)
}

const AppBarItem: React.FC<{
primaryText: string
secondaryText?: string
Action?: React.ReactNode
}> = ({ primaryText, secondaryText = '', Action }) => {
return (
<Box sx={{ p: 1, mr: 1 }}>
<Typography variant="body2" component="span" sx={{ color: 'grey.600' }}>
{primaryText}:
</Typography>{' '}
<Typography
variant="body2"
component="span"
color="nym.background.dark"
sx={{ mr: 1 }}
>
{secondaryText}
</Typography>
{Action}
</Box>
)
}
11 changes: 7 additions & 4 deletions nym-wallet/src/components/Confirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react'
import Typography from '@material-ui/core/Typography'
import Grid from '@material-ui/core/Grid'
import { CircularProgress } from '@material-ui/core'
import { Alert, AlertTitle } from '@material-ui/lab'
import {
Alert,
AlertTitle,
CircularProgress,
Grid,
Typography,
} from '@mui/material'

type ConfirmationProps = {
isLoading: boolean
Expand Down
105 changes: 68 additions & 37 deletions nym-wallet/src/components/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,82 @@
import React, { useState } from 'react'
import { Button } from '@material-ui/core'
import { Check } from '@material-ui/icons'
import { green } from '@material-ui/core/colors'
import React, { useEffect, useState } from 'react'
import { Button, IconButton, Tooltip } from '@mui/material'
import { Check, ContentCopy } from '@mui/icons-material'
import { clipboard } from '@tauri-apps/api'

const copy = (text: string): Promise<{ success: boolean; value: string }> => {
return new Promise((resolve, reject) => {
clipboard
.writeText(text)
.then(() => resolve({ success: true, value: text }))
.catch((e) => reject({ success: false, value: 'Failed to copy: ' + e }))
})
}

export const handleCopy = async ({
text,
cb,
export const CopyToClipboard = ({
text = '',
light,
iconButton,
}: {
text: string
cb: (success: boolean) => void
text?: string
light?: boolean
iconButton?: boolean
}) => {
const res = await copy(text)
if (res.success) {
setTimeout(() => {
cb(true)
}, 750)
} else {
console.log(res.value)
const [copied, setCopied] = useState(false)

const handleCopy = async (text: string) => {
try {
await clipboard.writeText(text)
setCopied(true)
} catch (e) {
console.log('failed to copy: ' + e)
}
}
}

export const CopyToClipboard = ({ text }: { text: string }) => {
const [copied, setCopied] = useState(false)
useEffect(() => {
let timer: NodeJS.Timeout
if (copied) {
timer = setTimeout(() => {
setCopied(false)
}, 2000)
}
return () => clearTimeout(timer)
}, [copied])

const updateCopyStatus = (isCopied: boolean) => setCopied(isCopied)
if (iconButton)
return (
<Tooltip title={!copied ? 'Copy' : 'Copied!'} leaveDelay={500}>
<IconButton
onClick={() => handleCopy(text)}
size="small"
sx={{
color: (theme) =>
light
? theme.palette.common.white
: theme.palette.nym.background.dark,
}}
>
{!copied ? (
<ContentCopy fontSize="small" />
) : (
<Check color="success" />
)}
</IconButton>
</Tooltip>
)

return (
<Button
size="small"
variant={copied ? 'text' : 'outlined'}
aria-label="save"
data-testid="copy-button"
onClick={() => handleCopy({ text, cb: updateCopyStatus })}
endIcon={copied && <Check />}
style={copied ? { background: green[500], color: 'white' } : {}}
variant="outlined"
color="inherit"
sx={{
color: (theme) =>
light
? theme.palette.common.white
: theme.palette.nym.background.dark,
borderColor: (theme) =>
light
? theme.palette.common.white
: theme.palette.nym.background.dark,
}}
onClick={() => handleCopy(text)}
endIcon={
copied && (
<Check sx={{ color: (theme) => theme.palette.success.light }} />
)
}
>
{copied ? 'Copied' : 'Copy'}
{!copied ? 'Copy' : 'Copied'}
</Button>
)
}
Loading

0 comments on commit 0f93dde

Please sign in to comment.