Skip to content

Commit cd7d7e5

Browse files
committed
feat(neuron-ui): add popping messages on copying and updating
1 parent 099c2f5 commit cd7d7e5

15 files changed

Lines changed: 156 additions & 50 deletions

File tree

packages/neuron-ui/src/components/Overview/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from 'office-ui-fabric-react'
2222

2323
import { StateWithDispatch } from 'states/stateProvider/reducer'
24-
import { updateTransactionList } from 'states/stateProvider/actionCreators'
24+
import { updateTransactionList, addPopup } from 'states/stateProvider/actionCreators'
2525

2626
import { showErrorMessage } from 'services/remote'
2727

@@ -281,11 +281,11 @@ const Overview = ({
281281
if (defaultAddress) {
282282
window.navigator.clipboard.writeText(defaultAddress.identifier)
283283
hideMinerInfo()
284-
// TODO: Add notification
284+
addPopup('lock-arg-copid')(dispatch)
285285
} else {
286286
showErrorMessage(t('messages.error'), t('messages.can-not-find-the-default-address'))
287287
}
288-
}, [defaultAddress, t, hideMinerInfo])
288+
}, [defaultAddress, t, hideMinerInfo, dispatch])
289289

290290
return (
291291
<Stack tokens={{ childrenGap: 15 }} verticalFill horizontalAlign="stretch">

packages/neuron-ui/src/components/Receive/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { Stack, Text, TextField, TooltipHost, Modal, FontSizes, IconButton } fro
55

66
import { StateWithDispatch } from 'states/stateProvider/reducer'
77
import QRCode from 'widgets/QRCode'
8+
import { addPopup } from 'states/stateProvider/actionCreators'
89

910
const Receive = ({
1011
wallet: { addresses = [] },
1112
match: { params },
13+
dispatch,
1214
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps<{ address: string }>>) => {
1315
const [t] = useTranslation()
1416
const [showLargeQRCode, setShowLargeQRCode] = useState(false)
@@ -23,7 +25,8 @@ const Receive = ({
2325

2426
const copyAddress = useCallback(() => {
2527
window.navigator.clipboard.writeText(accountAddress)
26-
}, [accountAddress])
28+
addPopup('addr-copied')(dispatch)
29+
}, [accountAddress, dispatch])
2730

2831
if (!accountAddress) {
2932
return <div>{t('receive.address-not-found')}</div>
@@ -55,7 +58,13 @@ const Receive = ({
5558
</Stack>
5659

5760
<Stack style={{ alignSelf: 'center' }}>
58-
<QRCode value={accountAddress} onQRCodeClick={() => setShowLargeQRCode(true)} size={256} exportable />
61+
<QRCode
62+
value={accountAddress}
63+
onQRCodeClick={() => setShowLargeQRCode(true)}
64+
size={256}
65+
exportable
66+
dispatch={dispatch}
67+
/>
5968
</Stack>
6069
</Stack>
6170

@@ -78,7 +87,7 @@ const Receive = ({
7887
</Text>
7988
</Stack>
8089
<Stack tokens={{ padding: '15px' }}>
81-
<QRCode value={accountAddress} size={400} />
90+
<QRCode value={accountAddress} size={400} dispatch={dispatch} />
8291
</Stack>
8392
</Modal>
8493
</>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.autoDismissMessages {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: flex-end;
5+
position: absolute;
6+
right: 0;
7+
8+
&>div {
9+
max-width: auto;
10+
margin: 3px;
11+
animation: autoDismiss 2.5s ease-out forwards;
12+
transform-origin: center top;
13+
box-sizing: border-box;
14+
box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.25);
15+
}
16+
}
17+
18+
@keyframes autoDismiss {
19+
from {
20+
transform: translateX(110%)
21+
}
22+
23+
15%,
24+
85% {
25+
26+
transform: translateX(0)
27+
}
28+
29+
30+
100% {
31+
transform: translateX(110%)
32+
}
33+
}

packages/neuron-ui/src/containers/Notification/index.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'
55
import { MessageBar, MessageBarType, IconButton } from 'office-ui-fabric-react'
66
import { NeuronWalletContext } from 'states/stateProvider'
77
import { StateWithDispatch, AppActions } from 'states/stateProvider/reducer'
8+
import styles from './Notification.module.scss'
89

910
const notificationType = (type: 'success' | 'warning' | 'alert') => {
1011
switch (type) {
@@ -29,7 +30,7 @@ const DismissButton = ({ onDismiss }: { onDismiss: React.MouseEventHandler<HTMLB
2930

3031
const NoticeContent = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
3132
const {
32-
app: { notifications = [] },
33+
app: { notifications = [], popups = [] },
3334
} = useContext(NeuronWalletContext)
3435
const [t] = useTranslation()
3536
const onDismiss = useCallback(() => {
@@ -38,28 +39,36 @@ const NoticeContent = ({ dispatch }: React.PropsWithoutRef<StateWithDispatch & R
3839
payload: null,
3940
})
4041
}, [dispatch])
41-
if (!notifications.length) {
42-
return null
43-
}
4442

4543
const notification = notifications[0]
4644

4745
return (
48-
<MessageBar
49-
messageBarType={notificationType(notification.type)}
50-
styles={{
51-
root: {
52-
flexDirection: 'row',
53-
},
54-
actions: {
55-
margin: 0,
56-
marginRight: '12px',
57-
},
58-
}}
59-
actions={<DismissButton onDismiss={onDismiss} />}
60-
>
61-
{t(notification.content)}
62-
</MessageBar>
46+
<div>
47+
{notifications.length ? (
48+
<MessageBar
49+
messageBarType={notificationType(notification.type)}
50+
styles={{
51+
root: {
52+
flexDirection: 'row',
53+
},
54+
actions: {
55+
margin: 0,
56+
marginRight: '12px',
57+
},
58+
}}
59+
actions={<DismissButton onDismiss={onDismiss} />}
60+
>
61+
{t(notification.content)}
62+
</MessageBar>
63+
) : null}
64+
<div className={styles.autoDismissMessages}>
65+
{popups.map(popup => (
66+
<MessageBar key={`${popup.timestamp}`} messageBarType={MessageBarType.success}>
67+
{t(popup.text)}
68+
</MessageBar>
69+
))}
70+
</div>
71+
</div>
6372
)
6473
}
6574

packages/neuron-ui/src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { loadTheme, getTheme } from 'office-ui-fabric-react'
55
import {
66
AddCircle as AddIcon,
77
Alert as AlertIcon,
8+
Checkmark as SuccessIcon,
89
Close as DismissIcon,
910
Copy as CopyIcon,
1011
Down as ArrowDownIcon,
@@ -58,6 +59,7 @@ const { semanticColors } = theme
5859
registerIcons({
5960
icons: {
6061
errorbadge: <AlertIcon size="16px" />,
62+
completed: <SuccessIcon size="16px" />,
6163
MiniCopy: <CopyIcon size="small" />,
6264
Search: <SearchIcon size="16px" color={semanticColors.menuIcon} />,
6365
FirstPage: <LinkTopIcon size="16px" color={semanticColors.menuIcon} style={{ transform: 'rotate(-90deg)' }} />,

packages/neuron-ui/src/locales/en.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,17 @@
217217
"invalid-mnemonic": "Invalid mnemonic words",
218218
"camera-not-available-or-disabled": "Camera is unavailable or disabled",
219219
"can-not-find-the-default-address": "Cannot find the default address",
220-
"amount-too-small": "Amount should not be less than 61 CKB"
220+
"amount-too-small": "Amount should not be less than 61 CKB",
221+
"create-wallet-successfully": "Create a wallet successfully",
222+
"import-wallet-successfully": "Import a wallet successfully",
223+
"update-wallet-successfully": "Update the wallet successfully",
224+
"delete-wallet-successfully": "Delete the wallet successfully",
225+
"create-network-successfully": "Create a network successfully",
226+
"update-network-successfully": "Update the network successfully",
227+
"delete-network-successfully": "Delete the network successfully",
228+
"addr-copied": "Address has been copied to the clipboard",
229+
"qrcode-copied": "QR Code has been copied to the clipboard",
230+
"lock-arg-copid": "Lock Arg has been copied to the clipboard"
221231
},
222232
"sync": {
223233
"syncing": "Syncing",

packages/neuron-ui/src/locales/zh.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,17 @@
217217
"invalid-mnemonic": "助记词不合法",
218218
"camera-not-available-or-disabled": "摄像头不可用或被禁用",
219219
"can-not-find-the-default-address": "未获得默认地址",
220-
"amount-too-small": "金额应不小于 61 CKB"
220+
"amount-too-small": "金额应不小于 61 CKB",
221+
"create-wallet-successfully": "新建钱包成功",
222+
"import-wallet-successfully": "导入钱包成功",
223+
"update-wallet-successfully": "已更新钱包信息",
224+
"delete-wallet-successfully": "已删除钱包",
225+
"create-network-successfully": "新节点已添加",
226+
"update-network-successfully": "已更新节点信息",
227+
"delete-network-successfully": "节点已删除",
228+
"addr-copied": "地址已复制到剪贴板",
229+
"qrcode-copied": "二维码已复制到剪贴板",
230+
"lock-arg-copid": "Lock Arg 已复制到剪贴板"
221231
},
222232
"sync": {
223233
"syncing": "同步中",

packages/neuron-ui/src/states/initStates/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const appState: State.App = {
3131
transactions: null,
3232
wizard: null,
3333
},
34+
popups: [],
3435
notifications: [],
3536
loadings: {
3637
sending: false,

packages/neuron-ui/src/states/stateProvider/actionCreators/app.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,21 @@ export const addNotification = ({ type, content }: { type: 'alert'; content: str
8585
})
8686
}
8787

88+
export const addPopup = (text: string) => (dispatch: StateDispatch) => {
89+
dispatch({
90+
type: AppActions.PopIn,
91+
payload: { text: `messages.${text}`, timestamp: Date.now() },
92+
})
93+
setTimeout(() => {
94+
dispatch({
95+
type: AppActions.PopOut,
96+
payload: null,
97+
})
98+
}, 3000)
99+
}
100+
88101
export default {
89102
initAppState,
90103
addNotification,
104+
addPopup,
91105
}

packages/neuron-ui/src/states/stateProvider/actionCreators/settings.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createNetwork as createRemoteNetwork, updateNetwork as updateRemoteNetwork } from 'services/remote'
22
import { addressBook } from 'utils/localCache'
33
import { Routes } from 'utils/const'
4-
import { addNotification } from './app'
4+
import { addNotification, addPopup } from './app'
55

66
import { AppActions, StateDispatch } from '../reducer'
77

@@ -20,6 +20,7 @@ export const createNetwork = (params: Controller.CreateNetworkParams) => (dispat
2020
type: AppActions.Ignore,
2121
payload: null,
2222
})
23+
addPopup('create-network-successfully')(dispatch)
2324
history.push(Routes.SettingsNetworks)
2425
} else {
2526
addNotification({ type: 'alert', content: res.message.title })(dispatch)
@@ -30,10 +31,7 @@ export const createNetwork = (params: Controller.CreateNetworkParams) => (dispat
3031
export const updateNetwork = (params: Controller.UpdateNetworkParams) => (dispatch: StateDispatch, history: any) => {
3132
updateRemoteNetwork(params).then(res => {
3233
if (res.status) {
33-
dispatch({
34-
type: AppActions.Ignore,
35-
payload: null,
36-
})
34+
addPopup('update-network-successfully')(dispatch)
3735
history.push(Routes.SettingsNetworks)
3836
} else {
3937
addNotification({ type: 'alert', content: res.message.title })(dispatch)

0 commit comments

Comments
 (0)