From e1487330cb3c60dd12a798d2754eda4fecbd5c8d Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sun, 30 Aug 2020 10:12:57 -0700 Subject: [PATCH] Fix websocket account subscriptions, update markets list --- src/utils/connection.js | 44 +++++++++-------------------------------- src/utils/markets.js | 44 ++++++++++++++++++++--------------------- src/utils/send.js | 4 ++-- 3 files changed, 33 insertions(+), 59 deletions(-) diff --git a/src/utils/connection.js b/src/utils/connection.js index 5291fc7..d1c6798 100644 --- a/src/utils/connection.js +++ b/src/utils/connection.js @@ -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 ( (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 diff --git a/src/utils/markets.js b/src/utils/markets.js index 1a6e6e5..2bcc80f 100644 --- a/src/utils/markets.js +++ b/src/utils/markets.js @@ -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() { diff --git a/src/utils/send.js b/src/utils/send.js index 31127c5..d730bd4 100644 --- a/src/utils/send.js +++ b/src/utils/send.js @@ -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;