Skip to content

Commit

Permalink
Merge pull request #1775 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Merge develop into testnet
  • Loading branch information
Keith-CY authored Sep 4, 2024
2 parents 3341c5a + 08a0aa9 commit 55b02bd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/pages/BlockDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default () => {
['node', 'block', 'info', blockHeightOrHash],
() =>
isBlockNumber(blockHeightOrHash)
? nodeService.rpc.getBlockByNumber(`0x${parseInt(blockHeightOrHash, 10).toString(16)}`)
? nodeService.rpc.getBlockByNumber(`0x${Number(blockHeightOrHash).toString(16)}`)
: nodeService.rpc.getBlock(blockHeightOrHash),
{
enabled: nodeModeActivated,
Expand Down
10 changes: 8 additions & 2 deletions src/services/ExplorerService/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BehaviorSubject, Subscription, map, switchMap, timer } from 'rxjs'
import { BehaviorSubject, Subscription, map, switchMap, timer, catchError, of } from 'rxjs'
import {
BLOCKCHAIN_ALERT_POLLING_TIME,
BLOCK_POLLING_TIME,
Expand Down Expand Up @@ -53,14 +53,20 @@ class ExplorerService {
this.callbacksAtStop = new Subscription()

this.callbacksAtStop.add(
timer(0, BLOCK_POLLING_TIME).pipe(switchMap(this.api.fetchStatistics)).subscribe(this.latestStatistics$),
timer(0, BLOCK_POLLING_TIME)
.pipe(
switchMap(this.api.fetchStatistics),
catchError(() => of(initStatistics)),
)
.subscribe(this.latestStatistics$),
)

this.callbacksAtStop.add(
timer(0, BLOCK_POLLING_TIME)
.pipe(
switchMap(this.api.fetchTipBlockNumber),
map(tipBlockNumber => Number(tipBlockNumber)),
catchError(() => of(0)),
)
.subscribe(this.latestBlockNumber$),
)
Expand Down
8 changes: 8 additions & 0 deletions src/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export const encodeNewAddress = (script: Script) => {
}

export const encodeDeprecatedAddress = (script: Script) => {
if (script.hashType === 'data1') {
return encodeNewAddress(script)
}

if (script.hashType === 'data2') {
return encodeNewAddress(script)
}

return generateAddress(script, { config: lumosConfig })
}

Expand Down
10 changes: 9 additions & 1 deletion src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ export function isNumeric(str: string) {
return !Number.isNaN(str) && !Number.isNaN(parseFloat(str))
}

const BLOCK_HASH_LENGTH = 64

export function isBlockNumber(str: string) {
return !Number.isNaN(str) && !Number.isNaN(parseFloat(str)) && parseFloat(str) !== 0
if (str.length >= BLOCK_HASH_LENGTH) return false

if (!Number.isNaN(str) && !Number.isNaN(parseFloat(str)) && parseFloat(str) !== 0) {
return true
}

return !Number.isNaN(str) && !Number.isNaN(parseInt(str, 16)) && parseInt(str, 16) !== 0
}

export const localeNumberString = (value: BigNumber | string | number): string => {
Expand Down

0 comments on commit 55b02bd

Please sign in to comment.