Skip to content

Commit

Permalink
fix: BroadcastTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
devchenyan committed Jan 13, 2024
1 parent bf3ea9b commit 17cc1a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
34 changes: 10 additions & 24 deletions packages/neuron-ui/src/components/BroadcastTransaction/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import React, { useCallback, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'
import { isSuccessResponse, RoutePath, isMainnet as isMainnetUtil, useDidMount, useGoBack, getExplorerUrl } from 'utils'
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 {
broadcastTransactionOnly,
getCurrentWallet,
OfflineSignStatus,
openExternal,
getLiveCells,
} from 'services/remote'
import { broadcastTransactionOnly, OfflineSignStatus, openExternal, getLiveCells } from 'services/remote'
import { ReactComponent as HardWalletIcon } from 'widgets/Icons/HardWallet.svg'

import styles from './broadcastTransaction.module.scss'
Expand All @@ -21,11 +15,11 @@ const BroadcastTransaction = () => {
app: { loadedTransaction = {} },
chain: { networkID },
settings: { networks },
wallet,
} = useGlobalState()

const [wallet, setWallet] = useState<State.Wallet | null>(null)
const [isBroadCasting, setIsBroadcasting] = useState(false)
const [broadCastedTxHash, setBroadCastedTxHash] = useState('')
const [isBroadcasting, setIsBroadcasting] = useState(false)
const [broadcastedTxHash, setBroadCastedTxHash] = useState('')
const [t] = useTranslation()
const dispatch = useDispatch()
const [errMsg, setErrMsg] = useState('')
Expand All @@ -45,8 +39,8 @@ const BroadcastTransaction = () => {

const navigate = useNavigate()
const onBroadcast = useCallback(async () => {
if (broadCastedTxHash) {
openExternal(`${getExplorerUrl(isMainnet)}/transaction/${broadCastedTxHash}`)
if (broadcastedTxHash) {
openExternal(`${getExplorerUrl(isMainnet)}/transaction/${broadcastedTxHash}`)
return
}

Expand Down Expand Up @@ -76,15 +70,7 @@ const BroadcastTransaction = () => {
} finally {
setIsBroadcasting(false)
}
}, [wallet, json, navigate, dispatch, broadCastedTxHash, setBroadCastedTxHash])

useDidMount(() => {
getCurrentWallet().then(res => {
if (isSuccessResponse(res)) {
setWallet(res.result)
}
})
})
}, [wallet, json, navigate, dispatch, broadcastedTxHash, setBroadCastedTxHash])

return (
<>
Expand All @@ -94,9 +80,9 @@ const BroadcastTransaction = () => {
cancelText={t('offline-sign.actions.cancel')}
onCancel={onBack}
confirmText={
broadCastedTxHash ? t('offline-sign.actions.view-in-explorer') : t('offline-sign.actions.broadcast')
broadcastedTxHash ? t('offline-sign.actions.view-in-explorer') : t('offline-sign.actions.broadcast')
}
isLoading={isBroadCasting}
isLoading={isBroadcasting}
onConfirm={onBroadcast}
>
<div className={styles.main}>
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"view-in-explorer": "View in Explorer"
},
"broadcast-transaction": "Broadcast Transaction",
"import-unsigned-transaction": "Import an unsigned transaction",
"import-unsigned-transaction": "Import a transaction to sign",
"import-unsigned-transaction-detail": "You have imported an unsigned transaction, please confirm and try again."
},
"overview": {
Expand Down

1 comment on commit 17cc1a7

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 7511562470

Please sign in to comment.