From c6f3be3b25eda755cc11f54f42406726011052e7 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Sun, 23 Apr 2023 13:41:00 +0800 Subject: [PATCH] feat: Offline Sign with new ui (#2638) --- .../src/components/OfflineSign/index.tsx | 149 ++++++++---------- .../OfflineSign/offlineSign.module.scss | 82 +++------- .../components/OfflineSignDialog/index.tsx | 50 ++---- .../src/widgets/Button/button.module.scss | 3 +- 4 files changed, 105 insertions(+), 179 deletions(-) diff --git a/packages/neuron-ui/src/components/OfflineSign/index.tsx b/packages/neuron-ui/src/components/OfflineSign/index.tsx index 121e53cd59..ebe5b8159b 100644 --- a/packages/neuron-ui/src/components/OfflineSign/index.tsx +++ b/packages/neuron-ui/src/components/OfflineSign/index.tsx @@ -1,9 +1,8 @@ -import React, { useRef, useCallback, useMemo, useState, useEffect } from 'react' +import React, { useCallback, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { useNavigate } from 'react-router-dom' import { isSuccessResponse, RoutePath, useDidMount } from 'utils' -import Button from 'widgets/Button' -import Spinner from 'widgets/Spinner' +import Dialog from 'widgets/Dialog' import { addNotification, useDispatch, useState as useGlobalState } from 'states' import { broadcastTransaction, getCurrentWallet, OfflineSignStatus } from 'services/remote' import { ReactComponent as HardWalletIcon } from 'widgets/Icons/HardWallet.svg' @@ -12,7 +11,6 @@ import OfflineSignDialog from '../OfflineSignDialog' import styles from './offlineSign.module.scss' const OfflineSign = () => { - const dialogRef = useRef(null) const { app: { loadedTransaction = {} }, } = useGlobalState() @@ -48,41 +46,33 @@ const OfflineSign = () => { navigate(-1) }, [navigate]) - const onSign = useCallback( - (e: React.FormEvent) => { - e.preventDefault() - setIsSigning(true) - }, - [setIsSigning] - ) - - const onBroadcast = useCallback( - async (e: React.FormEvent) => { - e.preventDefault() - setIsBroadcasting(true) - try { - const res = await broadcastTransaction({ - ...json, - walletID: wallet!.id, - }) - if (isSuccessResponse(res)) { - navigate(RoutePath.History) - } else { - addNotification({ - type: 'alert', - timestamp: +new Date(), - code: res.status, - content: typeof res.message === 'string' ? res.message : res.message.content, - meta: typeof res.message === 'string' ? undefined : res.message.meta, - })(dispatch) - onBack() - } - } finally { - setIsBroadcasting(false) + const onSign = useCallback(() => { + setIsSigning(true) + }, [setIsSigning]) + + const onBroadcast = useCallback(async () => { + setIsBroadcasting(true) + try { + const res = await broadcastTransaction({ + ...json, + walletID: wallet!.id, + }) + if (isSuccessResponse(res)) { + navigate(RoutePath.History) + } else { + addNotification({ + type: 'alert', + timestamp: +new Date(), + code: res.status, + content: typeof res.message === 'string' ? res.message : res.message.content, + meta: typeof res.message === 'string' ? undefined : res.message.meta, + })(dispatch) + onBack() } - }, - [wallet, json, navigate, dispatch, onBack] - ) + } finally { + setIsBroadcasting(false) + } + }, [wallet, json, navigate, dispatch, onBack]) useDidMount(() => { getCurrentWallet().then(res => { @@ -92,12 +82,6 @@ const OfflineSign = () => { }) }) - useEffect(() => { - if (!isSigning && dialogRef.current && !dialogRef.current.open) { - dialogRef.current.showModal() - } - }, [isSigning]) - const signDialogOnDismiss = useCallback(() => { setIsSigning(false) }, []) @@ -109,46 +93,43 @@ const OfflineSign = () => { } return ( - -
-
{t('offline-sign.title')}
-
- - - - - - - - - - - - - - - - - - -
{t('offline-sign.json-file')}{filePath}
{t('offline-sign.status.label')}{status}
{t('offline-sign.wallet')} - {wallet?.device ? : null} - {wallet?.name ?? ''} -
{t('offline-sign.content')}
-