Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge testnet into mainnet #1776

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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