From 09fa9c558a3dfbc830a521bd349efc349eee436a Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Sun, 18 Feb 2024 21:36:52 +0800 Subject: [PATCH] feat: Non-Native token transfer in history add more details about CKB --- .../CellInfoDialog/cellInfoDialog.module.scss | 272 +++++++++++++++++ .../src/components/CellInfoDialog/index.tsx | 158 ++++++++++ .../src/components/CellManagement/hooks.ts | 57 +--- .../src/components/CellManagement/index.tsx | 75 +---- .../formattedTokenAmount.module.scss | 9 +- .../components/FormattedTokenAmount/index.tsx | 52 +++- .../components/History/history.module.scss | 10 +- .../neuron-ui/src/components/History/hooks.ts | 4 +- .../src/components/History/index.tsx | 33 +- .../historyDetailPage.module.scss | 75 +++-- .../src/components/HistoryDetailPage/hooks.ts | 32 ++ .../components/HistoryDetailPage/index.tsx | 286 +++++++++++++----- .../transactionStatusWrap.module.scss | 1 + packages/neuron-ui/src/locales/en.json | 21 +- packages/neuron-ui/src/locales/es.json | 21 +- packages/neuron-ui/src/locales/fr.json | 21 +- packages/neuron-ui/src/locales/zh-tw.json | 19 +- packages/neuron-ui/src/locales/zh.json | 21 +- packages/neuron-ui/src/services/chain.ts | 2 - .../src/services/remote/remoteApiWrapper.ts | 1 + .../src/services/remote/transactions.ts | 2 + .../neuron-ui/src/services/remote/wallets.ts | 1 + .../neuron-ui/src/tests/parsers/index.test.ts | 18 ++ packages/neuron-ui/src/types/App/index.d.ts | 1 + packages/neuron-ui/src/utils/parsers.ts | 2 + .../neuron-ui/src/widgets/Switch/index.tsx | 28 ++ .../src/widgets/Switch/switch.module.scss | 34 +++ .../neuron-ui/src/widgets/Table/index.tsx | 34 ++- packages/neuron-wallet/src/controllers/api.ts | 12 +- .../src/controllers/cell-management.ts | 8 +- packages/neuron-wallet/src/controllers/dao.ts | 30 +- .../src/controllers/transactions.ts | 14 +- .../models/chain/transaction-with-status.ts | 10 +- .../src/models/chain/transaction.ts | 1 + packages/neuron-wallet/src/services/cells.ts | 39 ++- .../src/services/tx/transaction-service.ts | 52 +++- .../neuron-wallet/src/types/controller.d.ts | 2 + .../tests/services/cells.test.ts | 145 +++++++-- 38 files changed, 1265 insertions(+), 338 deletions(-) create mode 100644 packages/neuron-ui/src/components/CellInfoDialog/cellInfoDialog.module.scss create mode 100644 packages/neuron-ui/src/components/CellInfoDialog/index.tsx create mode 100644 packages/neuron-ui/src/components/HistoryDetailPage/hooks.ts create mode 100644 packages/neuron-ui/src/widgets/Switch/index.tsx create mode 100644 packages/neuron-ui/src/widgets/Switch/switch.module.scss diff --git a/packages/neuron-ui/src/components/CellInfoDialog/cellInfoDialog.module.scss b/packages/neuron-ui/src/components/CellInfoDialog/cellInfoDialog.module.scss new file mode 100644 index 0000000000..148d7b4f99 --- /dev/null +++ b/packages/neuron-ui/src/components/CellInfoDialog/cellInfoDialog.module.scss @@ -0,0 +1,272 @@ +.cellInfoDialog { + min-width: 650px; +} + +.title { + display: flex; + align-items: center; + gap: 4px; + font-size: 14px; + + .outPoint { + display: flex; + padding: 5px 8px; + justify-content: center; + align-items: center; + gap: 8px; + border-radius: 16px; + border: 1px solid var(--divide-line-color); + background: var(--input-disabled-color); + font-weight: 400; + color: var(--main-text-color); + + .hash { + font-family: 'JetBrains Mono'; + } + + & > svg { + path { + fill: var(--secondary-text-color); + } + } + } +} + +.head { + display: flex; + gap: 4px; + align-items: center; + margin-bottom: 12px; + + & > svg { + transform: rotate(-90deg); + path { + fill: var(--border-color); + } + } + + [data-type='hash'] { + color: var(--third-text-color); + font-family: 'JetBrains Mono'; + } + + .liveIcon { + width: 8px; + height: 8px; + border-radius: 8px; + background-color: var(--primary-color); + } +} + +.tabsClassName { + .tabsWrapClassName { + position: relative; + display: flex; + margin-bottom: 16px; + border-bottom: 1px solid var(--divide-line-color); + + .tabsColumnClassName { + position: relative; + padding: 10px 20px; + font-size: 14px; + font-weight: 500; + color: var(--tabs-default-color); + background-color: transparent; + border: none; + margin-right: 10px; + + &:hover { + font-weight: bold; + color: var(--tabs-active); + } + + &.active { + color: var(--tabs-active); + border-bottom: 2px solid var(--tabs-active); + } + } + } +} + +.scriptTable { + border-collapse: separate; + border-spacing: 0px; + width: 100%; + color: var(--main-text-color); + + td { + padding: 8px; + border: 1px solid var(--divide-line-color); + text-align: center; + } + + thead { + td { + border-bottom: 0; + &:nth-child(1) { + border-top-left-radius: 8px; + border-right: 0; + } + &:nth-last-child(1) { + border-top-right-radius: 8px; + } + } + } + + tbody { + tr { + &:not(:nth-last-child(1)) { + td { + border-bottom: 0; + } + } + &:nth-last-child(1) { + td { + &:nth-child(1) { + border-bottom-left-radius: 8px; + } + &:nth-last-child(1) { + border-bottom-right-radius: 8px; + } + } + } + } + td { + &:not(:nth-last-child(1)) { + border-right: 0; + } + } + } +} + +.content { + position: relative; + + .switchFormat { + position: absolute; + right: 0; + top: 10px; + color: var(--main-text-color); + display: flex; + align-items: center; + } +} + +.preStyle { + border: 1px solid var(--lock-info-title-border); + border-radius: 12px; + padding: 16px; + overflow-y: auto; + margin: 0; + color: var(--main-text-color); + font-family: 'JetBrains Mono'; + display: block; + width: calc(100% - 32px); + + &::selection { + background-color: var(--primary-color); + color: var(--primary-text-color); + } +} + +.capacityUsed { + padding: 0 16px 16px; + .slider { + width: 616px; + height: 16px; + border-radius: 8px; + border: 1px solid var(--divide-line-color); + background-color: var(--secondary-background-color); + position: relative; + + & > div { + position: absolute; + left: -1px; + top: -1px; + height: 100%; + border-radius: 8px; + border: 1px solid var(--primary-color); + background-color: var(--primary-color); + } + } + .capacityDetail { + color: var(--main-text-color); + font-style: normal; + font-weight: 400; + line-height: normal; + margin-top: 12px; + } +} + +.dataAction { + position: fixed; + width: 496px; + border-radius: 8px; + background: var(--secondary-background-color); + box-shadow: 0px 2px 10px 0px var(--main-shadow-color); + + .dataView { + color: var(--main-text-color); + font-weight: 500; + padding: 12px; + border-bottom: 1px solid var(--divide-line-color); + display: flex; + align-items: center; + + .formatTypeBtn { + border: none; + cursor: pointer; + background-color: transparent; + + &:hover, + &[data-activity='true'] { + color: var(--primary-color); + } + + &[data-open='true'] { + & > svg { + transform: rotate(180deg); + } + } + + & > svg { + margin-left: 4px; + path { + fill: var(--primary-color); + } + } + } + + .dropdown { + position: relative; + margin-left: 12px; + .formatTypes { + position: absolute; + top: 100%; + left: 0; + background-color: var(--secondary-background-color); + border-radius: 4px; + box-shadow: 0px 2px 10px 0px var(--main-shadow-color); + display: flex; + flex-direction: column; + padding: 12px 8px; + margin: 0; + gap: 16px; + white-space: nowrap; + z-index: 10; + } + } + } + + .dataFormat { + padding: 12px; + word-wrap: break-word; + } +} + +.copyAddress { + margin-left: 4px; + position: relative; + top: 4px; + cursor: pointer; +} diff --git a/packages/neuron-ui/src/components/CellInfoDialog/index.tsx b/packages/neuron-ui/src/components/CellInfoDialog/index.tsx new file mode 100644 index 0000000000..20bc08a669 --- /dev/null +++ b/packages/neuron-ui/src/components/CellInfoDialog/index.tsx @@ -0,0 +1,158 @@ +import React, { useMemo, useState } from 'react' +import Dialog from 'widgets/Dialog' +import { calculateUsedCapacity, shannonToCKBFormatter } from 'utils' +import { useTranslation } from 'react-i18next' +import Tabs from 'widgets/Tabs' +import { type TFunction } from 'i18next' +import { Script } from '@ckb-lumos/base' +import Switch from 'widgets/Switch' +import styles from './cellInfoDialog.module.scss' + +type ScriptRenderType = 'table' | 'raw' + +const ScriptRender = ({ script, renderType }: { script?: Script; renderType: ScriptRenderType }) => { + if (renderType === 'raw') { + const scriptRaw = script + ? `{ + "code_hash": "${script.codeHash}" + "hash_type": "${script.hashType}" + "args": "${script.args}" +}` + : `{ + "null" +}` + return
{scriptRaw}+ } + return ( +
KEY | +VALUE | +
code_hash | +{script?.codeHash ?? '--'} | +
hash_type | +{script?.hashType ?? '--'} | +
args | +{script?.args ?? '--'} | +
{output?.data}+ }, + }, + { + id: tabIds.capacityUsage, + label: t('cell-manage.cell-detail-dialog.capacity-used'), + render() { + return ( +