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

fix: improve custom chains provisioning and eslint conflicts #1

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"root": true,
"extends": ["react-app", "plugin:prettier/recommended", "./.eslintrc.base"]
"extends": ["react-app", "./.eslintrc.base", "plugin:prettier/recommended"]
}
2 changes: 2 additions & 0 deletions example-next/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const config = {
argsIgnorePattern: '^_',
},
],
'jsx-quotes': 'off',
'import/no-default-export': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-misused-promises': [
'error',
Expand Down
2 changes: 1 addition & 1 deletion example-next/src/app/wallets/mynearwallet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function NearPage() {

return (
<div>
<h1 className='text-lg font-semibold'>Oh, I see you're trying to connect to My Near Wallet.</h1>
<h1 className='text-lg font-semibold'>Oh, I see you are trying to connect to My Near Wallet.</h1>
<h2 className='text-center text-neutral-300 mt-2'>Please wait...</h2>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion example-next/src/components/ConnectedAccounts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
ConnectedAccount,
type ConnectedAccount,
useAccounts,
useChain,
useConnect,
Expand Down
2 changes: 1 addition & 1 deletion example-next/src/components/Example.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
ChainId,
type ChainId,
useChain,
useChains,
useCurrentAccount,
Expand Down
4 changes: 2 additions & 2 deletions example-next/src/components/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';
import { CosmsosChainType, TangledContextProvider, solana } from '@noble-assets/tangled-react';
import { type CosmsosChainType, TangledContextProvider, solana } from '@noble-assets/tangled-react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { ReactNode } from 'react';
import { type ReactNode } from 'react';

const dydx: CosmsosChainType = {
id: 'dydx-mainnet-1' as `${string}-${number}`,
Expand Down
2 changes: 1 addition & 1 deletion example-next/src/components/Tokens.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ETH_ADDRESS, SOL_ADDRESS, TokenMetadata, useChain, useToken } from '@noble-assets/tangled-react';
import { ETH_ADDRESS, SOL_ADDRESS, type TokenMetadata, useChain, useToken } from '@noble-assets/tangled-react';

export const Tokens = () => {
return (
Expand Down
26 changes: 9 additions & 17 deletions packages/react/src/utils/createChainConfigs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CHAIN_DATA, CHAIN_NAME } from '../constants/index.js';
import { Chain, ChainConfig, ChainData, ChainId, SupportedChainsByType } from '../types/index.js';
import { Chain, ChainConfig, SupportedChainsByType } from '../types/index.js';
import getDefaultSupportedChains from './getDefaultSupportedChains.js';

const createChainConfigs = (
Expand All @@ -11,24 +10,17 @@ const createChainConfigs = (

const overrideChainConfig = (
chainsByType: Partial<SupportedChainsByType>,
overrides: Partial<Record<Chain, ChainConfig>> | undefined,
overrides: Partial<Record<string, ChainConfig>> | undefined,
) => {
code-z2 marked this conversation as resolved.
Show resolved Hide resolved
const supportedChains = getDefaultSupportedChains();

for (const chains of Object.values(chainsByType)) {
for (const chain of chains) {
if (supportedChains[chain.type].some((c) => c.id === chain.id)) {
continue;
}
// todo: simplify... this is a bit redundant
const chainId = chain.id.toString() as ChainId;
const chainData = {
...(CHAIN_DATA[chainId] ?? chain),
...overrides?.[CHAIN_NAME[chainId] ?? chain.name],
} as ChainData;

// @ts-expect-error - resolves to never
supportedChains[chain.type].push(chainData);
for (const [type, chains] of Object.entries(chainsByType)) {
if (chains?.length) {
// @ts-expect-error key can be indexed with string
supportedChains[type as keyof SupportedChainsByType] = chains.map((chain) => ({
...chain,
code-z2 marked this conversation as resolved.
Show resolved Hide resolved
...overrides?.[chain.name],
}));
}
code-z2 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
14 changes: 7 additions & 7 deletions packages/react/src/utils/getDefaultSupportedChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as evm from '../chains/evm.js';
import { near } from '../chains/near.js';
import { solana } from '../chains/solana.js';
import { sui } from '../chains/sui.js';
import { CosmsosChainType, EVMChain, OtherChainData, SuiChainType, SupportedChainsByType } from '../types/index.js';
import { SupportedChainsByType } from '../types/index.js';

const getDefaultSupportedChains = (): SupportedChainsByType => {
const supportedChains: SupportedChainsByType = {
Expand Down Expand Up @@ -34,12 +34,12 @@ const getDefaultSupportedChains = (): SupportedChainsByType => {
evm.polygonZkEvm,
evm.scroll,
evm.zkSync,
] as EVMChain[];
supportedChains.cosmos = [cosmos.osmosis, cosmos.injective, cosmos.noble] as CosmsosChainType[];
supportedChains.solana = [solana] as OtherChainData<'solana'>[];
supportedChains.sui = [sui] as SuiChainType[];
supportedChains.near = [near] as OtherChainData<'near'>[];
supportedChains.bitcoin = [bitcoin] as OtherChainData<'bitcoin'>[];
];
supportedChains.cosmos = [cosmos.osmosis, cosmos.injective, cosmos.noble];
supportedChains.solana = [solana];
supportedChains.sui = [sui];
supportedChains.near = [near];
supportedChains.bitcoin = [bitcoin];
code-z2 marked this conversation as resolved.
Show resolved Hide resolved

return supportedChains;
};
Expand Down
Loading
Loading