-
Notifications
You must be signed in to change notification settings - Fork 17
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
wallet connection #70
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,25 +1,47 @@ | ||||||
import type { Web3Provider } from '@ethersproject/providers' | ||||||
import { BigintIsh, ChainId, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core' | ||||||
// This file is lazy-loaded, so the import of smart-order-router is intentional. | ||||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports | ||||||
import { AlphaRouter, AlphaRouterConfig } from '@uniswap/smart-order-router' | ||||||
import { asSupportedChain } from 'constants/chains' | ||||||
import { DEPRECATED_RPC_PROVIDERS } from 'constants/providers' | ||||||
import { RPC_PROVIDERS } from 'constants/providers' | ||||||
import { nativeOnChain } from 'constants/tokens' | ||||||
import JSBI from 'jsbi' | ||||||
import AppStaticJsonRpcProvider from 'rpc/StaticJsonRpcProvider' | ||||||
import { GetQuoteArgs, QuoteResult, QuoteState, SwapRouterNativeAssets } from 'state/routing/types' | ||||||
import { transformSwapRouteToGetQuoteResult } from 'utils/transformSwapRouteToGetQuoteResult' | ||||||
|
||||||
const routers = new Map<ChainId, AlphaRouter>() | ||||||
export function getRouter(chainId: ChainId): AlphaRouter { | ||||||
type RouterAndProvider = { router: AlphaRouter; provider: AppStaticJsonRpcProvider | Web3Provider } | ||||||
let cachedProviderRouter: { chainId: number; routerProvider: RouterAndProvider } | undefined = undefined | ||||||
const routers = new Map<ChainId, RouterAndProvider>() | ||||||
export function getRouter(chainId: ChainId, web3Provider: Web3Provider | undefined): RouterAndProvider { | ||||||
const providerChainId = web3Provider?.network.chainId | ||||||
if ( | ||||||
cachedProviderRouter !== undefined && | ||||||
cachedProviderRouter.chainId === providerChainId && | ||||||
chainId === providerChainId && | ||||||
web3Provider === cachedProviderRouter.routerProvider.provider | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't you just do the last of these 4 checks only and it would be sufficient? |
||||||
) { | ||||||
return cachedProviderRouter.routerProvider | ||||||
} else { | ||||||
cachedProviderRouter = undefined | ||||||
} | ||||||
if (providerChainId !== undefined && chainId === providerChainId && web3Provider !== undefined) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last check is redundant. If
Suggested change
But maybe you need the check in order for TS to properly narrow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its needed for typescript |
||||||
cachedProviderRouter = { | ||||||
chainId, | ||||||
routerProvider: { router: new AlphaRouter({ chainId, provider: web3Provider }), provider: web3Provider }, | ||||||
} | ||||||
return cachedProviderRouter?.routerProvider | ||||||
} | ||||||
const router = routers.get(chainId) | ||||||
if (router) return router | ||||||
|
||||||
const supportedChainId = asSupportedChain(chainId) | ||||||
if (supportedChainId) { | ||||||
const provider = DEPRECATED_RPC_PROVIDERS[supportedChainId] | ||||||
const router = new AlphaRouter({ chainId, provider }) | ||||||
routers.set(chainId, router) | ||||||
return router | ||||||
const provider = RPC_PROVIDERS[supportedChainId] | ||||||
const routerProvider = { router: new AlphaRouter({ chainId, provider }), provider } | ||||||
routers.set(chainId, routerProvider) | ||||||
return routerProvider | ||||||
} | ||||||
|
||||||
throw new Error(`Router does not support this chain (chainId: ${chainId}).`) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have this use built-in only if no wallet or wallet is not mainnet? That way if you are using Uniswap on Ethereum Mainnet it will use your wallet for ENS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we can, I just felt this PR was big enough not to add more stuff to it