forked from nervosnetwork/neuron
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Hot/cold combination of a wallet doesn't work smooth (nervosnetw…
…ork#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 <[email protected]>
- Loading branch information
Showing
20 changed files
with
359 additions
and
119 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/neuron-ui/src/components/BroadcastTransaction/broadcastTransaction.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
136 changes: 136 additions & 0 deletions
136
packages/neuron-ui/src/components/BroadcastTransaction/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string | null>('') | ||
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 ( | ||
<> | ||
<Dialog | ||
show={isSigned} | ||
title={t('offline-sign.broadcast-transaction')} | ||
cancelText={t('offline-sign.actions.cancel')} | ||
onCancel={onBack} | ||
confirmText={ | ||
broadcastedTxHash ? t('offline-sign.actions.view-in-explorer') : t('offline-sign.actions.broadcast') | ||
} | ||
isLoading={isBroadcasting} | ||
onConfirm={onBroadcast} | ||
> | ||
<div className={styles.main}> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td className={styles.first}>{t('offline-sign.json-file')}</td> | ||
<td>{filePath}</td> | ||
</tr> | ||
<tr> | ||
<td className={styles.first}>{t('offline-sign.status.label')}</td> | ||
<td>{t('offline-sign.status.signed')}</td> | ||
</tr> | ||
<tr> | ||
<td className={styles.first}>{t('offline-sign.content')}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<textarea disabled value={jsonContent} className={styles.textarea} /> | ||
</div> | ||
</Dialog> | ||
|
||
<Dialog | ||
show={!isSigned} | ||
className={styles.warningDialog} | ||
title={t('offline-sign.import-transaction-to-sign')} | ||
cancelText={t('offline-sign.actions.cancel')} | ||
onCancel={onBack} | ||
onConfirm={onBack} | ||
> | ||
<div className={styles.content}>{t('offline-sign.import-unsigned-transaction-detail')}</div> | ||
</Dialog> | ||
|
||
<AlertDialog | ||
show={!!errMsg} | ||
title={t('message-types.alert')} | ||
message={errMsg} | ||
type="failed" | ||
onCancel={() => setErrMsg('')} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
BroadcastTransaction.displayName = 'BroadcastTransaction' | ||
|
||
export default BroadcastTransaction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.