Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/nervosnetwork/neuron int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
Keith-CY committed Jul 23, 2024
2 parents ce359c2 + 2ec3ff8 commit ecce6fb
Show file tree
Hide file tree
Showing 157 changed files with 1,710 additions and 989 deletions.
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"ncp": "2.0.0",
"prettier": "2.8.8",
"ts-jest": "29.2.0",
"ts-node": "^10.9.2",
"typescript": "5.3.3",
"wait-on": "7.0.1"
},
Expand All @@ -66,7 +67,15 @@
"@types/react": "18.2.45",
"react-i18next": ">=11.16.4",
"react-refresh": "0.14.0",
"node-fetch": "2.6.13"
"node-fetch": "2.6.13",
"@ckb-lumos/ckb-indexer": "0.23.0",
"@ckb-lumos/base": "0.23.0",
"@ckb-lumos/bi": "0.23.0",
"@ckb-lumos/codec": "0.23.0",
"@ckb-lumos/common-scripts": "0.23.0",
"@ckb-lumos/config-manager": "0.23.0",
"@ckb-lumos/lumos": "0.23.0",
"@ckb-lumos/rpc": "0.23.0"
},
"volta": {
"node": "20.10.0"
Expand Down
5 changes: 5 additions & 0 deletions packages/neuron-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export default {
options: {},
},
webpackFinal: config => {
config.resolve.fallback = {
fs: false,
crypto: false,
buffer: false,
}
config.resolve.alias = {
...config.resolve.alias,
electron: require.resolve('./electron'),
Expand Down
6 changes: 5 additions & 1 deletion packages/neuron-ui/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const path = require('path')
module.exports = function override(config) {
const webpackConfig = { ...config }
webpackConfig.resolve.alias.electron = path.join(__dirname, 'src/electron-modules')
webpackConfig.resolve.fallback = { fs: false }
webpackConfig.resolve.fallback = {
fs: false,
crypto: false,
buffer: false,
}
return webpackConfig
}
17 changes: 9 additions & 8 deletions packages/neuron-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
"last 2 chrome versions"
],
"dependencies": {
"@ckb-lumos/bi": "0.21.1",
"@ckb-lumos/rpc": "0.21.1",
"@ckb-lumos/base": "0.21.1",
"@ckb-lumos/codec": "0.21.1",
"@ckb-lumos/hd": "0.21.1",
"@ckb-lumos/helpers": "0.21.1",
"@ckb-lumos/config-manager": "0.21.1",
"@ckb-lumos/common-scripts": "0.21.1",
"@ckb-lumos/lumos": "0.23.0",
"@ckb-lumos/bi": "0.23.0",
"@ckb-lumos/rpc": "0.23.0",
"@ckb-lumos/base": "0.23.0",
"@ckb-lumos/codec": "0.23.0",
"@ckb-lumos/hd": "0.23.0",
"@ckb-lumos/helpers": "0.23.0",
"@ckb-lumos/config-manager": "0.23.0",
"@ckb-lumos/common-scripts": "0.23.0",
"canvg": "2.0.0",
"i18next": "23.7.11",
"immer": "9.0.21",
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/CellInfoDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { calculateUsedCapacity, getExplorerUrl, shannonToCKBFormatter, truncateM
import { useTranslation } from 'react-i18next'
import Tabs from 'widgets/Tabs'
import { type TFunction } from 'i18next'
import { Script } from '@ckb-lumos/base'
import { Script } from '@ckb-lumos/lumos'
import Switch from 'widgets/Switch'
import { Copy, ExplorerIcon } from 'widgets/Icons/icon'
import Alert from 'widgets/Alert'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
.actions {
display: flex;
gap: 16px;
& > svg {
& svg {
cursor: pointer;
&[data-disabled='true'] {
cursor: not-allowed;
Expand Down
7 changes: 6 additions & 1 deletion packages/neuron-ui/src/components/CellManagement/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { ErrorCode, LockScriptCategory, RoutePath, TypeScriptCategory, isSuccess
import { SortType } from 'widgets/Table'

const cellTypeOrder: Record<string, number> = {
[TypeScriptCategory.SUDT]: 1,
[TypeScriptCategory.SUDT]: 0,
[TypeScriptCategory.XUDT]: 1,
[TypeScriptCategory.NFT]: 2,
[TypeScriptCategory.Spore]: 3,
[TypeScriptCategory.Unknown]: 4,
Expand Down Expand Up @@ -47,6 +48,9 @@ const getLockStatusAndReason = (item: State.LiveCellWithLocalInfo) => {
case TypeScriptCategory.DAO:
lockedReason = { key: 'cell-manage.locked-reason.NFT-SUDT-DAO', params: { type: 'Nervos DAO' } }
break
case TypeScriptCategory.XUDT:
lockedReason = { key: 'cell-manage.locked-reason.NFT-SUDT-DAO', params: { type: 'XUDT' } }
break
case TypeScriptCategory.Unknown:
lockedReason = { key: 'cell-manage.locked-reason.Unknown' }
break
Expand Down Expand Up @@ -82,6 +86,7 @@ const getCellType = (item: State.LiveCellWithLocalInfo) => {
switch (item.typeScriptType) {
case TypeScriptCategory.NFT:
case TypeScriptCategory.SUDT:
case TypeScriptCategory.XUDT:
case TypeScriptCategory.Spore:
case TypeScriptCategory.Unknown:
return item.typeScriptType
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-ui/src/components/CellManagement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { TFunction } from 'i18next'
import TextField from 'widgets/TextField'
import { useSearchParams } from 'react-router-dom'
import CellInfoDialog from 'components/CellInfoDialog'
import { computeScriptHash } from '@ckb-lumos/base/lib/utils'
import { computeScriptHash } from '@ckb-lumos/lumos/utils'
import Hardware from 'widgets/Icons/Hardware.png'
import Button from 'widgets/Button'
import Alert from 'widgets/Alert'
Expand Down Expand Up @@ -193,7 +193,7 @@ const getColumns = ({
<Tooltip tip={t('cell-manage.unlock')} showTriangle placement="top">
<UnLock
data-disabled={!!lockedReason}
onClick={onAction}
onClick={lockedReason ? undefined : onAction}
data-action={Actions.Unlock}
data-index={index}
/>
Expand All @@ -202,7 +202,7 @@ const getColumns = ({
<Tooltip tip={t('cell-manage.lock')} showTriangle placement="top">
<LockCell
data-disabled={!!lockedReason}
onClick={onAction}
onClick={lockedReason ? undefined : onAction}
data-action={Actions.Lock}
data-index={index}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { calculateUnlockDaoMaximumWithdraw, getTransaction } from 'services/remote'
import { showPageNotice, transactionState, useDispatch, useState as useGlobalState } from 'states'
import { type CKBComponents } from '@ckb-lumos/rpc/lib/types/api'
import { type CKBComponents } from '@ckb-lumos/lumos/rpc'
import PageContainer from 'components/PageContainer'
import LockInfoDialog from 'components/LockInfoDialog'
import ScriptTag from 'components/ScriptTag'
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/LockInfoDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTranslation } from 'react-i18next'
import React, { useRef } from 'react'
import { type CKBComponents } from '@ckb-lumos/rpc/lib/types/api'
import { type CKBComponents } from '@ckb-lumos/lumos/rpc'
import Dialog from 'widgets/Dialog'
import { useCopy, useDialog, scriptToAddress } from 'utils'
import { Copy } from 'widgets/Icons/icon'
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/MultisigAddress/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
OfflineSignJSON,
getMultisigSyncProgress,
} from 'services/remote'
import { computeScriptHash } from '@ckb-lumos/base/lib/utils'
import { computeScriptHash } from '@ckb-lumos/lumos/utils'

export const useSearch = (clearSelected: () => void, onFilterConfig: (searchKey: string) => void) => {
const [keywords, setKeywords] = useState('')
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-ui/src/components/NervosDAO/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { AppActions, StateAction } from 'states/stateProvider/reducer'
import { updateNervosDaoData, clearNervosDaoData } from 'states/stateProvider/actionCreators'

import { NavigateFunction } from 'react-router-dom'
import { type CKBComponents } from '@ckb-lumos/rpc/lib/types/api'
import { type CKBComponents } from '@ckb-lumos/lumos/rpc'
import { calculateAPC, CONSTANTS, isSuccessResponse, RoutePath } from 'utils'

import { rpc, getHeader } from 'services/chain'
import { generateDaoWithdrawTx, generateDaoClaimTx } from 'services/remote'
import { calculateMaximumWithdrawCompatible } from '@ckb-lumos/common-scripts/lib/dao'
import { calculateMaximumWithdrawCompatible } from '@ckb-lumos/lumos/common-scripts/dao'

const { MILLISECONDS_IN_YEAR, MEDIUM_FEE_RATE } = CONSTANTS

Expand Down Expand Up @@ -337,7 +337,7 @@ export const useUpdateDepositEpochList = ({
useEffect(() => {
if (connectionStatus === 'online') {
getBlockHashes(records.map(v => v.depositOutPoint?.txHash).filter(v => !!v) as string[]).then(
(depositBlockHashes: { txHash: string; blockHash: string | null }[]) => {
(depositBlockHashes: { txHash: string; blockHash: string | undefined }[]) => {
const recordKeyIdx: string[] = []
const batchParams: ['getHeader', string][] = []
records.forEach(record => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, useMemo, useState } from 'react'
import Tabs, { VariantProps } from 'widgets/Tabs'
import { type CKBComponents } from '@ckb-lumos/rpc/lib/types/api'
import { type CKBComponents } from '@ckb-lumos/lumos/rpc'
import { clsx, localNumberFormatter, shannonToCKBFormatter, scriptToAddress, isMainnet as isMainnetUtils } from 'utils'
import { useTranslation } from 'react-i18next'
import { onEnter } from 'utils/inputDevice'
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/NervosDAORecord/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react'
import { getHeader } from 'services/chain'
import { calculateAPC, CONSTANTS } from 'utils'
import { type CKBComponents } from '@ckb-lumos/rpc/lib/types/api'
import { type CKBComponents } from '@ckb-lumos/lumos/rpc'

const { MILLISECONDS_IN_YEAR } = CONSTANTS

Expand Down
10 changes: 8 additions & 2 deletions packages/neuron-ui/src/components/SUDTAccountList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
isSuccessResponse,
useIsInsufficientToCreateSUDTAccount,
useOnGenerateNewAccountTransaction,
UDTType,
} from 'utils'

import { getSUDTAccountList, updateSUDTAccount } from 'services/remote'
Expand All @@ -48,7 +49,11 @@ const SUDTAccountList = () => {
const [keyword, setKeyword] = useState('')
const [dialog, setDialog] = useState<{ id: string; action: 'create' | 'update' } | null>(null)
const [isLoaded, setIsLoaded] = useState(false)
const [insufficient, setInsufficient] = useState({ [AccountType.CKB]: false, [AccountType.SUDT]: false })
const [insufficient, setInsufficient] = useState({
[AccountType.CKB]: false,
[AccountType.SUDT]: false,
[AccountType.XUDT]: false,
})

const isMainnet = isMainnetUtil(networks, networkID)
const [receiveData, setReceiveData] = useState<DataProps | null>(null)
Expand Down Expand Up @@ -178,6 +183,7 @@ const SUDTAccountList = () => {
tokenName: accountToUpdate.tokenName || DEFAULT_SUDT_FIELDS.tokenName,
symbol: accountToUpdate.symbol || DEFAULT_SUDT_FIELDS.symbol,
isCKB: accountToUpdate.tokenId === DEFAULT_SUDT_FIELDS.CKBTokenId,
udtType: accountToUpdate.udtType,
onSubmit: (info: Omit<TokenInfo, 'isCKB'>) => {
const params: any = { id: accountToUpdate.accountId }
Object.keys(info).forEach(key => {
Expand Down Expand Up @@ -208,7 +214,7 @@ const SUDTAccountList = () => {
: undefined

const handleCreateAccount = useCallback(
(info: TokenInfo) => {
(info: TokenInfo & { udtType?: UDTType }) => {
createAccount(info, () => {
setNotice(t('s-udt.create-account-success'))
})
Expand Down
36 changes: 25 additions & 11 deletions packages/neuron-ui/src/components/SUDTCreateDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
isSuccessResponse,
useSUDTAccountInfoErrors,
useFetchTokenInfoList,
useOpenSUDTTokenUrl,
useOpenUDTTokenUrl,
UDTType,
} from 'utils'
import { DEFAULT_SUDT_FIELDS } from 'utils/const'
import styles from './sUDTCreateDialog.module.scss'

export enum AccountType {
SUDT = 'sudt',
XUDT = 'xudt',
CKB = 'ckb',
}

Expand All @@ -33,10 +35,10 @@ export interface TokenInfo extends BasicInfo {

export interface SUDTCreateDialogProps extends TokenInfo {
isMainnet: boolean
onSubmit: (info: TokenInfo) => void
onSubmit: (info: TokenInfo & { udtType?: UDTType }) => void
onCancel: () => void
existingAccountNames?: string[]
insufficient?: { [AccountType.CKB]: boolean; [AccountType.SUDT]: boolean }
insufficient?: { [P in AccountType]: boolean }
}

enum DialogSection {
Expand All @@ -49,6 +51,10 @@ const accountTypes: { key: AccountType; label: string }[] = [
key: AccountType.SUDT,
label: 's-udt.create-dialog.sudt-account',
},
{
key: AccountType.XUDT,
label: 's-udt.create-dialog.xudt-account',
},
{
key: AccountType.CKB,
label: 's-udt.create-dialog.ckb-account',
Expand Down Expand Up @@ -121,23 +127,29 @@ const SUDTCreateDialog = ({
onSubmit,
onCancel,
existingAccountNames = [],
insufficient = { [AccountType.CKB]: false, [AccountType.SUDT]: false },
insufficient = { [AccountType.CKB]: false, [AccountType.SUDT]: false, [AccountType.XUDT]: false },
isMainnet,
}: Partial<Omit<SUDTCreateDialogProps, 'onSubmit' | 'onCancel'>> &
Pick<SUDTCreateDialogProps, 'onSubmit' | 'onCancel' | 'insufficient'>) => {
const [t] = useTranslation()
const [info, dispatch] = useReducer(reducer, { accountName, tokenId, tokenName, symbol, decimal })
const [accountType, setAccountType] = useState([AccountType.SUDT, AccountType.CKB].find(at => !insufficient[at]))
const [accountType, setAccountType] = useState(
[AccountType.SUDT, AccountType.CKB, AccountType.XUDT].find(at => !insufficient[at])
)
const isUDT = accountType === AccountType.SUDT || accountType === AccountType.XUDT
// eslint-disable-next-line no-nested-ternary
const udtType = isUDT ? (accountType === AccountType.SUDT ? UDTType.SUDT : UDTType.XUDT) : undefined
const [step, setStep] = useState(DialogSection.Account)
const tokenInfoList = useFetchTokenInfoList()

const tokenInfoFields: (keyof TokenInfo)[] = ['tokenId', 'tokenName', 'symbol', 'decimal']

const tokenErrors = useSUDTAccountInfoErrors({
info,
isCKB: AccountType.CKB === accountType,
isCKB: !isUDT,
existingAccountNames,
t,
udtType,
})
const isAccountNameReady = info.accountName.trim() && !tokenErrors.accountName && accountType

Expand Down Expand Up @@ -190,7 +202,7 @@ const SUDTCreateDialog = ({
}
case DialogSection.Token: {
if (isTokenReady) {
onSubmit({ ...info, accountName: info.accountName.trim(), tokenName: info.tokenName.trim() })
onSubmit({ ...info, udtType, accountName: info.accountName.trim(), tokenName: info.tokenName.trim() })
}
break
}
Expand All @@ -216,7 +228,7 @@ const SUDTCreateDialog = ({
}
}
}
const openSUDTTokenUrl = useOpenSUDTTokenUrl(info.tokenId, isMainnet)
const openSUDTTokenUrl = useOpenUDTTokenUrl(info.tokenId, udtType, isMainnet)
return (
<Dialog
show
Expand Down Expand Up @@ -285,14 +297,16 @@ const SUDTCreateDialog = ({
className={styles.settingField}
placeholder={t(`s-udt.create-dialog.input.${field.label}`)}
hint={
!tokenErrors[field.key] && field.key === 'tokenId' && accountType === AccountType.SUDT
? t(`s-udt.create-dialog.placeholder.${field.label}`)
!tokenErrors[field.key] && field.key === 'tokenId' && isUDT
? t(`s-udt.create-dialog.placeholder.${field.label}`, {
udtType: AccountType.SUDT === accountType ? 'sUDT' : 'xUDT',
})
: undefined
}
/>
))}
</div>
{accountType === AccountType.SUDT && !tokenErrors.tokenId && info.tokenId && (
{isUDT && !tokenErrors.tokenId && info.tokenId && (
<button
type="button"
className={styles.explorerNavButton}
Expand Down
8 changes: 5 additions & 3 deletions packages/neuron-ui/src/components/SUDTMigrateDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'
import { SpecialAssetCell } from 'components/SpecialAssetList/hooks'
import { MIN_CKB_REQUIRED_BY_NORMAL_SUDT, SHANNON_CKB_RATIO } from 'utils/const'
import Dialog from 'widgets/Dialog'
import { PresetScript, UDTType } from 'utils'
import styles from './sUDTMigrateDialog.module.scss'

const items = [
Expand Down Expand Up @@ -38,12 +39,13 @@ const SUDTMigrateDialog = ({
setType('')
onCancel()
}
const udtType = cell.customizedAssetInfo.type === PresetScript.SUDT ? UDTType.SUDT : UDTType.XUDT

return (
<Dialog
className={styles.container}
show
title={t('migrate-sudt.title')}
title={t('migrate-sudt.title', { udtType })}
onCancel={handleCancel}
cancelText={t('migrate-sudt.cancel')}
confirmText={t('migrate-sudt.next')}
Expand All @@ -64,8 +66,8 @@ const SUDTMigrateDialog = ({
role="button"
tabIndex={idx}
>
<div className={styles.title}>{t(v.title)}</div>
<div className={styles.subTitle}>{t(v.subTitle)}</div>
<div className={styles.title}>{t(v.title, { udtType })}</div>
<div className={styles.subTitle}>{t(v.subTitle, { udtType })}</div>
</div>
))}
</>
Expand Down
Loading

0 comments on commit ecce6fb

Please sign in to comment.