Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide loading for the detail button on the history page #2656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/neuron-ui/src/components/TransactionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const TransactionList = ({
dispatch,
}: TransactionListProps) => {
const [txHash, setTxHash] = useState('')
const [isDetailOpening, setIsDetailOpening] = useState(false)
const [t] = useTranslation()

const {
Expand Down Expand Up @@ -115,7 +116,8 @@ const TransactionList = ({
break
}
case 'detail': {
showTransactionDetails(btn.dataset.hash)
setIsDetailOpening(true)
showTransactionDetails(btn.dataset.hash).finally(() => setIsDetailOpening(false))
break
}
default: {
Expand Down Expand Up @@ -279,9 +281,10 @@ const TransactionList = ({
onClick={onActionBtnClick}
data-hash={tx.hash}
data-action="detail"
disabled={isDetailOpening}
>
<Detail />
<span>{t('history.view-detail')}</span>
<span>{isDetailOpening ? t('history.opening') : t('history.view-detail')}</span>
</button>
<button
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,9 @@ $pending-color: #b3b3b3;
svg {
height: 16px;
}

&[disabled] {
background: #9b9bd4;
}
}
}
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
"view-in-explorer-button-title": "View on explorer",
"view-detail": "Detail",
"view-detail-button-title": "View Detail",
"opening": "Opening",
"copy-tx-hash": "Copy Transaction Hash",
"copy-balance": "Copy Balance",
"copy-address": "Copy Address",
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
"view-in-explorer-button-title": "瀏覽器中查看詳情",
"view-detail": "詳情",
"view-detail-button-title": "查看詳情",
"opening": "正在打開",
"copy-tx-hash": "複製交易哈希",
"copy-balance": "複製餘額",
"copy-address": "複製地址",
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
"view-in-explorer-button-title": "浏览器中查看详情",
"view-detail": "详情",
"view-detail-button-title": "查看详情",
"opening": "正在打开",
"copy-tx-hash": "复制交易哈希",
"copy-balance": "复制余额",
"copy-address": "复制地址",
Expand Down
20 changes: 18 additions & 2 deletions packages/neuron-wallet/src/controllers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,24 @@ export default class ApiController {
})

handle('show-transaction-details', async (_, hash: string) => {
showWindow(`#/transaction/${hash}`, t(`messageBox.transaction.title`, { hash }), {
height: 750
const win = showWindow(
`#/transaction/${hash}`,
t(`messageBox.transaction.title`, { hash }),
{
height: 750
},
undefined,
(win) => win.webContents.getURL().endsWith(`#/transaction/${hash}`)
)

if (win.isVisible()) return

return new Promise((resolve, reject) => {
win.once('ready-to-show', resolve)
CommonUtils.sleep(3e3).then(() => {
win.off('ready-to-show', resolve)
reject(new Error('Show window timeout'))
})
})
})

Expand Down
5 changes: 3 additions & 2 deletions packages/neuron-wallet/src/controllers/app/show-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const showWindow = (
url: string,
title: string,
options?: Electron.BrowserWindowConstructorOptions,
channels?: string[]
channels?: string[],
comparator: (win: BrowserWindow) => boolean = (win) => win.getTitle() === title
): BrowserWindow => {
const opened = BrowserWindow.getAllWindows().find(bw => bw.getTitle() === title)
const opened = BrowserWindow.getAllWindows().find(comparator)
if (opened) {
opened.webContents.send('navigation', url.replace(/^#/, ''))
opened.focus()
Expand Down