From 28094280758c747edc288413d5993f927b342c34 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Mon, 29 Jan 2024 17:44:17 +0800 Subject: [PATCH 1/5] fix: Hot/cold combination of a wallet doesn't work smooth (#3000) * fix: issue 288 * fix: broadcastTransaction * fix: BroadcastTransaction * fix: French * fix: broadcastTransactionOnly * fix: comments * fix: broadcastSignedTransaction * fix * feat: remove Wallet field --------- Co-authored-by: Chen Yu --- .../broadcastTransaction.module.scss | 42 +++++ .../components/BroadcastTransaction/index.tsx | 136 +++++++++++++++ .../src/components/OfflineSign/index.tsx | 60 ++++--- .../OfflineSign/offlineSign.module.scss | 10 ++ .../components/OfflineSignDialog/index.tsx | 7 +- packages/neuron-ui/src/locales/en.json | 10 +- packages/neuron-ui/src/locales/fr.json | 156 +++++++++--------- packages/neuron-ui/src/locales/zh-tw.json | 10 +- packages/neuron-ui/src/locales/zh.json | 10 +- packages/neuron-ui/src/router.tsx | 5 + .../neuron-ui/src/services/remote/offline.ts | 3 + .../src/services/remote/remoteApiWrapper.ts | 1 + packages/neuron-ui/src/utils/enums.ts | 1 + packages/neuron-wallet/src/controllers/api.ts | 4 + .../neuron-wallet/src/controllers/app/menu.ts | 12 ++ 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 + .../src/services/asset-account-service.ts | 2 +- .../src/services/transaction-sender.ts | 6 +- 20 files changed, 359 insertions(+), 119 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..ccc1da482c --- /dev/null +++ b/packages/neuron-ui/src/components/BroadcastTransaction/index.tsx @@ -0,0 +1,136 @@ +import React, { useCallback, useMemo, useState } from 'react' +import { useTranslation } from 'react-i18next' +import { useNavigate } from 'react-router-dom' +import { isSuccessResponse, RoutePath, isMainnet as isMainnetUtil, useGoBack, getExplorerUrl } from 'utils' +import Dialog from 'widgets/Dialog' +import AlertDialog from 'widgets/AlertDialog' +import { useDispatch, useState as useGlobalState } from 'states' +import { broadcastSignedTransaction, OfflineSignStatus, openExternal, getTransactionList } from 'services/remote' + +import styles from './broadcastTransaction.module.scss' + +const BroadcastTransaction = () => { + const { + app: { loadedTransaction = {} }, + chain: { networkID }, + settings: { networks }, + wallet, + } = useGlobalState() + + const [isBroadcasting, setIsBroadcasting] = useState(false) + const [broadcastedTxHash, setBroadcastedTxHash] = useState('') + const [t] = useTranslation() + const dispatch = useDispatch() + const [errMsg, setErrMsg] = useState('') + const isMainnet = isMainnetUtil(networks, networkID) + + 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 () => { + if (broadcastedTxHash) { + openExternal(`${getExplorerUrl(isMainnet)}/transaction/${broadcastedTxHash}`) + return + } + + setIsBroadcasting(true) + + const res = await broadcastSignedTransaction({ + ...json, + }) + + setIsBroadcasting(false) + + if (isSuccessResponse(res)) { + if (!wallet?.id) { + setBroadcastedTxHash(res.result) + return + } + + if (res.result) { + getTransactionList({ + walletID: wallet.id, + pageNo: 1, + pageSize: 10, + keywords: res.result, + }).then(txRes => { + if (isSuccessResponse(txRes) && txRes.result.items.length) { + navigate(RoutePath.History) + } else { + setBroadcastedTxHash(res.result) + } + }) + } + } else { + setErrMsg(typeof res.message === 'string' ? res.message : res.message.content || '') + } + }, [wallet, json, navigate, dispatch, broadcastedTxHash, setBroadcastedTxHash]) + + return ( + <> + +
+ + + + + + + + + + + + + + +
{t('offline-sign.json-file')}{filePath}
{t('offline-sign.status.label')}{t('offline-sign.status.signed')}
{t('offline-sign.content')}
+