-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from tokenguardio/dapp-analytics-dev
Release 3.1.2
- Loading branch information
Showing
5 changed files
with
71 additions
and
11 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
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,21 @@ | ||
import _ from 'lodash'; | ||
|
||
export function formatNumber(num: number): string { | ||
if (num >= 1e9) { | ||
return (num / 1e9).toFixed(1) + 'B'; | ||
} else if (num >= 1e6) { | ||
return (num / 1e6).toFixed(1) + 'M'; | ||
} else if (num >= 1e3) { | ||
return (num / 1e3).toFixed(1) + 'k'; | ||
} | ||
return num.toString(); | ||
} | ||
|
||
export function convertAndFormatNumbers(num1: number, num2: number): string { | ||
const formattedNum1 = formatNumber(num1); | ||
const formattedNum2 = formatNumber(num2); | ||
const percentage = ((num1 / num2) * 100).toFixed(2); | ||
|
||
return `${formattedNum1} / ${formattedNum2} (${percentage}%)`; | ||
} | ||
|
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,20 @@ | ||
import { ApiPromise, WsProvider } from '@polkadot/api'; | ||
|
||
const rpcEndpoints: { [key: string]: string } = { | ||
polkadot: 'wss://rpc.polkadot.io', | ||
kusama: 'wss://kusama-rpc.polkadot.io', | ||
'aleph-zero': 'wss://rpc.azero.dev', | ||
}; | ||
|
||
export async function getCurrentBlock(chain: string) { | ||
const endpoint = rpcEndpoints[chain]; | ||
if (!endpoint) { | ||
throw new Error(`RPC endpoint for chain ${chain} not found`); | ||
} | ||
|
||
const wsProvider = new WsProvider(endpoint); | ||
const api = await ApiPromise.create({ provider: wsProvider }); | ||
|
||
const currentBlock = await api.rpc.chain.getHeader(); | ||
return currentBlock.number.toNumber(); | ||
} |
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