-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1402f8b
commit 12dccc8
Showing
14 changed files
with
248 additions
and
38 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; | ||
} |
124 changes: 124 additions & 0 deletions
124
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,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<State.Wallet | null>(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 ( | ||
<> | ||
<Dialog | ||
show={isSigned} | ||
title={t('offline-sign.broadcast-transaction')} | ||
cancelText={t('offline-sign.actions.cancel')} | ||
onCancel={onBack} | ||
confirmText={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.wallet')}</td> | ||
<td> | ||
{wallet?.device ? <HardWalletIcon /> : null} | ||
<span>{wallet?.name ?? ''}</span> | ||
</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-unsigned-transaction')} | ||
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
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.
12dccc8
There was a problem hiding this comment.
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 7301946003