Skip to content

Commit

Permalink
refactor: replace toUint64Le, parseEpoch from ckbCore.utils with lumos (
Browse files Browse the repository at this point in the history
#3138)

refactor: replace toUint64Le, parseEpoch from ckbCore.utils with lumos methods
  • Loading branch information
twhy authored May 6, 2024
1 parent 128e425 commit 4aea8d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/SpecialAssetList/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect } from 'react'
import { ckbCore } from 'services/chain'
import { number, bytes } from '@ckb-lumos/codec'
import { getSUDTAccountList } from 'services/remote'
import { NeuronWalletActions, useDispatch } from 'states'
import {
Expand Down Expand Up @@ -144,7 +144,7 @@ export const useSpecialAssetColumnInfo = ({

switch (assetInfo.lock) {
case PresetScript.Locktime: {
const targetEpochInfo = epochParser(ckbCore.utils.toUint64Le(`0x${lock.args.slice(-16)}`))
const targetEpochInfo = epochParser(bytes.hexify(number.Uint64LE.pack(`0x${lock.args.slice(-16)}`)))
const currentEpochInfo = epochParser(epoch)
const targetEpochFraction =
Number(targetEpochInfo.length) > 0 ? Number(targetEpochInfo.index) / Number(targetEpochInfo.length) : 1
Expand Down
3 changes: 0 additions & 3 deletions packages/neuron-ui/src/services/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ export const ckbCore = new CKBCore('')
export const { getHeader, getBlockchainInfo, getTipHeader, getHeaderByNumber, getFeeRateStats, getTransaction } =
ckbCore.rpc

export const { toUint64Le, parseEpoch } = ckbCore.utils

export default {
ckbCore,
getHeader,
getTipHeader,
getTransaction,
toUint64Le,
getFeeRateStats,
}
9 changes: 5 additions & 4 deletions packages/neuron-ui/src/utils/parsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { toUint64Le, parseEpoch } from 'services/chain'
import { since } from '@ckb-lumos/base'
import { number, bytes } from '@ckb-lumos/codec'
import { MILLISECONDS, PAGE_SIZE } from './const'

export const listParams = (search: string) => {
Expand All @@ -17,7 +18,7 @@ export const listParams = (search: string) => {

export const epochParser = (epoch: string) => {
const e = epoch.startsWith('0x') ? epoch : `0x${BigInt(epoch).toString(16)}`
const parsed = parseEpoch(e)
const parsed = since.parseEpoch(e)

const res = {
length: BigInt(parsed.length),
Expand All @@ -44,7 +45,7 @@ export const toUint128Le = (hexString: string) => {
s = s.slice(0, 34)
}

return `${toUint64Le(`0x${s.substr(18, 16)}`)}${toUint64Le(s.substr(0, 18)).slice(2)}`
return bytes.hexify(number.Uint128LE.pack(s))
}

export const getLockTimestamp = ({
Expand All @@ -56,7 +57,7 @@ export const getLockTimestamp = ({
epoch: string
bestKnownBlockTimestamp: number
}) => {
const targetEpochInfo = epochParser(toUint64Le(`0x${lockArgs.slice(-16)}`))
const targetEpochInfo = epochParser(bytes.hexify(number.Uint64LE.pack(`0x${lockArgs.slice(-16)}`)))
const currentEpochInfo = epochParser(epoch)
const targetEpochFraction =
Number(targetEpochInfo.length) > 0 ? Number(targetEpochInfo.index) / Number(targetEpochInfo.length) : 1
Expand Down

2 comments on commit 4aea8d0

@github-actions
Copy link
Contributor

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 8963128699

@github-actions
Copy link
Contributor

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 8963128841

Please sign in to comment.