Fix websocket account subscriptions, update markets list
This commit is contained in:
parent
4ab8710ab9
commit
e1487330cb
|
@ -1,6 +1,6 @@
|
|||
import { useLocalStorageState } from './utils';
|
||||
import { clusterApiUrl, Connection } from '@solana/web3.js';
|
||||
import React, { useContext, useMemo, useEffect } from 'react';
|
||||
import { Account, clusterApiUrl, Connection } from '@solana/web3.js';
|
||||
import React, { useContext, useEffect, useMemo } from 'react';
|
||||
import { setCache, useAsyncData } from './fetch-loop';
|
||||
import tuple from 'immutable-tuple';
|
||||
|
||||
|
@ -34,30 +34,10 @@ export function ConnectionProvider({ children }) {
|
|||
// The websocket library solana/web3.js uses closes its websocket connection when the subscription list
|
||||
// is empty after opening its first time, preventing subsequent subscriptions from receiving responses.
|
||||
// This is a hack to prevent the list from every getting empty
|
||||
// useEffect(() => {
|
||||
// const id = connection.onSignature(
|
||||
// 'do not worry, this is expected to yield warning logs',
|
||||
// (result) => {
|
||||
// console.log(
|
||||
// 'Received onSignature responses from does-not-exist',
|
||||
// result,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// return () => connection.removeSignatureListener(id);
|
||||
// }, [connection]);
|
||||
// useEffect(() => {
|
||||
// const id = sendConnection.onSignature(
|
||||
// 'do not worry, this is expected to yield warning logs',
|
||||
// (result) => {
|
||||
// console.log(
|
||||
// 'Received onSignature responses from does-not-exist',
|
||||
// result,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// return () => sendConnection.removeSignatureListener(id);
|
||||
// }, [sendConnection]);
|
||||
useEffect(() => {
|
||||
const id = connection.onAccountChange(new Account().publicKey, () => {});
|
||||
return () => connection.removeAccountChangeListener(id);
|
||||
}, [connection]);
|
||||
|
||||
return (
|
||||
<ConnectionContext.Provider
|
||||
|
@ -87,7 +67,7 @@ export function useAccountInfo(publicKey) {
|
|||
const [accountInfo, loaded] = useAsyncData(
|
||||
async () => (publicKey ? connection.getAccountInfo(publicKey) : null),
|
||||
cacheKey,
|
||||
{ refreshInterval: 60000000 },
|
||||
{ refreshInterval: 60_000 },
|
||||
);
|
||||
let id = publicKey?.toBase58();
|
||||
useEffect(() => {
|
||||
|
@ -97,10 +77,7 @@ export function useAccountInfo(publicKey) {
|
|||
if (accountListenerCount.has(cacheKey)) {
|
||||
let currentItem = accountListenerCount.get(cacheKey);
|
||||
console.log('Incrementing', id, currentItem.count + 1);
|
||||
accountListenerCount.set(cacheKey, {
|
||||
count: currentItem.count + 1,
|
||||
subscriptionId: currentItem.subscriptionId,
|
||||
});
|
||||
++currentItem.count;
|
||||
} else {
|
||||
let previousData = null;
|
||||
console.log('Subscribing to ', id);
|
||||
|
@ -127,10 +104,7 @@ export function useAccountInfo(publicKey) {
|
|||
accountListenerCount.delete(cacheKey);
|
||||
} else {
|
||||
console.log('Decrementing', id, nextCount);
|
||||
accountListenerCount.set(cacheKey, {
|
||||
count: nextCount,
|
||||
subscriptionId: currentItem.subscriptionId,
|
||||
});
|
||||
--currentItem.count;
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
|
|
@ -29,62 +29,62 @@ export const COIN_MINTS = {
|
|||
};
|
||||
|
||||
export const MARKET_INFO_BY_NAME = {
|
||||
'MSRM/USDC': {
|
||||
address: '7kgkDyW7dmyMeP8KFXzbcUZz1R2WHsovDZ7n3ihZuNDS',
|
||||
name: 'MSRM/USDC',
|
||||
},
|
||||
'MSRM/USDT': {
|
||||
address: 'H4snTKK9adiU15gP22ErfZYtro3aqR9BTMXiH3AwiUTQ',
|
||||
name: 'MSRM/USDT',
|
||||
},
|
||||
'BTC/USDC': {
|
||||
address: 'CAgAeMD7quTdnr6RPa7JySQpjf3irAmefYNdTb6anemq',
|
||||
name: 'BTC/USDC',
|
||||
'MSRM/USDC': {
|
||||
address: '7kgkDyW7dmyMeP8KFXzbcUZz1R2WHsovDZ7n3ihZuNDS',
|
||||
name: 'MSRM/USDC',
|
||||
},
|
||||
'BTC/USDT': {
|
||||
address: '8AcVjMG2LTbpkjNoyq8RwysokqZunkjy3d5JDzxC6BJa',
|
||||
name: 'BTC/USDT',
|
||||
},
|
||||
'ETH/USDC': {
|
||||
address: 'ASKiV944nKg1W9vsf7hf3fTsjawK6DwLwrnB2LH9n61c',
|
||||
name: 'ETH/USDC',
|
||||
'BTC/USDC': {
|
||||
address: 'CAgAeMD7quTdnr6RPa7JySQpjf3irAmefYNdTb6anemq',
|
||||
name: 'BTC/USDC',
|
||||
},
|
||||
'ETH/USDT': {
|
||||
address: 'HfCZdJ1wfsWKfYP2qyWdXTT5PWAGWFctzFjLH48U1Hsd',
|
||||
name: 'ETH/USDT',
|
||||
},
|
||||
'SRM/USDC': {
|
||||
address: '68J6nkWToik6oM9rTatKSR5ibVSykAtzftBUEAvpRsys',
|
||||
name: 'SRM/USDC',
|
||||
'ETH/USDC': {
|
||||
address: 'ASKiV944nKg1W9vsf7hf3fTsjawK6DwLwrnB2LH9n61c',
|
||||
name: 'ETH/USDC',
|
||||
},
|
||||
'SRM/USDT': {
|
||||
address: 'HARFLhSq8nECZk4DVFKvzqXMNMA9a3hjvridGMFizeLa',
|
||||
name: 'SRM/USDT',
|
||||
},
|
||||
'FTT/USDC': {
|
||||
address: 'FZqrBXz7ADGsmDf1TM9YgysPUfvtG8rJiNUrqDpHc9Au',
|
||||
name: 'FTT/USDC',
|
||||
'SRM/USDC': {
|
||||
address: '68J6nkWToik6oM9rTatKSR5ibVSykAtzftBUEAvpRsys',
|
||||
name: 'SRM/USDC',
|
||||
},
|
||||
'FTT/USDT': {
|
||||
address: 'DHDdghmkBhEpReno3tbzBPtsxCt6P3KrMzZvxavTktJt',
|
||||
name: 'FTT/USDT',
|
||||
},
|
||||
'YFI/USDC': {
|
||||
address: 'FJg9FUtbN3fg3YFbMCFiZKjGh5Bn4gtzxZmtxFzmz9kT',
|
||||
name: 'YFI/USDC',
|
||||
'FTT/USDC': {
|
||||
address: 'FZqrBXz7ADGsmDf1TM9YgysPUfvtG8rJiNUrqDpHc9Au',
|
||||
name: 'FTT/USDC',
|
||||
},
|
||||
'YFI/USDT': {
|
||||
address: '5zu5bTZZvqESAAgFsr12CUMxdQvMrvU9CgvC1GW8vJdf',
|
||||
name: 'YFI/USDT',
|
||||
},
|
||||
'LINK/USDC': {
|
||||
address: '7GZ59DMgJ7D6dfoJTpszPayTRyua9jwcaGJXaRMMF1my',
|
||||
name: 'LINK/USDC',
|
||||
'YFI/USDC': {
|
||||
address: 'FJg9FUtbN3fg3YFbMCFiZKjGh5Bn4gtzxZmtxFzmz9kT',
|
||||
name: 'YFI/USDC',
|
||||
},
|
||||
'LINK/USDT': {
|
||||
address: 'F5xschQBMpu1gD2q1babYEAVJHR1buj1YazLiXyQNqSW',
|
||||
name: 'LINK/USDT',
|
||||
},
|
||||
'LINK/USDC': {
|
||||
address: '7GZ59DMgJ7D6dfoJTpszPayTRyua9jwcaGJXaRMMF1my',
|
||||
name: 'LINK/USDC',
|
||||
},
|
||||
};
|
||||
|
||||
export function useMarketsList() {
|
||||
|
|
|
@ -145,8 +145,8 @@ export async function placeOrder({
|
|||
market?.tickSize?.toFixed(getDecimalCount(market.tickSize)) ||
|
||||
market?.tickSize;
|
||||
const isIncrement = (num, step) =>
|
||||
Math.abs((num / step) % 1) < 1e-10 ||
|
||||
Math.abs(((num / step) % 1) - 1) < 1e-10;
|
||||
Math.abs((num / step) % 1) < 1e-5 ||
|
||||
Math.abs(((num / step) % 1) - 1) < 1e-5;
|
||||
if (isNaN(price)) {
|
||||
notify({ message: 'Invalid price', type: 'error' });
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue