Skip to content

Commit

Permalink
Merge pull request #300 from pangolindex/dev
Browse files Browse the repository at this point in the history
To Prod
  • Loading branch information
SarjuHansaliya committed Mar 7, 2023
2 parents 3e0752f + c78d458 commit 884aee9
Show file tree
Hide file tree
Showing 98 changed files with 2,193 additions and 2,202 deletions.
15 changes: 1 addition & 14 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [
2,
'always',
[
'lower-case', // default
'camel-case', // camelCase
'kebab-case', // kebab-case
'pascal-case', // PascalCase
'sentence-case', // Sentence case
'snake-case', // snake_case
'start-case', // Start Case,
'upper-case', // Upper case
],
],
'subject-case': [0, 'always'],
},
ignores: [(commit) => commit.includes('[skip ci]')],
};
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@ethersproject/providers": "^5.7.2",
"@pangolindex/sdk": "5.0.0-rc.0",
"@pangolindex/sdk": "5.0.1",
"@types/react-router-dom": "^5.3.3",
"@web3-react/core": "6.0.9",
"@web3-react/injected-connector": "6.0.7",
Expand Down
8 changes: 4 additions & 4 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"

"@pangolindex/sdk@5.0.0-rc.0":
version "5.0.0-rc.0"
resolved "https://registry.yarnpkg.com/@pangolindex/sdk/-/sdk-5.0.0-rc.0.tgz#5d865fccf4d1db93cfb096980969f0365afb3f4b"
integrity sha512-Ce4zbtX5bMLYvk9mua2v5gJazBi1TrnCnMcQlVCobwLFolwunB7MMMfUgiK3aYORyyiDKJtvaPH97Q2BMIkt9Q==
"@pangolindex/sdk@5.0.1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@pangolindex/sdk/-/sdk-5.0.1.tgz#d19e9947de929956a5ad94617400e24db4a1bc3c"
integrity sha512-L1fXniq9vm+DicpuT9Y8wZT1ENO5gNHK4J2BKqlYbLpDAMAuul4m3ibmaYrmHlgRdYyrL0B8pytf8yCFzpdtMw==
dependencies:
big.js "^5.2.2"
decimal.js-light "^2.5.0"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pangolindex/components",
"version": "6.0.1",
"version": "6.0.2-rc.2",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"engines": {
Expand Down Expand Up @@ -123,7 +123,7 @@
"@babel/preset-typescript": "^7.18.6",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@pangolindex/sdk": "5.0.0",
"@pangolindex/sdk": "5.0.1",
"@rollup/plugin-commonjs": "^21.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.5",
Expand Down
6 changes: 2 additions & 4 deletions src/apollo/block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag'; // eslint-disable-line import/no-named-as-default
import { useQuery } from 'react-query';
import { useChainId } from 'src/hooks';
import { subgraphClient } from './client';
import { SubgraphEnum, useSubgraphClient } from './client';

export const GET_BLOCKS = (timestamps) => {
let queryString = 'query blocks {';
Expand Down Expand Up @@ -68,12 +68,10 @@ export interface SubgraphLastBlockResponse {
*/
export function useLastSubgraphBlock() {
const chainId = useChainId();

const client = useSubgraphClient(SubgraphEnum.Exchange);
const { data: block } = useQuery(
['get-last-block-subgraph', chainId],
async () => {
const client = subgraphClient[chainId];

if (!client) return undefined;

const data = await client.request<SubgraphLastBlockResponse>(GET_LAST_BLOCK);
Expand Down
100 changes: 40 additions & 60 deletions src/apollo/client.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,51 @@
import { ChainId } from '@pangolindex/sdk';
import { CHAINS, ChainId } from '@pangolindex/sdk';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { GraphQLClient } from 'graphql-request';
import { SUBGRAPH_BASE_URL } from 'src/constants';
import { useChainId } from 'src/hooks';

export const client = new ApolloClient({
link: new HttpLink({
uri: `${SUBGRAPH_BASE_URL}/exchange`,
}),
cache: new InMemoryCache(),
// shouldBatch: true,
});
export const getExchangeSubgraphApolloClient = (chainId: ChainId) => {
const url = CHAINS[chainId]?.subgraph?.exchange;

export const blockClient = new ApolloClient({
link: new HttpLink({
uri: 'https://api.thegraph.com/subgraphs/name/dasconnor/avalanche-blocks',
}),
cache: new InMemoryCache(),
});
if (url) {
return new ApolloClient({
link: new HttpLink({
uri: url,
}),
cache: new InMemoryCache(),
});
}
};

export const getBlockSubgraphApolloClient = (chainId: ChainId) => {
const url = CHAINS[chainId]?.subgraph?.blocks;

export const avalancheMininchefV2Client = new GraphQLClient(
'https://api.thegraph.com/subgraphs/name/sarjuhansaliya/minichefv2-dummy',
{ headers: {} },
);
if (url) {
return new ApolloClient({
link: new HttpLink({
uri: url,
}),
cache: new InMemoryCache(),
});
}
};

export const hederaTestnetSubgraphGql = new GraphQLClient(
'https://hedera-test.pangolin.network/subgraphs/name/pangolin',
{
headers: {},
},
);
export enum SubgraphEnum {
Exchange = 'exchange',
Pangochef = 'pangochef',
Minichef = 'minichef',
}

export const hederaMainnetSubgraphGql = new GraphQLClient(
'https://hedera-graph.pangolin.network/subgraphs/name/pangolin',
{
headers: {},
},
);
export const getSubgraphClient = (chainId: ChainId, subgraph: SubgraphEnum) => {
const url = CHAINS[chainId]?.subgraph?.[subgraph];

export const subgraphClient = {
[ChainId.AVALANCHE]: avalancheMininchefV2Client,
[ChainId.FUJI]: undefined,
[ChainId.WAGMI]: undefined,
[ChainId.COSTON]: undefined,
[ChainId.SONGBIRD]: undefined,
[ChainId.FLARE_MAINNET]: undefined,
[ChainId.HEDERA_TESTNET]: hederaTestnetSubgraphGql,
[ChainId.HEDERA_MAINNET]: hederaMainnetSubgraphGql,
[ChainId.NEAR_MAINNET]: undefined,
[ChainId.NEAR_TESTNET]: undefined,
[ChainId.COSTON2]: undefined,
[ChainId.EVMOS_TESTNET]: undefined,
[ChainId.EVMOS_MAINNET]: undefined,
[ChainId.ETHEREUM]: undefined,
[ChainId.POLYGON]: undefined,
[ChainId.FANTOM]: undefined,
[ChainId.XDAI]: undefined,
[ChainId.BSC]: undefined,
[ChainId.ARBITRUM]: undefined,
[ChainId.CELO]: undefined,
[ChainId.OKXCHAIN]: undefined,
[ChainId.VELAS]: undefined,
[ChainId.AURORA]: undefined,
[ChainId.CRONOS]: undefined,
[ChainId.FUSE]: undefined,
[ChainId.MOONRIVER]: undefined,
[ChainId.MOONBEAM]: undefined,
[ChainId.OP]: undefined,
if (url) {
return new GraphQLClient(url);
}
};

export function useSubgraphClient(subgraph: SubgraphEnum): GraphQLClient | undefined {
const chainId = useChainId();
return getSubgraphClient(chainId, subgraph);
}
4 changes: 2 additions & 2 deletions src/apollo/pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gql from 'graphql-tag'; // eslint-disable-line import/no-named-as-default
import { useQuery } from 'react-query';
import { useChainId } from 'src/hooks';
import { validateAddressMapping } from 'src/utils';
import { subgraphClient } from './client';
import { SubgraphEnum, useSubgraphClient } from './client';
import { SubgraphToken } from './tokens';

type SubgraphPair = {
Expand Down Expand Up @@ -70,10 +70,10 @@ export const useSubgraphPairs = (pairAddresses: (string | undefined)[]) => {
// we need to convert addresses to lowercase as subgraph has lowercase addresses
const pairsToFind = pairAddresses?.map((item) => item?.toLowerCase())?.filter((item) => !!item) as string[];
const chainId = useChainId();
const gqlClient = useSubgraphClient(SubgraphEnum.Exchange);
const validateAddress = validateAddressMapping[chainId];
// get pairs from subgraph
return useQuery<SubgraphPair[] | null>(['get-subgraph-pairs', chainId, ...pairsToFind], async () => {
const gqlClient = subgraphClient[chainId];
if (!gqlClient) {
return null;
}
Expand Down
8 changes: 3 additions & 5 deletions src/apollo/pangochef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gql from 'graphql-tag'; // eslint-disable-line import/no-named-as-default
import { useQuery } from 'react-query';
import { useChainId, usePangolinWeb3 } from 'src/hooks';
import { hederaFn } from 'src/utils/hedera';
import { subgraphClient } from './client';
import { SubgraphEnum, useSubgraphClient } from './client';
import { SubgraphToken } from './tokens';

export interface PangoChefSubgraphInfo {
Expand Down Expand Up @@ -140,11 +140,10 @@ export const GET_FARMS_STAKED = gql`
export const useSubgraphFarms = () => {
const chainId = useChainId();
const { account } = usePangolinWeb3();

const gqlClient = useSubgraphClient(SubgraphEnum.Pangochef);
return useQuery<PangoChefSubgraphInfo[]>(
['get-pangochef-subgraph-farms', chainId, account],
async () => {
const gqlClient = subgraphClient[chainId];
if (!gqlClient) {
return null;
}
Expand All @@ -162,11 +161,10 @@ export const useSubgraphFarms = () => {
export function useSubgraphFarmsStakedAmount() {
const chainId = useChainId();
const { account } = usePangolinWeb3();

const gqlClient = useSubgraphClient(SubgraphEnum.Pangochef);
return useQuery<FarmPosition[]>(
['get-pangochef-subgraph-farms-staked-amount', chainId, account],
async () => {
const gqlClient = subgraphClient[chainId];
if (!gqlClient) {
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions src/apollo/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMemo } from 'react';
import { useQuery } from 'react-query';
import { useChainId } from 'src/hooks';
import { validateAddressMapping } from 'src/utils';
import { subgraphClient } from './client';
import { SubgraphEnum, useSubgraphClient } from './client';

export type SubgraphToken = {
id: string;
Expand Down Expand Up @@ -41,7 +41,7 @@ export const useSubgraphTokens = (tokenAddresses: (string | undefined)[]) => {
);
const chainId = useChainId();
const validateAddress = validateAddressMapping[chainId];
const gqlClient = subgraphClient[chainId];
const gqlClient = useSubgraphClient(SubgraphEnum.Exchange);
// get tokens from subgraph
return useQuery<SubgraphToken[]>(
['get-subgraph-tokens', chainId, ...tokensToFind],
Expand Down
4 changes: 0 additions & 4 deletions src/assets/images/evmos.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/assets/images/flare.svg

This file was deleted.

12 changes: 0 additions & 12 deletions src/assets/images/hedera.svg

This file was deleted.

Binary file removed src/assets/images/songbird.png
Binary file not shown.
Binary file removed src/assets/images/wagmi.png
Binary file not shown.
51 changes: 3 additions & 48 deletions src/components/CurrencyLogo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { CAVAX, ChainId, Currency, Token } from '@pangolindex/sdk';
import deepEqual from 'deep-equal';
import { Currency, Token } from '@pangolindex/sdk';
import React, { useMemo } from 'react';
import EvmosLogo from 'src/assets/images/evmos.svg';
import FlareLogo from 'src/assets/images/flare.svg';
import HederaLogo from 'src/assets/images/hedera.svg';
import NearLogo from 'src/assets/images/near.svg';
import SongBirdLogo from 'src/assets/images/songbird.png';
import WgmiLogo from 'src/assets/images/wagmi.png';
import { AvaxLogo, CflrLogo } from 'src/components/Icons';
import { LogoSize } from 'src/constants';
import { useChainId } from 'src/hooks';
import { getTokenLogoURL } from 'src/utils/getTokenLogoURL';
Expand All @@ -29,48 +21,11 @@ export default function CurrencyLogo({
const chainId = useChainId();

const srcs: string[] = useMemo(() => {
if (
currency === CAVAX[ChainId.AVALANCHE] ||
currency === CAVAX[ChainId.WAGMI] ||
currency === CAVAX[ChainId.COSTON] ||
currency === CAVAX[ChainId.SONGBIRD] ||
currency === CAVAX[ChainId.FLARE_MAINNET] ||
currency === CAVAX[ChainId.HEDERA_TESTNET] ||
currency === CAVAX[ChainId.HEDERA_MAINNET] ||
currency === CAVAX[ChainId.NEAR_TESTNET] ||
currency === CAVAX[ChainId.NEAR_MAINNET] ||
currency === CAVAX[ChainId.COSTON2] ||
currency === CAVAX[ChainId.EVMOS_TESTNET || currency === CAVAX[ChainId.EVMOS_MAINNET]]
)
return [];
if (currency instanceof Token || !!(currency as Token).address) {
const primarySrc = getTokenLogoURL((currency as Token)?.address, chainId, imageSize);
const primarySrc = getTokenLogoURL((currency as Token)?.address, chainId, imageSize);

return [primarySrc];
}

return [];
return [primarySrc];
}, [currency]);

if (deepEqual(currency, CAVAX[ChainId.AVALANCHE])) {
return <AvaxLogo size={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.WAGMI])) {
return <img src={WgmiLogo} width={`${size}px`} height={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.COSTON])) {
return <CflrLogo size={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.NEAR_TESTNET]) || deepEqual(currency, CAVAX[ChainId.NEAR_MAINNET])) {
return <img src={NearLogo} width={`${size}px`} height={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.SONGBIRD])) {
return <img src={SongBirdLogo} width={`${size}px`} height={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.FLARE_MAINNET])) {
return <img src={FlareLogo} width={`${size}px`} height={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.HEDERA_TESTNET]) || deepEqual(currency, CAVAX[ChainId.HEDERA_MAINNET])) {
return <img src={HederaLogo} width={`${size}px`} height={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.COSTON2])) {
return <CflrLogo size={`${size}px`} className={className} />;
} else if (deepEqual(currency, CAVAX[ChainId.EVMOS_TESTNET]) || deepEqual(currency, CAVAX[ChainId.EVMOS_MAINNET])) {
return <img src={EvmosLogo} width={`${size}px`} height={`${size}px`} className={className} />;
}
return (
<StyledLogo
className={className}
Expand Down
Loading

1 comment on commit 884aee9

@vercel
Copy link

@vercel vercel bot commented on 884aee9 Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.