From 487e22e58ab70a6c37565e283bb23efe6f20eae5 Mon Sep 17 00:00:00 2001 From: Victor Creed Date: Mon, 14 Dec 2020 19:13:26 +0200 Subject: [PATCH 1/5] block checking --- src/app/containers/WalletProvider/saga.ts | 15 +++++++-------- src/app/containers/WalletProvider/slice.ts | 4 +++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/app/containers/WalletProvider/saga.ts b/src/app/containers/WalletProvider/saga.ts index 2e5c3086d..4f3c6bf3b 100644 --- a/src/app/containers/WalletProvider/saga.ts +++ b/src/app/containers/WalletProvider/saga.ts @@ -84,6 +84,8 @@ function* processBlockHeader(event) { function* processBlock({ block, address }) { try { const transactionStack = yield select(selectTransactionStack); + const localTransactions = transactionStack.map(e => e.toLowerCase()); + const user = address.toLowerCase(); if (!block) { console.log('no block?'); @@ -97,9 +99,9 @@ function* processBlock({ block, address }) { for (let i = 0; i < txs.length; i++) { const from = (txs[i].from || '').toLowerCase(); const to = (txs[i].to || '').toLowerCase(); - const hash: string = txs[i].hash || ''; + const hash: string = (txs[i].hash || '').toLowerCase(); - if (transactionStack.includes(hash) && from === address.toLowerCase()) { + if (localTransactions.includes(hash) || from === user || to === user) { const receipt: TransactionReceipt = yield call( [Sovryn, Sovryn.getWeb3().eth.getTransactionReceipt], hash, @@ -116,18 +118,15 @@ function* processBlock({ block, address }) { } const hasContract = Sovryn.contractList.find(contract => { - const address = contract.options.address.toLowerCase(); - return address === from || address === to; + const contractAddress = contract.options.address.toLowerCase(); + return contractAddress === from || contractAddress === to; }); if (hasContract) { hasChanges = true; } - if ( - address && - (address.toLowerCase() === from || address.toLowerCase() === from) - ) { + if (user && (user === from || user === from)) { hasChanges = true; } } diff --git a/src/app/containers/WalletProvider/slice.ts b/src/app/containers/WalletProvider/slice.ts index 3a2ec9785..8b224ad91 100644 --- a/src/app/containers/WalletProvider/slice.ts +++ b/src/app/containers/WalletProvider/slice.ts @@ -81,7 +81,9 @@ const walletProviderSlice = createSlice({ console.error('block failed'); }, blockReceived(state, action: PayloadAction) { - state.blockNumber = action.payload.number; + if (action.payload.number < state.blockNumber) { + state.blockNumber = action.payload.number; + } }, processBlock(state, action: PayloadAction) {}, From d393c9412a8f77c55532c620a0fbcdc97913e5b8 Mon Sep 17 00:00:00 2001 From: Victor Creed Date: Tue, 15 Dec 2020 09:28:34 +0200 Subject: [PATCH 2/5] block processing improvements --- src/app/containers/WalletProvider/saga.ts | 19 ++++++++++++++----- src/app/containers/WalletProvider/slice.ts | 14 +++++++++++--- src/app/containers/WalletProvider/types.ts | 1 + src/app/hooks/useGetContractPastEvents.ts | 4 ++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/app/containers/WalletProvider/saga.ts b/src/app/containers/WalletProvider/saga.ts index 4f3c6bf3b..1db9f978c 100644 --- a/src/app/containers/WalletProvider/saga.ts +++ b/src/app/containers/WalletProvider/saga.ts @@ -66,18 +66,24 @@ function* callCreateBlockChannels() { } function* processBlockHeader(event) { - const { address } = yield select(selectWalletProvider); + const { address, processedBlocks } = yield select(selectWalletProvider); const blockNumber = event.payload.number; const web3 = Sovryn.getWeb3(); try { - const block = yield call(web3.eth.getBlock, blockNumber, true); - yield call(processBlock, { block, address }); + const previousBlocks = Array(5) + .fill(blockNumber) + .map((number, index) => number - index); + const blocksToProcess = previousBlocks + .filter(x => !processedBlocks.includes(x)) + .reverse(); + for (const number of blocksToProcess) { + const block = yield call(web3.eth.getBlock, number, true); + yield call(processBlock, { block, address }); + } } catch (error) { console.error('Error in block processing:'); console.error(error); - - // yield put({ type: 'BLOCK_FAILED', error }); } } @@ -87,6 +93,8 @@ function* processBlock({ block, address }) { const localTransactions = transactionStack.map(e => e.toLowerCase()); const user = address.toLowerCase(); + console.log('block', block.number, address); + if (!block) { console.log('no block?'); return; @@ -132,6 +140,7 @@ function* processBlock({ block, address }) { } } + yield put(actions.blockProcessed(block.number)); if (hasChanges) { yield put(actions.reSync(block.number)); } diff --git a/src/app/containers/WalletProvider/slice.ts b/src/app/containers/WalletProvider/slice.ts index 8b224ad91..a1653bfcb 100644 --- a/src/app/containers/WalletProvider/slice.ts +++ b/src/app/containers/WalletProvider/slice.ts @@ -25,6 +25,7 @@ export const initialState: ContainerState = { isDialogOpen: false, }, assetRates: [], + processedBlocks: [], }; const walletProviderSlice = createSlice({ @@ -72,7 +73,9 @@ const walletProviderSlice = createSlice({ }, reSync(state, action: PayloadAction) { - state.syncBlockNumber = action.payload; + if (action.payload > state.syncBlockNumber) { + state.syncBlockNumber = action.payload; + } }, readerReady() {}, @@ -81,13 +84,18 @@ const walletProviderSlice = createSlice({ console.error('block failed'); }, blockReceived(state, action: PayloadAction) { - if (action.payload.number < state.blockNumber) { + if (action.payload.number > state.blockNumber) { state.blockNumber = action.payload.number; } }, processBlock(state, action: PayloadAction) {}, - + blockProcessed(state, { payload }: PayloadAction) { + if (state.processedBlocks.length > 30) { + state.processedBlocks.shift(); + } + state.processedBlocks.push(payload); + }, whitelistCheck(state) { state.whitelist.loading = true; state.whitelist.loaded = false; diff --git a/src/app/containers/WalletProvider/types.ts b/src/app/containers/WalletProvider/types.ts index fd2f5f0b4..fd3bf4a2b 100644 --- a/src/app/containers/WalletProvider/types.ts +++ b/src/app/containers/WalletProvider/types.ts @@ -14,6 +14,7 @@ export interface WalletProviderState { transactions: any; transactionStack: string[]; assetRates: CachedAssetRate[]; + processedBlocks: number[]; // whitelisting whitelist: IWhitelist; } diff --git a/src/app/hooks/useGetContractPastEvents.ts b/src/app/hooks/useGetContractPastEvents.ts index fa36cef43..13818aca0 100644 --- a/src/app/hooks/useGetContractPastEvents.ts +++ b/src/app/hooks/useGetContractPastEvents.ts @@ -26,7 +26,7 @@ export function useGetContractPastEvents( const getEvents = useCallback(async () => { const fromBlock = getContract(contractName).blockNumber; - const toBlock = syncBlockNumber || 'latest'; + const toBlock = 'latest'; return eventReader.getPastEvents( contractName, event, @@ -36,7 +36,7 @@ export function useGetContractPastEvents( toBlock, }, ); - }, [address, contractName, event, filters, syncBlockNumber]); + }, [address, contractName, event, filters]); useEffect(() => { if (!address) { From 7a0e70c762f7f2dd4054b1f4ce424a2af56bc43e Mon Sep 17 00:00:00 2001 From: Victor Creed Date: Tue, 15 Dec 2020 09:31:09 +0200 Subject: [PATCH 3/5] block processing improvements --- src/app/containers/WalletProvider/saga.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/containers/WalletProvider/saga.ts b/src/app/containers/WalletProvider/saga.ts index 1db9f978c..310820fd0 100644 --- a/src/app/containers/WalletProvider/saga.ts +++ b/src/app/containers/WalletProvider/saga.ts @@ -93,8 +93,6 @@ function* processBlock({ block, address }) { const localTransactions = transactionStack.map(e => e.toLowerCase()); const user = address.toLowerCase(); - console.log('block', block.number, address); - if (!block) { console.log('no block?'); return; From 6116fd361601c5417766df5ed711215c6e5bbc62 Mon Sep 17 00:00:00 2001 From: Victor Creed Date: Tue, 15 Dec 2020 11:50:51 +0200 Subject: [PATCH 4/5] removing whitelisting --- .env.production | 2 +- src/utils/sovryn/sovryn-network.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.env.production b/.env.production index 7823a2406..0d3dd310f 100644 --- a/.env.production +++ b/.env.production @@ -5,7 +5,7 @@ REACT_APP_SENTRY_DSN=https://2981633dd7f04f0d9fb3facf8c1332b8@o459269.ingest.sen REACT_APP_PORTIS_ID=469a25c8-1101-4c57-823d-c47cb328f788 -REACT_APP_WHITELIST=true +REACT_APP_WHITELIST=false REACT_APP_WHITELIST_TOKEN=0x576aE218aeCfD4CbD2DBe07250b47e26060932B1 REACT_APP_YBUG_ID=3f1jrxvzrhkn1b975t8b diff --git a/src/utils/sovryn/sovryn-network.ts b/src/utils/sovryn/sovryn-network.ts index 8d69106a3..049408175 100644 --- a/src/utils/sovryn/sovryn-network.ts +++ b/src/utils/sovryn/sovryn-network.ts @@ -308,13 +308,13 @@ export class SovrynNetwork { provider.on('accountsChanged', async (accounts: string[]) => { this.store().dispatch(actions.accountChanged(accounts[0])); }); - provider.on('chainChanged', async (chainId: number) => { + provider.on('chainChanged', async (chain: string) => { + const chainId = parseInt(chain); const networkId = await this._writeWeb3.eth.net.getId(); await this.testChain(chainId); await this.initReadWeb3(chainId); this.store().dispatch(actions.chainChanged({ chainId, networkId })); }); - provider.on('networkChanged', async (networkId: number) => { const chainId = await (this._writeWeb3.eth as any).chainId(); await this.testChain(chainId); From c581135aa0ad2b990f2cca7931f51df2f1a312bd Mon Sep 17 00:00:00 2001 From: Victor Creed Date: Tue, 15 Dec 2020 12:08:55 +0200 Subject: [PATCH 5/5] notification about lifted limits --- src/app/components/Header/index.tsx | 2 ++ .../LimitsNotification/Loadable.tsx | 12 ++++++++ .../components/LimitsNotification/index.tsx | 30 +++++++++++++++++++ src/locales/en/translation.json | 3 ++ 4 files changed, 47 insertions(+) create mode 100644 src/app/components/LimitsNotification/Loadable.tsx create mode 100644 src/app/components/LimitsNotification/index.tsx diff --git a/src/app/components/Header/index.tsx b/src/app/components/Header/index.tsx index 772d60d56..85486e387 100644 --- a/src/app/components/Header/index.tsx +++ b/src/app/components/Header/index.tsx @@ -16,6 +16,7 @@ import { media } from '../../../styles/media'; import { WhitelistedNotification } from '../WhitelistedNotification/Loadable'; import { translations } from 'locales/i18n'; import { actions } from 'app/containers/FastBtcForm/slice'; +import { LimitsNotification } from '../LimitsNotification/Loadable'; export function Header() { const { t } = useTranslation(); @@ -108,6 +109,7 @@ export function Header() { + ); } diff --git a/src/app/components/LimitsNotification/Loadable.tsx b/src/app/components/LimitsNotification/Loadable.tsx new file mode 100644 index 000000000..cb007c4be --- /dev/null +++ b/src/app/components/LimitsNotification/Loadable.tsx @@ -0,0 +1,12 @@ +/** + * + * Asynchronously loads the component for LimitsNotification + * + */ + +import { lazyLoad } from 'utils/loadable'; + +export const LimitsNotification = lazyLoad( + () => import('./index'), + module => module.LimitsNotification, +); diff --git a/src/app/components/LimitsNotification/index.tsx b/src/app/components/LimitsNotification/index.tsx new file mode 100644 index 000000000..caa453337 --- /dev/null +++ b/src/app/components/LimitsNotification/index.tsx @@ -0,0 +1,30 @@ +/** + * + * LimitsNotification + * + */ +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { Icon } from '@blueprintjs/core/lib/esm/components/icon/icon'; +import { translations } from '../../../locales/i18n'; +import { currentNetwork } from '../../../utils/classifiers'; + +interface Props {} + +export function LimitsNotification(props: Props) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { t, i18n } = useTranslation(); + + if (currentNetwork !== 'mainnet') return <>; + + return ( +
+
+
+ +
+
{t(translations.limitsNotification.text)}
+
+
+ ); +} diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index c89b4cf58..d84a54a68 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -217,6 +217,9 @@ "whiteListedNotification": { "text": "Currently Sovryn is available for invited users only and your wallet is not yet whitelisted. All interactions is disabled until you switch to whitelisted wallet or get whitelisted for current one." }, + "limitsNotification": { + "text": "Sovryn has just lifted transaction limits (hooray!). This means you can now take any position size. Please be aware, however, since the limits were only just removed, liquidity in the system may be low initially." + }, "lend": { "history": { "title": "Lending history"