From 12dccc830e8297ae7b23149b73ff93f820b25884 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Wed, 20 Dec 2023 16:30:03 +0800 Subject: [PATCH 1/9] fix: issue 288 --- .../broadcastTransaction.module.scss | 42 ++++++ .../components/BroadcastTransaction/index.tsx | 124 ++++++++++++++++++ .../src/components/OfflineSign/index.tsx | 60 ++++----- .../OfflineSign/offlineSign.module.scss | 10 ++ .../components/OfflineSignDialog/index.tsx | 7 +- packages/neuron-ui/src/locales/en.json | 7 +- packages/neuron-ui/src/locales/zh-tw.json | 7 +- packages/neuron-ui/src/locales/zh.json | 7 +- packages/neuron-ui/src/router.tsx | 5 + packages/neuron-ui/src/utils/enums.ts | 1 + .../neuron-wallet/src/controllers/app/menu.ts | 13 ++ packages/neuron-wallet/src/locales/en.ts | 1 + packages/neuron-wallet/src/locales/zh-tw.ts | 1 + packages/neuron-wallet/src/locales/zh.ts | 1 + 14 files changed, 248 insertions(+), 38 deletions(-) create mode 100644 packages/neuron-ui/src/components/BroadcastTransaction/broadcastTransaction.module.scss create mode 100644 packages/neuron-ui/src/components/BroadcastTransaction/index.tsx diff --git a/packages/neuron-ui/src/components/BroadcastTransaction/broadcastTransaction.module.scss b/packages/neuron-ui/src/components/BroadcastTransaction/broadcastTransaction.module.scss new file mode 100644 index 0000000000..56ed207431 --- /dev/null +++ b/packages/neuron-ui/src/components/BroadcastTransaction/broadcastTransaction.module.scss @@ -0,0 +1,42 @@ +.main { + tr { + td { + font-size: 14px; + line-height: 26px; + color: var(--main-text-color); + svg { + width: 14px; + height: 14px; + margin-right: 4px; + position: relative; + top: 2px; + } + } + .first { + padding-right: 24px; + color: var(--input-second-color); + } + } +} + +.warningDialog { + width: 680px; + .content { + display: flex; + justify-content: center; + margin-top: 24px; + color: var(--main-text-color); + } +} + +.textarea { + color: var(--main-text-color); + margin-top: 17px; + width: 648px; + height: 206px; + resize: none; + background: var(--secondary-background-color); + border: 1px solid var(--divide-line-color); + border-radius: 8px; + padding: 16px; +} diff --git a/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx b/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx new file mode 100644 index 0000000000..b181829853 --- /dev/null +++ b/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx @@ -0,0 +1,124 @@ +import React, { useCallback, useMemo, useState } from 'react' +import { useTranslation } from 'react-i18next' +import { useNavigate } from 'react-router-dom' +import { isSuccessResponse, RoutePath, useDidMount, useGoBack } from 'utils' +import Dialog from 'widgets/Dialog' +import AlertDialog from 'widgets/AlertDialog' +import { useDispatch, useState as useGlobalState } from 'states' +import { broadcastTransaction, getCurrentWallet, OfflineSignStatus } from 'services/remote' +import { ReactComponent as HardWalletIcon } from 'widgets/Icons/HardWallet.svg' + +import styles from './broadcastTransaction.module.scss' + +const BroadcastTransaction = () => { + const { + app: { loadedTransaction = {} }, + } = useGlobalState() + + const [wallet, setWallet] = useState(null) + const [isBroadCasting, setIsBroadcasting] = useState(false) + const [t] = useTranslation() + const dispatch = useDispatch() + const [errMsg, setErrMsg] = useState('') + + const { filePath, json } = loadedTransaction + + const jsonContent = useMemo(() => { + return JSON.stringify(json, null, 2) + }, [json]) + + const signStatus: OfflineSignStatus = json.status + + const isSigned = useMemo(() => signStatus === OfflineSignStatus.Signed, [signStatus]) + + const onBack = useGoBack() + + const navigate = useNavigate() + const onBroadcast = useCallback(async () => { + setIsBroadcasting(true) + try { + const res = await broadcastTransaction({ + ...json, + walletID: wallet!.id, + }) + if (isSuccessResponse(res)) { + navigate(RoutePath.History) + } else { + setErrMsg(typeof res.message === 'string' ? res.message : res.message.content || '') + } + } finally { + setIsBroadcasting(false) + } + }, [wallet, json, navigate, dispatch]) + + useDidMount(() => { + getCurrentWallet().then(res => { + if (isSuccessResponse(res)) { + setWallet(res.result) + } + }) + }) + + return ( + <> + +
+ + + + + + + + + + + + + + + + + + +
{t('offline-sign.json-file')}{filePath}
{t('offline-sign.status.label')}{t('offline-sign.status.signed')}
{t('offline-sign.wallet')} + {wallet?.device ? : null} + {wallet?.name ?? ''} +
{t('offline-sign.content')}
+