-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #925 from nymtech/feature/ui-enhancements
Feature/UI enhancements for Desktop Wallet
- Loading branch information
Showing
56 changed files
with
3,283 additions
and
2,979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"semi": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
Oops, something went wrong.