-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose useChainInfo (re-use of some info for signer) (#2460)
- Loading branch information
Showing
2 changed files
with
40 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
// Copyright 2017-2020 @polkadot/app-settings authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { MetadataDef } from '@polkadot/extension-inject/types'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { getChainTypes } from '@polkadot/apps-config/api'; | ||
import { getSystemIcon } from '@polkadot/apps-config/ui'; | ||
import { useApi } from '@polkadot/react-hooks'; | ||
|
||
interface ChainInfo extends MetadataDef {} | ||
|
||
export default function useChainInfo (): ChainInfo | null { | ||
const { api, isApiReady, systemChain, systemName } = useApi(); | ||
const [state, setState] = useState<MetadataDef | null>(null); | ||
|
||
useEffect((): void => { | ||
isApiReady && setState({ | ||
chain: systemChain, | ||
genesisHash: api.genesisHash.toHex(), | ||
icon: getSystemIcon(systemName), | ||
metaCalls: Buffer.from(api.runtimeMetadata.asCallsOnly.toU8a()).toString('base64'), | ||
specVersion: api.runtimeVersion.specVersion.toNumber(), | ||
ss58Format: api.registry.chainSS58 || 42, | ||
tokenDecimals: api.registry.chainDecimals || 12, | ||
tokenSymbol: api.registry.chainToken || 'Unit', | ||
types: getChainTypes(api.runtimeVersion.specName.toString(), systemChain) | ||
}); | ||
}, [api, isApiReady, systemChain, systemName]); | ||
|
||
return state; | ||
} |