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