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"]
}
6 changes: 3 additions & 3 deletions packages/taraxa-ui/src/components/AwardCard/AwardCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React from 'react';
import { Card, CardContent, Box, Typography } from '@mui/material';
import useStyles from './AwardCard.styles';
import { Award } from '../Icons';
Expand All @@ -10,12 +10,12 @@ export interface AwardCardProps {
description: string;
}

export const AwardCard: FC<AwardCardProps> = ({
export const AwardCard = ({
title,
subtitle,
total,
description,
}) => {
}: AwardCardProps) => {
const classes = useStyles();

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/taraxa-ui/src/components/BlockCard/BlockCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React from 'react';
import {
Divider,
Card,
Expand All @@ -18,7 +18,7 @@ export interface BlockCardProps {
transactions: TransactionDetailsProps[];
}

export const BlockCard: FC<BlockCardProps> = ({ title, transactions }) => {
export const BlockCard = ({ title, transactions }: BlockCardProps) => {
const classes = useStyles();

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/taraxa-ui/src/components/Icons/Exclamation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

const Exclamation: React.FC<{ color: string }> = ({ color }) => {
const Exclamation = ({ color }: { color: string }) => {
return (
<svg
width='18'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ProgressBarCellProps {
percentage: string;
}

const ProgressBar: React.FC<ProgressBarCellProps> = ({ percentage }) => {
const ProgressBar = ({ percentage }: ProgressBarCellProps) => {
const classes = useStyles();
return (
<div className={classes.cellContainer}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React from 'react';
import { Box, Typography } from '@mui/material';
import useStyles from './TransactionDetails.styles';
import { Block, Route } from '../Icons';
Expand All @@ -19,14 +19,14 @@ export const shortenHash = (text: string, visibleLength = 44): string => {
return `${text.substring(0, visibleLength).replace(/\s+$/, '')}...`;
};

export const TransactionDetails: FC<TransactionDetailsProps> = ({
export const TransactionDetails = ({
hash,
transactionCount,
timeSince,
hashElement,
level,
blockNumber,
}) => {
}: TransactionDetailsProps) => {
const classes = useStyles();

return (
Expand Down
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
Loading