Skip to content

Commit f299ba2

Browse files
committed
fix: comments
1 parent 7207e2c commit f299ba2

File tree

9 files changed

+68
-24
lines changed

9 files changed

+68
-24
lines changed

packages/neuron-ui/src/components/CellManagement/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
getLockTimestamp,
2626
isMainnet as isMainnetUtil,
2727
TypeScriptCategory,
28-
UDTType,
2928
} from 'utils'
3029
import { HIDE_BALANCE } from 'utils/const'
3130
import Tooltip from 'widgets/Tooltip'
@@ -395,7 +394,7 @@ const CellManagement = () => {
395394
data={{
396395
tokenID: operateCells[0].type.args,
397396
address: operateCells[0].lock.args,
398-
udtType: operateCells[0].typeScriptType === TypeScriptCategory.SUDT ? UDTType.SUDT : UDTType.XUDT,
397+
outpoint: operateCells[0].outPoint,
399398
}}
400399
onClose={onActionCancel}
401400
onConfirm={fetchLiveCells}

packages/neuron-ui/src/components/RecycleUDTCellDialog/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useCallback, useEffect, useState, useMemo } from 'react'
22
import { useTranslation } from 'react-i18next'
33
import { useState as useGlobalState } from 'states'
4+
import { type CKBComponents } from '@ckb-lumos/lumos/rpc'
45
import { sudtValueToAmount, shannonToCKBFormatter } from 'utils/formatters'
56
import Dialog from 'widgets/Dialog'
67
import AlertDialog from 'widgets/AlertDialog'
@@ -20,7 +21,6 @@ import {
2021
OfflineSignType,
2122
} from 'services/remote'
2223
import {
23-
UDTType,
2424
addressToScript,
2525
isSuccessResponse,
2626
isMainnet as isMainnetUtil,
@@ -33,7 +33,7 @@ import styles from './recycleUDTCellDialog.module.scss'
3333
export interface DataProps {
3434
address: string
3535
tokenID: string
36-
udtType: UDTType
36+
outpoint?: CKBComponents.OutPoint
3737
}
3838

3939
type DialogType = 'ready' | 'inProgress' | 'verify' | 'success'
@@ -73,7 +73,7 @@ const RecycleUDTCellDialog = ({
7373
t,
7474
})
7575

76-
const { address: holder, tokenID, udtType } = data
76+
const { address: holder, tokenID, outpoint } = data
7777

7878
const isMainnet = isMainnetUtil(networks, networkID)
7979

@@ -95,7 +95,7 @@ const RecycleUDTCellDialog = ({
9595
getUDTTokenInfoAndBalance({
9696
tokenID,
9797
holder,
98-
udtType,
98+
outpoint,
9999
}).then(res => {
100100
if (isSuccessResponse(res)) {
101101
setInfo(res.result)
@@ -152,7 +152,7 @@ const RecycleUDTCellDialog = ({
152152
tokenID,
153153
holder,
154154
receiver: addressToScript(receiver, { isMainnet }).args,
155-
udtType,
155+
outpoint,
156156
})
157157
if (!isSuccessResponse(txRes)) {
158158
errFunc(errorFormatter(txRes.message, t))

packages/neuron-ui/src/components/SUDTAccountList/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ const SUDTAccountList = () => {
139139
setRecycleData({
140140
address: addressToScript(account.address, { isMainnet }).args,
141141
tokenID: account.tokenId,
142-
udtType: account.udtType!,
143142
})
144143
break
145144
}

packages/neuron-ui/src/types/Controller/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ declare namespace Controller {
359359
interface Params {
360360
tokenID: string
361361
holder: string
362-
udtType: UDTType
362+
outpoint?: CKBComponents.OutPoint
363363
}
364364
interface Response {
365365
tokenID: string
@@ -378,7 +378,7 @@ declare namespace Controller {
378378
holder: string
379379
tokenID: string
380380
receiver: string
381-
udtType: UDTType
381+
outpoint?: CKBComponents.OutPoint
382382
}
383383

384384
type Response = Tx

packages/neuron-wallet/src/controllers/api.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,14 +919,23 @@ export default class ApiController {
919919

920920
handle(
921921
'get-sudt-token-info-and-balance',
922-
async (_, params: { tokenID: string; holder: string; udtType: UDTType }) => {
922+
async (_, params: { tokenID: string; holder: string; outpoint?: CKBComponents.OutPoint }) => {
923923
return this.#sudtController.getUDTTokenInfoAndBalance(params)
924924
}
925925
)
926926

927927
handle(
928928
'generate-recycle-udt-cell-tx',
929-
async (_, params: { walletId: string; holder: string; tokenID: string; receiver: string; udtType: UDTType }) => {
929+
async (
930+
_,
931+
params: {
932+
walletId: string
933+
holder: string
934+
tokenID: string
935+
receiver: string
936+
outpoint?: CKBComponents.OutPoint
937+
}
938+
) => {
930939
return this.#assetAccountController.generateRecycleUDTCellTx(params)
931940
}
932941
)

packages/neuron-wallet/src/controllers/asset-account.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,18 @@ export default class AssetAccountController {
115115
holder: string
116116
tokenID: string
117117
receiver: string
118-
udtType: UDTType
118+
outpoint?: CKBComponents.OutPoint
119119
}) {
120-
const tx = await AssetAccountService.generateRecycleUDTCellTx(params)
120+
const tokens = await SudtTokenInfoService.findSudtTokenInfoByArgs([params.tokenID])
121+
if (!tokens || !tokens.length) {
122+
throw new ServiceHasNoResponse('UDT Cell')
123+
}
124+
125+
const { udtType } = tokens[0]
126+
const tx = await AssetAccountService.generateRecycleUDTCellTx({
127+
...params,
128+
udtType,
129+
})
121130
return {
122131
status: ResponseCode.Success,
123132
result: tx,

packages/neuron-wallet/src/controllers/sudt.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ export default class SUDTController {
3232
const { decimal, name, symbol } = parseSUDTTokenInfo(liveCell.data)
3333
return {
3434
status: ResponseCode.Success,
35-
result: { tokenID: params.tokenID, symbol: symbol, tokenName: name, decimal: decimal },
35+
result: { tokenID: params.tokenID, symbol: symbol, tokenName: name, decimal: decimal, udtType: UDTType.SUDT },
3636
}
3737
}
3838

39+
// outpoint
3940
public async getUDTTokenInfoAndBalance(params: {
4041
tokenID: string
4142
holder: string
42-
udtType: UDTType
43+
outpoint?: CKBComponents.OutPoint
4344
}): Promise<Controller.Response<SudtTokenInfo & { balance: string; capacity: string }>> {
44-
const { tokenID, holder, udtType } = params
45+
const { tokenID, holder, outpoint } = params
4546
const info = await this.getSUDTTokenInfo({ tokenID })
4647
if (!info.result) {
4748
return {
4849
status: ResponseCode.Fail,
4950
}
5051
}
51-
const balance = await AssetAccountService.calculateUDTAccountBalance(holder, tokenID, udtType)
52-
const cells = await AssetAccountService.getACPCells(holder, tokenID, udtType)
52+
53+
const balance = await AssetAccountService.calculateUDTAccountBalance(holder, tokenID, info.result.udtType, outpoint)
54+
const cells = await AssetAccountService.getACPCells(holder, tokenID, info.result.udtType, outpoint)
5355

5456
let capacity = cells.reduce((a, b) => {
5557
return a + BigInt(b.capacity as string)

packages/neuron-wallet/src/models/chain/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TypeCheckerUtils from '../../utils/type-checker'
99
import OutPoint from './out-point'
1010
import { Signatures } from '../../models/offline-sign'
1111
import { ckbHash } from '@ckb-lumos/lumos/utils'
12+
import { UDTType } from '../../utils/const'
1213

1314
export enum TransactionStatus {
1415
Pending = 'pending',
@@ -22,6 +23,7 @@ export interface SudtTokenInfo {
2223
tokenID: string
2324
tokenName: string
2425
decimal: string
26+
udtType?: UDTType | undefined
2527
}
2628

2729
export interface SudtInfo {

packages/neuron-wallet/src/services/asset-account-service.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ import { MIN_CELL_CAPACITY, UDTType } from '../utils/const'
1919
import SudtTokenInfoService from './sudt-token-info'
2020

2121
export default class AssetAccountService {
22-
public static async getACPCells(publicKeyHash: string, tokenId: string = 'CKBytes', udtType?: UDTType) {
22+
public static async getACPCells(
23+
publicKeyHash: string,
24+
tokenId: string = 'CKBytes',
25+
udtType?: UDTType,
26+
outpoint?: OutPoint
27+
) {
2328
const assetAccountInfo = new AssetAccountInfo()
2429
const anyoneCanPayLockHash = assetAccountInfo.generateAnyoneCanPayScript(publicKeyHash).computeHash()
30+
2531
const outputs = await getConnection()
2632
.getRepository(OutputEntity)
2733
.findBy({
@@ -31,6 +37,12 @@ export default class AssetAccountService {
3137
tokenId !== 'CKBytes'
3238
? assetAccountInfo.generateUdtScript(tokenId, udtType ?? UDTType.SUDT)!.computeHash()
3339
: IsNull(),
40+
...(outpoint
41+
? {
42+
outPointTxHash: outpoint.txHash,
43+
outPointIndex: outpoint.index,
44+
}
45+
: {}),
3446
})
3547

3648
return outputs
@@ -52,7 +64,12 @@ export default class AssetAccountService {
5264
return availableBalance >= 0 ? availableBalance.toString() : BigInt(0)
5365
}
5466

55-
public static async calculateUDTAccountBalance(publicKeyHash: string, tokenId: string, udtType?: UDTType) {
67+
public static async calculateUDTAccountBalance(
68+
publicKeyHash: string,
69+
tokenId: string,
70+
udtType?: UDTType,
71+
outpoint?: OutPoint
72+
) {
5673
const assetAccountInfo = new AssetAccountInfo()
5774
const anyoneCanPayLockHash = assetAccountInfo.generateAnyoneCanPayScript(publicKeyHash).computeHash()
5875
const typeHash =
@@ -66,6 +83,12 @@ export default class AssetAccountService {
6683
status: In([OutputStatus.Live, OutputStatus.Sent]),
6784
lockHash: anyoneCanPayLockHash,
6885
typeHash,
86+
...(outpoint
87+
? {
88+
outPointTxHash: outpoint.txHash,
89+
outPointIndex: outpoint.index,
90+
}
91+
: {}),
6992
})
7093
.getMany()
7194

@@ -117,10 +140,11 @@ export default class AssetAccountService {
117140
holder: string
118141
tokenID: string
119142
receiver: string
120-
udtType: UDTType
143+
udtType?: UDTType
144+
outpoint?: CKBComponents.OutPoint
121145
}) {
122-
const { walletId, holder, tokenID, udtType, receiver } = params
123-
const cells = await AssetAccountService.getACPCells(holder, tokenID, udtType)
146+
const { walletId, holder, tokenID, receiver, udtType, outpoint } = params
147+
const cells = await AssetAccountService.getACPCells(holder, tokenID, udtType, outpoint)
124148

125149
if (!cells.length) {
126150
throw new Error(`No cells found!`)

0 commit comments

Comments
 (0)