From 0a75f8f0b62f6fe241055fb1f989e4f3347fa30d Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 15 Dec 2022 23:28:17 +1100 Subject: [PATCH 1/4] add rpc settings ui --- components/settings/RpcSettings.tsx | 97 ++++++++++++++++++++++++++++ components/settings/SettingsPage.tsx | 4 ++ public/locales/en/settings.json | 3 + public/locales/es/settings.json | 3 + public/locales/ru/settings.json | 3 + public/locales/zh/settings.json | 3 + public/locales/zh_tw/settings.json | 3 + utils/constants.ts | 2 + 8 files changed, 118 insertions(+) create mode 100644 components/settings/RpcSettings.tsx diff --git a/components/settings/RpcSettings.tsx b/components/settings/RpcSettings.tsx new file mode 100644 index 00000000..fdfa76f0 --- /dev/null +++ b/components/settings/RpcSettings.tsx @@ -0,0 +1,97 @@ +import ButtonGroup from '@components/forms/ButtonGroup' +import Input from '@components/forms/Input' +import Button from '@components/shared/Button' +import useLocalStorageState from 'hooks/useLocalStorageState' +import { useTranslation } from 'next-i18next' +import { ChangeEvent, useEffect, useState } from 'react' +import { RPC_PROVIDER_KEY } from 'utils/constants' + +const RPC_URLS = [ + { + label: 'Syndica', + value: + 'https://solana-api.syndica.io/access-token/4ywEBJNxuwPLXXU9UlMK67fAMZBt1GLdwuXyXSYnoYPn5aXajT8my0R5klXhYRkk/rpc', + }, + { + label: 'Triton', + value: 'https://mango-mango-d092.mainnet.rpcpool.com/', + }, + { label: 'Custom', value: '' }, +] + +const RpcSettings = () => { + const { t } = useTranslation('settings') + const [customUrl, setCustomUrl] = useState('') + const [showCustomForm, setShowCustomForm] = useState(false) + const [rpcEndpointProvider, setRpcEndpointProvider] = useLocalStorageState( + RPC_PROVIDER_KEY, + RPC_URLS[0] + ) + const rpcEndpoint = RPC_URLS.find( + (node) => node.label === rpcEndpointProvider.label + ) + + const handleSetEndpointProvider = (provider: string) => { + const endpointProvider = RPC_URLS.find((node) => node.label === provider) + setRpcEndpointProvider(endpointProvider) + if (provider !== 'Custom') { + setShowCustomForm(false) + // update connection to endpointProvider.value + } + } + + useEffect(() => { + if (rpcEndpointProvider.label === 'Custom') { + setShowCustomForm(true) + setCustomUrl(rpcEndpointProvider.value) + } + }, [rpcEndpointProvider]) + + const handleSaveCustomEndpoint = () => { + if (!customUrl) return + const provider = { label: 'Custom', value: customUrl } + setRpcEndpointProvider(provider) + // update connection to customUrl + } + + return ( + <> +

{t('rpc')}

+
+

{t('rpc-provider')}

+
+ handleSetEndpointProvider(v)} + values={RPC_URLS.map((val) => val.label)} + /> + {showCustomForm ? ( +
+
+ ) => + setCustomUrl(e.target.value) + } + /> + +
+
+ ) : null} +
+
+ + ) +} + +export default RpcSettings diff --git a/components/settings/SettingsPage.tsx b/components/settings/SettingsPage.tsx index 78a28382..a2179ab8 100644 --- a/components/settings/SettingsPage.tsx +++ b/components/settings/SettingsPage.tsx @@ -1,12 +1,16 @@ import AnimationSettings from './AnimationSettings' import DisplaySettings from './DisplaySettings' import PreferredExplorerSettings from './PreferredExplorerSettings' +import RpcSettings from './RpcSettings' import SoundSettings from './SoundSettings' const SettingsPage = () => { return (
+ +
+
diff --git a/public/locales/en/settings.json b/public/locales/en/settings.json index ce0386cb..7c8c4c54 100644 --- a/public/locales/en/settings.json +++ b/public/locales/en/settings.json @@ -24,6 +24,9 @@ "orderbook-flash": "Orderbook Flash", "preferred-explorer": "Preferred Explorer", "recent-trades": "Recent Trades", + "rpc": "RPC", + "rpc-provider": "RPC Provider", + "rpc-url": "Enter RPC URL", "russian": "Русский", "slider": "Slider", "solana-beach": "Solana Beach", diff --git a/public/locales/es/settings.json b/public/locales/es/settings.json index ce0386cb..7c8c4c54 100644 --- a/public/locales/es/settings.json +++ b/public/locales/es/settings.json @@ -24,6 +24,9 @@ "orderbook-flash": "Orderbook Flash", "preferred-explorer": "Preferred Explorer", "recent-trades": "Recent Trades", + "rpc": "RPC", + "rpc-provider": "RPC Provider", + "rpc-url": "Enter RPC URL", "russian": "Русский", "slider": "Slider", "solana-beach": "Solana Beach", diff --git a/public/locales/ru/settings.json b/public/locales/ru/settings.json index ce0386cb..7c8c4c54 100644 --- a/public/locales/ru/settings.json +++ b/public/locales/ru/settings.json @@ -24,6 +24,9 @@ "orderbook-flash": "Orderbook Flash", "preferred-explorer": "Preferred Explorer", "recent-trades": "Recent Trades", + "rpc": "RPC", + "rpc-provider": "RPC Provider", + "rpc-url": "Enter RPC URL", "russian": "Русский", "slider": "Slider", "solana-beach": "Solana Beach", diff --git a/public/locales/zh/settings.json b/public/locales/zh/settings.json index ce0386cb..7c8c4c54 100644 --- a/public/locales/zh/settings.json +++ b/public/locales/zh/settings.json @@ -24,6 +24,9 @@ "orderbook-flash": "Orderbook Flash", "preferred-explorer": "Preferred Explorer", "recent-trades": "Recent Trades", + "rpc": "RPC", + "rpc-provider": "RPC Provider", + "rpc-url": "Enter RPC URL", "russian": "Русский", "slider": "Slider", "solana-beach": "Solana Beach", diff --git a/public/locales/zh_tw/settings.json b/public/locales/zh_tw/settings.json index ce0386cb..7c8c4c54 100644 --- a/public/locales/zh_tw/settings.json +++ b/public/locales/zh_tw/settings.json @@ -24,6 +24,9 @@ "orderbook-flash": "Orderbook Flash", "preferred-explorer": "Preferred Explorer", "recent-trades": "Recent Trades", + "rpc": "RPC", + "rpc-provider": "RPC Provider", + "rpc-url": "Enter RPC URL", "russian": "Русский", "slider": "Slider", "solana-beach": "Solana Beach", diff --git a/utils/constants.ts b/utils/constants.ts index 8fda48a1..c9c42918 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -48,3 +48,5 @@ export const NOTIFICATION_POSITION_KEY = 'notificationPosition' export const MIN_SOL_BALANCE = 0.04 export const FAVORITE_MARKETS_KEY = 'favoriteMarkets' + +export const RPC_PROVIDER_KEY = 'rpcProviderKey' From de69a19ade456e4b71ee3b2761bef9ab697c6c8f Mon Sep 17 00:00:00 2001 From: saml33 Date: Fri, 16 Dec 2022 13:19:11 +1100 Subject: [PATCH 2/4] update connection/client --- components/settings/RpcSettings.tsx | 14 ++-- public/locales/en/settings.json | 1 + public/locales/es/settings.json | 1 + public/locales/ru/settings.json | 1 + public/locales/zh/settings.json | 1 + public/locales/zh_tw/settings.json | 1 + store/mangoStore.ts | 100 +++++++++++++++++++++++----- 7 files changed, 98 insertions(+), 21 deletions(-) diff --git a/components/settings/RpcSettings.tsx b/components/settings/RpcSettings.tsx index fdfa76f0..e3d812ad 100644 --- a/components/settings/RpcSettings.tsx +++ b/components/settings/RpcSettings.tsx @@ -1,26 +1,28 @@ import ButtonGroup from '@components/forms/ButtonGroup' import Input from '@components/forms/Input' 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 { RPC_PROVIDER_KEY } from 'utils/constants' const RPC_URLS = [ + { + label: 'Triton', + value: 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5', + }, { label: 'Syndica', value: 'https://solana-api.syndica.io/access-token/4ywEBJNxuwPLXXU9UlMK67fAMZBt1GLdwuXyXSYnoYPn5aXajT8my0R5klXhYRkk/rpc', }, - { - label: 'Triton', - value: 'https://mango-mango-d092.mainnet.rpcpool.com/', - }, { label: 'Custom', value: '' }, ] const RpcSettings = () => { const { t } = useTranslation('settings') + const actions = mangoStore((s) => s.actions) const [customUrl, setCustomUrl] = useState('') const [showCustomForm, setShowCustomForm] = useState(false) const [rpcEndpointProvider, setRpcEndpointProvider] = useLocalStorageState( @@ -36,7 +38,7 @@ const RpcSettings = () => { setRpcEndpointProvider(endpointProvider) if (provider !== 'Custom') { setShowCustomForm(false) - // update connection to endpointProvider.value + actions.updateConnection(endpointProvider!.value) } } @@ -51,7 +53,7 @@ const RpcSettings = () => { if (!customUrl) return const provider = { label: 'Custom', value: customUrl } setRpcEndpointProvider(provider) - // update connection to customUrl + actions.updateConnection(customUrl) } return ( diff --git a/public/locales/en/settings.json b/public/locales/en/settings.json index 7c8c4c54..6fc93af4 100644 --- a/public/locales/en/settings.json +++ b/public/locales/en/settings.json @@ -28,6 +28,7 @@ "rpc-provider": "RPC Provider", "rpc-url": "Enter RPC URL", "russian": "Русский", + "save": "Save", "slider": "Slider", "solana-beach": "Solana Beach", "solana-explorer": "Solana Explorer", diff --git a/public/locales/es/settings.json b/public/locales/es/settings.json index 7c8c4c54..6fc93af4 100644 --- a/public/locales/es/settings.json +++ b/public/locales/es/settings.json @@ -28,6 +28,7 @@ "rpc-provider": "RPC Provider", "rpc-url": "Enter RPC URL", "russian": "Русский", + "save": "Save", "slider": "Slider", "solana-beach": "Solana Beach", "solana-explorer": "Solana Explorer", diff --git a/public/locales/ru/settings.json b/public/locales/ru/settings.json index 7c8c4c54..6fc93af4 100644 --- a/public/locales/ru/settings.json +++ b/public/locales/ru/settings.json @@ -28,6 +28,7 @@ "rpc-provider": "RPC Provider", "rpc-url": "Enter RPC URL", "russian": "Русский", + "save": "Save", "slider": "Slider", "solana-beach": "Solana Beach", "solana-explorer": "Solana Explorer", diff --git a/public/locales/zh/settings.json b/public/locales/zh/settings.json index 7c8c4c54..6fc93af4 100644 --- a/public/locales/zh/settings.json +++ b/public/locales/zh/settings.json @@ -28,6 +28,7 @@ "rpc-provider": "RPC Provider", "rpc-url": "Enter RPC URL", "russian": "Русский", + "save": "Save", "slider": "Slider", "solana-beach": "Solana Beach", "solana-explorer": "Solana Explorer", diff --git a/public/locales/zh_tw/settings.json b/public/locales/zh_tw/settings.json index 7c8c4c54..6fc93af4 100644 --- a/public/locales/zh_tw/settings.json +++ b/public/locales/zh_tw/settings.json @@ -28,6 +28,7 @@ "rpc-provider": "RPC Provider", "rpc-url": "Enter RPC URL", "russian": "Русский", + "save": "Save", "slider": "Slider", "solana-beach": "Solana Beach", "solana-explorer": "Solana Explorer", diff --git a/store/mangoStore.ts b/store/mangoStore.ts index 551126d7..aa47e0a8 100644 --- a/store/mangoStore.ts +++ b/store/mangoStore.ts @@ -32,6 +32,7 @@ import { INPUT_TOKEN_DEFAULT, LAST_ACCOUNT_KEY, OUTPUT_TOKEN_DEFAULT, + RPC_PROVIDER_KEY, } from '../utils/constants' import { OrderbookL2, SpotBalances } from 'types' import spotBalancesUpdater from './spotBalancesUpdater' @@ -40,24 +41,67 @@ import perpPositionsUpdater from './perpPositionsUpdater' const GROUP = new PublicKey('78b8f4cGCwmZ9ysPFMWLaLTkkaYnUjwMJYStWe5RTSSX') -export const connection = new web3.Connection( - process.env.NEXT_PUBLIC_ENDPOINT || - 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5', - 'processed' -) +const ENDPOINTS = [ + { + name: 'mainnet-beta', + url: + process.env.NEXT_PUBLIC_ENDPOINT || + 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5', + websocket: + process.env.NEXT_PUBLIC_ENDPOINT || + 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5', + custom: false, + }, + { + name: 'devnet', + // url: 'https://mango.devnet.rpcpool.com', + // websocket: 'https://mango.devnet.rpcpool.com', + url: 'https://api.devnet.solana.com', + websocket: 'https://api.devnet.solana.com', + custom: false, + }, + // { + // name: 'testnet', + // url: 'https://api.testnet.solana.com', + // websocket: 'https://api.testnet.solana.com', + // custom: false, + // }, +] + +// export const connection = new web3.Connection( +// process.env.NEXT_PUBLIC_ENDPOINT || +// 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5', +// 'processed' +// ) const options = AnchorProvider.defaultOptions() export const CLUSTER: 'mainnet-beta' | 'devnet' = 'mainnet-beta' +const ENDPOINT = ENDPOINTS.find((e) => e.name === CLUSTER) const wallet = new EmptyWallet(Keypair.generate()) -const DEFAULT_PROVIDER = new AnchorProvider(connection, wallet, options) -DEFAULT_PROVIDER.opts.skipPreflight = true -const DEFAULT_CLIENT = MangoClient.connect( - DEFAULT_PROVIDER, - CLUSTER, - MANGO_V4_ID[CLUSTER], - { +// const DEFAULT_PROVIDER = new AnchorProvider(connection, wallet, options) +// DEFAULT_PROVIDER.opts.skipPreflight = true +// const DEFAULT_CLIENT = MangoClient.connect( +// DEFAULT_PROVIDER, +// CLUSTER, +// MANGO_V4_ID[CLUSTER], +// { +// idsSource: 'get-program-accounts', +// } +// ) + +const initMangoClient = (provider: AnchorProvider): MangoClient => { + return MangoClient.connect(provider, CLUSTER, MANGO_V4_ID[CLUSTER], { + postSendTxCallback: ({ txid }: { txid: string }) => { + notify({ + title: 'Transaction sent', + description: 'Waiting for confirmation', + type: 'confirm', + txid: txid, + }) + }, + // blockhashCommitment: 'confirmed', idsSource: 'get-program-accounts', - } -) + }) +} export interface TotalInterestDataItem { borrow_interest: number @@ -295,11 +339,24 @@ export type MangoStore = { connectMangoClientWithWallet: (wallet: WalletAdapter) => Promise reloadGroup: () => Promise loadMarketFills: () => Promise + updateConnection: (url: string) => void } } const mangoStore = create()( subscribeWithSelector((_set, get) => { + 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 + } + + const connection = new web3.Connection(rpcUrl!, 'processed') + const provider = new AnchorProvider(connection, wallet, options) + provider.opts.skipPreflight = true + const client = initMangoClient(provider) return { activityFeed: { feed: [], @@ -310,7 +367,7 @@ const mangoStore = create()( connection, group: undefined, groupLoaded: false, - client: DEFAULT_CLIENT, + client, mangoAccount: { current: undefined, initialLoad: true, @@ -940,6 +997,19 @@ const mangoStore = create()( console.log('Error fetching fills:', err) } }, + updateConnection(endpointUrl) { + const set = get().set + const newConnection = new web3.Connection(endpointUrl, 'processed') + + const newProvider = new AnchorProvider(connection, wallet, options) + newProvider.opts.skipPreflight = true + const newClient = initMangoClient(newProvider) + + set((state) => { + state.connection = newConnection + state.client = newClient + }) + }, }, } }) From 61216e299f9fa3fc632e1f3779e9ac9128efbccd Mon Sep 17 00:00:00 2001 From: tjs Date: Tue, 27 Dec 2022 14:00:34 -0500 Subject: [PATCH 3/4] fix merge conflict --- utils/constants.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/constants.ts b/utils/constants.ts index 1df2228f..5362f7db 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -34,6 +34,7 @@ export const GRID_LAYOUT_KEY = 'savedLayouts-0.2' export const NOTIFICATION_POSITION_KEY = 'notificationPosition-0.2' export const TRADE_CHART_UI_KEY = 'tradeChart-0.2' + export const FAVORITE_MARKETS_KEY = 'favoriteMarkets-0.2' export const THEME_KEY = 'theme-0.1' @@ -57,8 +58,6 @@ export const DEFAULT_MARKET_NAME = 'SOL/USDC' export const MIN_SOL_BALANCE = 0.04 -export const FAVORITE_MARKETS_KEY = 'favoriteMarkets' - export const RPC_PROVIDER_KEY = 'rpcProviderKey' export const ACCOUNT_ACTION_MODAL_HEIGHT = '478px' From 0bc6593aa3e0a77768fe39bd9ea36709216501e1 Mon Sep 17 00:00:00 2001 From: tjs Date: Tue, 27 Dec 2022 16:13:15 -0500 Subject: [PATCH 4/4] fix rpc custom connection --- components/forms/Input.tsx | 2 +- components/settings/RpcSettings.tsx | 27 ++++----- store/mangoStore.ts | 89 ++++++++--------------------- 3 files changed, 40 insertions(+), 78 deletions(-) diff --git a/components/forms/Input.tsx b/components/forms/Input.tsx index 2a3febd4..7d8b8264 100644 --- a/components/forms/Input.tsx +++ b/components/forms/Input.tsx @@ -41,6 +41,7 @@ const Input = forwardRef((props, ref) => {
) : null} ((props, ref) => { ${suffix ? 'pr-11' : ''}`} disabled={disabled} ref={ref} - {...props} type={type} value={value} onChange={onChange} diff --git a/components/settings/RpcSettings.tsx b/components/settings/RpcSettings.tsx index e3d812ad..31171e0a 100644 --- a/components/settings/RpcSettings.tsx +++ b/components/settings/RpcSettings.tsx @@ -12,11 +12,10 @@ const RPC_URLS = [ label: 'Triton', value: 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5', }, - { - label: 'Syndica', - value: - 'https://solana-api.syndica.io/access-token/4ywEBJNxuwPLXXU9UlMK67fAMZBt1GLdwuXyXSYnoYPn5aXajT8my0R5klXhYRkk/rpc', - }, + // { + // label: 'Genesys Go', + // value: 'https://mango.genesysgo.net', + // }, { label: 'Custom', value: '' }, ] @@ -27,18 +26,19 @@ const RpcSettings = () => { const [showCustomForm, setShowCustomForm] = useState(false) const [rpcEndpointProvider, setRpcEndpointProvider] = useLocalStorageState( RPC_PROVIDER_KEY, + RPC_URLS[0].value + ) + const rpcEndpoint = + RPC_URLS.find((node) => node.label === rpcEndpointProvider.label) || RPC_URLS[0] - ) - const rpcEndpoint = RPC_URLS.find( - (node) => node.label === rpcEndpointProvider.label - ) const handleSetEndpointProvider = (provider: string) => { - const endpointProvider = RPC_URLS.find((node) => node.label === provider) - setRpcEndpointProvider(endpointProvider) + const endpointProvider = + RPC_URLS.find((node) => node.label === provider) || RPC_URLS[0] + setRpcEndpointProvider(endpointProvider.value) if (provider !== 'Custom') { setShowCustomForm(false) - actions.updateConnection(endpointProvider!.value) + actions.updateConnection(endpointProvider.value) } } @@ -63,7 +63,7 @@ const RpcSettings = () => {

{t('rpc-provider')}

handleSetEndpointProvider(v)} values={RPC_URLS.map((val) => val.label)} /> @@ -74,6 +74,7 @@ const RpcSettings = () => { type="text" name="url" id="url" + className="!h-10" placeholder={t('rpc-url')} value={customUrl} onChange={(e: ChangeEvent) => diff --git a/store/mangoStore.ts b/store/mangoStore.ts index 9ce9a93d..41753071 100644 --- a/store/mangoStore.ts +++ b/store/mangoStore.ts @@ -54,42 +54,22 @@ const ENDPOINTS = [ }, { name: 'devnet', - // url: 'https://mango.devnet.rpcpool.com', - // websocket: 'https://mango.devnet.rpcpool.com', - url: 'https://api.devnet.solana.com', - websocket: 'https://api.devnet.solana.com', + url: 'https://mango.devnet.rpcpool.com', + websocket: 'https://mango.devnet.rpcpool.com', custom: false, }, - // { - // name: 'testnet', - // url: 'https://api.testnet.solana.com', - // websocket: 'https://api.testnet.solana.com', - // custom: false, - // }, ] -// export const connection = new web3.Connection( -// process.env.NEXT_PUBLIC_ENDPOINT || -// 'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5', -// 'processed' -// ) const options = AnchorProvider.defaultOptions() export const CLUSTER: 'mainnet-beta' | 'devnet' = 'mainnet-beta' -const ENDPOINT = ENDPOINTS.find((e) => e.name === CLUSTER) -const wallet = new EmptyWallet(Keypair.generate()) -// const DEFAULT_PROVIDER = new AnchorProvider(connection, wallet, options) -// DEFAULT_PROVIDER.opts.skipPreflight = true -// const DEFAULT_CLIENT = MangoClient.connect( -// DEFAULT_PROVIDER, -// CLUSTER, -// MANGO_V4_ID[CLUSTER], -// { -// idsSource: 'get-program-accounts', -// } -// ) +const ENDPOINT = ENDPOINTS.find((e) => e.name === CLUSTER) || ENDPOINTS[0] +const emptyWallet = new EmptyWallet(Keypair.generate()) const initMangoClient = (provider: AnchorProvider): MangoClient => { return MangoClient.connect(provider, CLUSTER, MANGO_V4_ID[CLUSTER], { + // blockhashCommitment: 'confirmed', + idsSource: 'get-program-accounts', + prioritizationFee: 2, postSendTxCallback: ({ txid }: { txid: string }) => { notify({ title: 'Transaction sent', @@ -98,8 +78,6 @@ const initMangoClient = (provider: AnchorProvider): MangoClient => { txid: txid, }) }, - // blockhashCommitment: 'confirmed', - idsSource: 'get-program-accounts', }) } @@ -340,7 +318,6 @@ export type MangoStore = { fetchTourSettings: (walletPk: string) => void fetchWalletTokens: (wallet: Wallet) => Promise connectMangoClientWithWallet: (wallet: WalletAdapter) => Promise - reloadGroup: () => Promise loadMarketFills: () => Promise updateConnection: (url: string) => void } @@ -349,6 +326,7 @@ export type MangoStore = { const mangoStore = create()( subscribeWithSelector((_set, get) => { let rpcUrl = ENDPOINT?.url + if (typeof window !== 'undefined' && CLUSTER === 'mainnet-beta') { const urlFromLocalStorage = localStorage.getItem(RPC_PROVIDER_KEY) rpcUrl = urlFromLocalStorage @@ -356,10 +334,11 @@ const mangoStore = create()( : ENDPOINT?.url } - const connection = new web3.Connection(rpcUrl!, 'processed') - const provider = new AnchorProvider(connection, wallet, options) + const connection = new web3.Connection(rpcUrl, 'processed') + const provider = new AnchorProvider(connection, emptyWallet, options) provider.opts.skipPreflight = true const client = initMangoClient(provider) + return { activityFeed: { feed: [], @@ -587,6 +566,11 @@ const mangoStore = create()( try { const set = get().set const client = get().client + console.log( + 'fetching group', + client.program.provider.connection.rpcEndpoint + ) + const group = await client.getGroup(GROUP) const selectedMarketName = get().selectedMarket.name @@ -883,23 +867,8 @@ const mangoStore = create()( options ) provider.opts.skipPreflight = true - const client = await MangoClient.connect( - provider, - CLUSTER, - MANGO_V4_ID[CLUSTER], - { - idsSource: 'get-program-accounts', - prioritizationFee: 2, - postSendTxCallback: ({ txid }: { txid: string }) => { - notify({ - title: 'Transaction sent', - description: 'Waiting for confirmation', - type: 'confirm', - txid: txid, - }) - }, - } - ) + const client = initMangoClient(provider) + set((s) => { s.client = client }) @@ -913,19 +882,6 @@ const mangoStore = create()( } } }, - reloadGroup: async () => { - try { - const set = get().set - const client = get().client - const group = await client.getGroup(GROUP) - - set((state) => { - state.group = group - }) - } catch (e) { - console.error('Error fetching group', e) - } - }, async fetchProfileDetails(walletPk: string) { const set = get().set set((state) => { @@ -1005,9 +961,14 @@ const mangoStore = create()( }, updateConnection(endpointUrl) { const set = get().set + const client = mangoStore.getState().client const newConnection = new web3.Connection(endpointUrl, 'processed') - - const newProvider = new AnchorProvider(connection, wallet, options) + const oldProvider = client.program.provider as AnchorProvider + const newProvider = new AnchorProvider( + newConnection, + oldProvider.wallet, + options + ) newProvider.opts.skipPreflight = true const newClient = initMangoClient(newProvider)