more custom rpc fixes
This commit is contained in:
parent
ad79ce2695
commit
b945b62a7a
|
@ -4,7 +4,7 @@ import Button from '@components/shared/Button'
|
|||
import mangoStore from '@store/mangoStore'
|
||||
import useLocalStorageState from 'hooks/useLocalStorageState'
|
||||
import { useTranslation } from 'next-i18next'
|
||||
import { ChangeEvent, useEffect, useState } from 'react'
|
||||
import { ChangeEvent, useEffect, useMemo, useState } from 'react'
|
||||
import { RPC_PROVIDER_KEY } from 'utils/constants'
|
||||
|
||||
const RPC_URLS = [
|
||||
|
@ -12,10 +12,10 @@ const RPC_URLS = [
|
|||
label: 'Triton',
|
||||
value: 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5',
|
||||
},
|
||||
// {
|
||||
// label: 'Genesys Go',
|
||||
// value: 'https://mango.genesysgo.net',
|
||||
// },
|
||||
{
|
||||
label: 'Genesys Go',
|
||||
value: 'https://mango.genesysgo.net',
|
||||
},
|
||||
{ label: 'Custom', value: '' },
|
||||
]
|
||||
|
||||
|
@ -28,13 +28,20 @@ const RpcSettings = () => {
|
|||
RPC_PROVIDER_KEY,
|
||||
RPC_URLS[0].value
|
||||
)
|
||||
const rpcEndpoint =
|
||||
RPC_URLS.find((node) => node.label === rpcEndpointProvider.label) ||
|
||||
RPC_URLS[0]
|
||||
|
||||
const rpcEndpoint = useMemo(() => {
|
||||
return (
|
||||
RPC_URLS.find((node) => node.value === rpcEndpointProvider) || {
|
||||
label: 'Custom',
|
||||
value: rpcEndpointProvider,
|
||||
}
|
||||
)
|
||||
}, [rpcEndpointProvider])
|
||||
|
||||
const handleSetEndpointProvider = (provider: string) => {
|
||||
const endpointProvider =
|
||||
RPC_URLS.find((node) => node.label === provider) || RPC_URLS[0]
|
||||
const endpointProvider = RPC_URLS.find(
|
||||
(node) => node.label === provider
|
||||
) || { label: 'Custom', value: rpcEndpointProvider }
|
||||
setRpcEndpointProvider(endpointProvider.value)
|
||||
if (provider !== 'Custom') {
|
||||
setShowCustomForm(false)
|
||||
|
@ -43,16 +50,15 @@ const RpcSettings = () => {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (rpcEndpointProvider.label === 'Custom') {
|
||||
if (rpcEndpoint.label === 'Custom') {
|
||||
setShowCustomForm(true)
|
||||
setCustomUrl(rpcEndpointProvider.value)
|
||||
setCustomUrl(rpcEndpoint.value)
|
||||
}
|
||||
}, [rpcEndpointProvider])
|
||||
}, [rpcEndpoint])
|
||||
|
||||
const handleSaveCustomEndpoint = () => {
|
||||
if (!customUrl) return
|
||||
const provider = { label: 'Custom', value: customUrl }
|
||||
setRpcEndpointProvider(provider)
|
||||
setRpcEndpointProvider(customUrl)
|
||||
actions.updateConnection(customUrl)
|
||||
}
|
||||
|
||||
|
|
|
@ -325,16 +325,21 @@ export type MangoStore = {
|
|||
|
||||
const mangoStore = create<MangoStore>()(
|
||||
subscribeWithSelector((_set, get) => {
|
||||
let rpcUrl = ENDPOINT?.url
|
||||
let rpcUrl = ENDPOINT.url
|
||||
|
||||
if (typeof window !== 'undefined' && CLUSTER === 'mainnet-beta') {
|
||||
const urlFromLocalStorage = localStorage.getItem(RPC_PROVIDER_KEY)
|
||||
rpcUrl = urlFromLocalStorage
|
||||
? JSON.parse(urlFromLocalStorage).value
|
||||
: ENDPOINT?.url
|
||||
: ENDPOINT.url
|
||||
}
|
||||
|
||||
const connection = new web3.Connection(rpcUrl, 'processed')
|
||||
let connection: Connection
|
||||
try {
|
||||
connection = new web3.Connection(rpcUrl, 'processed')
|
||||
} catch {
|
||||
connection = new web3.Connection(ENDPOINT.url, 'processed')
|
||||
}
|
||||
const provider = new AnchorProvider(connection, emptyWallet, options)
|
||||
provider.opts.skipPreflight = true
|
||||
const client = initMangoClient(provider)
|
||||
|
@ -971,6 +976,7 @@ const mangoStore = create<MangoStore>()(
|
|||
)
|
||||
newProvider.opts.skipPreflight = true
|
||||
const newClient = initMangoClient(newProvider)
|
||||
console.log('here')
|
||||
|
||||
set((state) => {
|
||||
state.connection = newConnection
|
||||
|
|
|
@ -39,6 +39,8 @@ export const FAVORITE_MARKETS_KEY = 'favoriteMarkets-0.2'
|
|||
|
||||
export const THEME_KEY = 'theme-0.1'
|
||||
|
||||
export const RPC_PROVIDER_KEY = 'rpcProviderKey-0.3'
|
||||
|
||||
// Unused
|
||||
export const PROFILE_CATEGORIES = [
|
||||
'borrower',
|
||||
|
@ -58,8 +60,6 @@ export const DEFAULT_MARKET_NAME = 'SOL/USDC'
|
|||
|
||||
export const MIN_SOL_BALANCE = 0.04
|
||||
|
||||
export const RPC_PROVIDER_KEY = 'rpcProviderKey'
|
||||
|
||||
export const ACCOUNT_ACTION_MODAL_HEIGHT = '478px'
|
||||
|
||||
export const ACCOUNT_ACTION_MODAL_INNER_HEIGHT = '416px'
|
||||
|
|
Loading…
Reference in New Issue