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

Created SDK package and move community networks file to it #582

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"status-build": "cross-env SKIP_PREFLIGHT_CHECK=true yarn workspace @taraxa_project/taraxa-node-status build",
"status-start": "cross-env SKIP_PREFLIGHT_CHECK=true yarn workspace @taraxa_project/taraxa-node-status dev",
"ui-build": "cross-env SKIP_PREFLIGHT_CHECK=true yarn workspace @taraxa_project/taraxa-ui build",
"sdk-build": "cross-env SKIP_PREFLIGHT_CHECK=true yarn workspace @taraxa_project/taraxa-sdk build",
"shared-build": "cross-env SKIP_PREFLIGHT_CHECK=true yarn workspace @taraxa_project/explorer-shared build",
"shared-typeorm:run": "cross-env SKIP_PREFLIGHT_CHECK=true yarn workspace @taraxa_project/explorer-shared typeorm:run",
"shared-typeorm:prod:run": "cross-env SKIP_PREFLIGHT_CHECK=true yarn workspace @taraxa_project/explorer-shared typeorm:prod:run",
Expand Down
4 changes: 4 additions & 0 deletions packages/taraxa-sdk/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
lib
.dockerignore
.git
36 changes: 36 additions & 0 deletions packages/taraxa-sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
overrides: [
{
// JavaScript and JSX
files: ['*.{ts,tsx}'],
Malak67 marked this conversation as resolved.
Show resolved Hide resolved
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
rules: {
'ro-restricted-exports': 'off',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/*.stories.*', '**/.storybook/**/*.*'],
Malak67 marked this conversation as resolved.
Show resolved Hide resolved
peerDependencies: true,
},
],
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
printWidth: 80,
trailingComma: 'es5',
semi: true,
doubleQuote: false,
jsxSingleQuote: true,
singleQuote: true,
useTabs: false,
tabWidth: 2,
},
],
},
},
],
};
3 changes: 3 additions & 0 deletions packages/taraxa-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
lib/
yarn-error.log
11 changes: 11 additions & 0 deletions packages/taraxa-sdk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"trailingComma": "es5",
"endOfLine": "auto",
"printWidth": 80,
"semi": true,
"doubleQuote": false,
"jsxSingleQuote": true,
"useTabs": false,
"tabWidth": 2
}
37 changes: 37 additions & 0 deletions packages/taraxa-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@taraxa_project/taraxa-sdk",
"version": "0.0.1",
"description": "Taraxa SDK Library",
"main": "lib/index.js",
"module": "lib/index.esm.js",
"types": "lib/src/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c",
"prepublishOnly": "yarn build"
},
"license": "MIT",
"keywords": [
"react",
"typescript"
],
"author": "Taraxa",
"peerDependencies": {
"react": "^18.1.0",
Malak67 marked this conversation as resolved.
Show resolved Hide resolved
"react-dom": "^18.1.0"
},
"dependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-image": "^2.1.1",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-url": "^6.1.0",
"@types/react": "18.0.8",
"rollup": "^2.34.2",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.29.0",
"typescript": "^4.1.2"
},
"devDependencies": {
"tslib": "^2.3.1"
}
}
36 changes: 36 additions & 0 deletions packages/taraxa-sdk/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import url from '@rollup/plugin-url';
import image from '@rollup/plugin-image';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('./package.json');

export default {
input: 'src/index.ts',
output: [
{
file: packageJson.main,
format: 'cjs',
sourcemap: true,
},
{
file: packageJson.module,
format: 'esm',
sourcemap: true,
},
],
plugins: [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({ useTsconfigDeclarationDir: true }),
url({
include: ['**/*.woff', '**/*.woff2', '**/*.eot', '**/*.ttf'],
name: '[name].[ext]',
}),
image(),
Malak67 marked this conversation as resolved.
Show resolved Hide resolved
],
};
10 changes: 10 additions & 0 deletions packages/taraxa-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {
NetworkName,
networks,
getNetwork,
getNetworkSubdomain,
} from './networks';
import type { Network, Networks } from './networks';

export { networks, NetworkName, getNetwork, getNetworkSubdomain };
export type { Network, Networks };
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
interface Network {
export enum NetworkName {
MAINNET = 'Mainnet',
TESTNET = 'Testnet',
DEVNET = 'Devnet',
}

export interface Network {
chainName: string;
rpcUrl: string;
iconUrl: string;
Expand All @@ -9,10 +15,14 @@ interface Network {
decimals: number;
};
indexerUrl: string;
graphqlUrl: string;
faucetUrl: string;
}
interface Networks {

export interface Networks {
[key: number]: Network;
}

export const networks: Networks = {
841: {
chainName: 'Taraxa Mainnet',
Expand All @@ -25,6 +35,8 @@ export const networks: Networks = {
decimals: 18,
},
indexerUrl: 'https://indexer.mainnet.explorer.taraxa.io',
graphqlUrl: 'https://graphql.mainnet.taraxa.io/',
faucetUrl: '',
},
842: {
chainName: 'Taraxa Testnet',
Expand All @@ -37,6 +49,8 @@ export const networks: Networks = {
decimals: 18,
},
indexerUrl: 'https://indexer.testnet.explorer.taraxa.io',
graphqlUrl: 'https://graphql.testnet.taraxa.io/',
faucetUrl: 'https://faucet-testnet.explorer.taraxa.io/',
},
843: {
chainName: 'Taraxa Devnet',
Expand All @@ -49,17 +63,31 @@ export const networks: Networks = {
decimals: 18,
},
indexerUrl: 'https://indexer.devnet.explorer.taraxa.io',
graphqlUrl: 'https://graphql.devnet.taraxa.io/',
faucetUrl: 'https://faucet-devnet.explorer.taraxa.io/',
},
200: {
chainName: 'Taraxa PRnet',
rpcUrl: 'https://rpc-pr-2460.prnet.taraxa.io/',
iconUrl: 'https://community.taraxa.io/logo192.png',
blockExplorerUrl: 'https://explorer-pr-2460.prnet.taraxa.io/',
nativeCurrency: {
name: 'TARA',
symbol: 'TARA',
decimals: 18,
},
indexerUrl: 'https://indexer-pr-2460.prnet.taraxa.io',
},
};

export const networkNameToId: { [key in NetworkName]: number } = {
[NetworkName.MAINNET]: 841,
[NetworkName.TESTNET]: 842,
[NetworkName.DEVNET]: 843,
};

export const getNetwork = (name: NetworkName): Network | null => {
const id = networkNameToId[name];
return networks[id] || null;
};

export const getNetworkSubdomain = (network: NetworkName): string => {
switch (network) {
case NetworkName.TESTNET:
return 'testnet';
case NetworkName.DEVNET:
return 'devnet';
case NetworkName.MAINNET:
return 'mainnet';
default:
return '';
}
};
15 changes: 15 additions & 0 deletions packages/taraxa-sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "./lib",
"baseUrl": ".",
"sourceMap": true,
"composite": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "./lib"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "lib", "*.d.ts"]
}
5 changes: 4 additions & 1 deletion packages/taraxa-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"composite": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "./lib"
"declarationDir": "./lib",
"paths": {
"react": ["node_modules/@types/react"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "lib", "*.d.ts"]
Expand Down
1 change: 1 addition & 0 deletions services/community-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@taraxa_project/taraxa-ui": "^0.0.1",
"@taraxa_project/taraxa-sdk": "^0.0.1",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { Button } from '@taraxa_project/taraxa-ui';
import { networks } from '@taraxa_project/taraxa-sdk';
import useMainnet from '../../services/useMainnet';
import useCMetamask from '../../services/useCMetamask';
import { networks } from '../../utils/networks';

const WrongNetwork = () => {
const mainnet = useMainnet();
Expand Down
2 changes: 1 addition & 1 deletion services/community-site/src/services/useExplorerStats.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useMemo } from 'react';
import { networks } from '@taraxa_project/taraxa-sdk';

import { Validator, ValidatorStatus, ValidatorType } from '../interfaces/Validator';
import { networks } from '../utils/networks';
import useApi from './useApi';
import useMainnet from './useMainnet';
import useValidators from './useValidators';
Expand Down
2 changes: 1 addition & 1 deletion services/community-site/src/services/useIndexerYields.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useMemo } from 'react';
import { networks } from '@taraxa_project/taraxa-sdk';
import useApi from './useApi';
import useMainnet from './useMainnet';
import { networks } from '../utils/networks';

export type YieldResponse = {
fromBlock: number;
Expand Down
2 changes: 1 addition & 1 deletion services/community-site/src/services/useMainnet.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'ethers';
import { useMemo } from 'react';
import { networks } from '../utils/networks';
import { networks } from '@taraxa_project/taraxa-sdk';

function useMainnet() {
const chainId = useMemo(() => parseInt(process.env.REACT_APP_MAINNET_CHAIN_ID!, 10), []);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, createContext, useEffect, useCallback, useRef } from 'react';
import { networks } from '../utils/networks';
import { networks } from '@taraxa_project/taraxa-sdk';
import useApi from './useApi';
import useMainnet from './useMainnet';

Expand Down
2 changes: 1 addition & 1 deletion services/community-site/src/services/useWalletPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Text, Modal, Loading, Button } from '@taraxa_project/taraxa-ui';
import { networks } from '@taraxa_project/taraxa-sdk';
import { ethers } from 'ethers';
import React, { useState, useContext, createContext } from 'react';
import { useMediaQuery } from 'react-responsive';
import CloseIcon from '../assets/icons/close';
import ErrorIcon from '../assets/icons/error';
import SuccessIcon from '../assets/icons/success';
import WalletIcon from '../assets/icons/wallet';
import { networks } from '../utils/networks';
import useMainnet from './useMainnet';

export enum WalletPopupState {
Expand Down
1 change: 1 addition & 0 deletions services/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@mui/styles": "^5.9.3",
"@taraxa_project/explorer-shared": "^0.0.1",
"@taraxa_project/taraxa-ui": "^0.0.1",
"@taraxa_project/taraxa-sdk": "^0.0.1",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
Expand Down
4 changes: 2 additions & 2 deletions services/explorer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Container, Box } from '@taraxa_project/taraxa-ui';
import { NetworkName } from '@taraxa_project/taraxa-sdk';
import { Navigate, Route, Routes } from 'react-router-dom';
import { Provider as UrqlProvider } from 'urql';
import { Header, Footer } from './components';
Expand All @@ -16,7 +17,6 @@ import { DagPage } from './pages/Dag/Dag';
import PBFTDataContainer from './pages/PBFTData/PBFTDataContainer';
import { NodeStateProvider, useExplorerNetwork } from './hooks';
import { QueryClient, QueryClientProvider } from 'react-query';
import { Network } from './utils';

declare global {
interface Window {
Expand All @@ -43,7 +43,7 @@ const Root = (): JSX.Element => {
<Route path='/dag' element={<DagPage />} />
<Route path='/tx/:txHash' element={<TransactionDataContainer />} />
<Route path='/address/:account' element={<AddressInfoPage />} />
{currentNetwork !== Network.MAINNET && (
{currentNetwork !== NetworkName.MAINNET && (
<Route path='/faucet' element={<FaucetPage />} />
)}
<Route path='*' element={<Navigate to='/' replace />} />
Expand Down
12 changes: 0 additions & 12 deletions services/explorer/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import { ITaraxaNode } from '@taraxa_project/explorer-shared';
import { BlockData, Transaction } from '../models';

export const MAINNET_API = `${process.env.REACT_APP_MAINNET_API_HOST}`;
export const TESTNET_API = `${process.env.REACT_APP_TESTNET_API_HOST}`;
export const DEVNET_API = `${process.env.REACT_APP_DEVNET_API_HOST}`;

export const MAINNET_FAUCET_API = `${process.env.REACT_APP_MAINNET_FAUCET_HOST}`;
export const TESTNET_FAUCET_API = `${process.env.REACT_APP_TESTNET_FAUCET_HOST}`;
export const DEVNET_FAUCET_API = `${process.env.REACT_APP_DEVNET_FAUCET_HOST}`;

export const MAINNET_RPC_API = `${process.env.REACT_APP_TARAXA_MAINNET_PROVIDER}`;
export const TESTNET_RPC_API = `${process.env.REACT_APP_TARAXA_TESTNET_PROVIDER}`;
export const DEVNET_RPC_API = `${process.env.REACT_APP_TARAXA_DEVNET_PROVIDER}`;

export const TOKEN_PRICE_API_ENDPOINT = `${
process.env.REACT_APP_TOKEN_PRICE_API_ENDPOINT ||
`https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=taraxa`
Expand Down
Loading