Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
fix: graph timeframe updates after website idle (#182)
Browse files Browse the repository at this point in the history
* Update yarn.lock

* #41 | WIP resolver tests

* feat: add wait-for-expect testing library

* feat: remove unnecessary propertiy in gql schema

* feat: add mocked polkadotJsContext for testing purposes

* feat: update getBalancesByAddress implementation

* feat: update gql schema

* #41 | move render function to fix ESlint validation

* refactor: mockApiPromise and mockUsePolkadotJsContext

* test: add fail cases

* feat: upgrade type def for polkadot/api v7

* #41 accounts resolver mock

* #41 | clear VestingSchedule from account schema

* #41 | selectedAccount => activeAccount

* #41 | remove duplicated line

* #41 | PR comment fixes

* #41 | PR comment fixes

* #41 | addressing PR review - refactored onAccountSelected handling

* #41 | PR issue fix - use classNames FTW

* #41 | PR comment fix - account is always populated

* #41 | TODO comment

* #41 | basic react-intl setup

* #41 | Formatted messages for links

* #41 | handle and propagate getAllAccounts loading state

* #41 | moving files along to match desired dir structures

* #41 | moving files along to match desired dir structures

* #41 | further dir structure shaking and cleanup

* #41 | accounts dir structure refactoring finished

* #41 | Todo

* #41 | add source field to Account GQL type

* #41 | test update

* #41 | add transformIgnorePatterns for polkadot to jest.config.js file

* #41 | getAccounts lib function and tests

* #41 | cleanup

* #41 | cleanup

* #41 | getAccounts refactoring

* #41 | getAccounts tests finished

* #41 | use waitForExpect

* #41 | accounts resolver tests

* #41 | pass ss58Format as an option to avoid manual address encoding

* #41 | tests structured formatting

* #41 | fix test description

* #41 | shared withTypename helper

* #41 | propper return type

* #41 | extract callback to separate function

* test: refactor getAccounts

* #41 | basilisk ui app provider name  moved to constants

* #41 | update mocked web3Enable response format

* #41 | update padding to result in whole px value

* #41 | use skip instead of lazy query to avoid manual effects

* #41 | post merge fixes

* Create .nvmrc

* #41 | post install yarn.lock update

* #41 | fix storybook test snapshots

* #41 | remove tests for deprecated component

* #41 | Icon component refactoring

* #41 | translations

* Really remove husky:

* account-selector redesign

* Updates to tradeform

* fixes to AssetBalanceInput + stories

* Added default asset out bsx

* remove trade chart

* cleanup trade form

* working towards trade info

* reverse spot price

* spot price display

* submit trade

* complete wallet

* fix wallet

* start balance input

* fix balance fetching for accounts

* Added last block fetching and trade info

* added spot price display to trade form

* mumbo jumbo with spot price

* debugging last block

* update polkadot dependencies, fix trade limit calc

* change event listener for trade type changing

* feat: subscription for last block

* added historical dataset with latest data composition, added asset switcher

* fix asset balance input + metric unit selector

* page layout

* fix ci?

* Update styles

* some chart fixes

* small story fix

* remove an unwanted dot

* chart-style

* correct loading statuses for accounts & pool by ids

* Revive trade chart

* reset dataset on asset id change

* fix loading status for wallet & trade form

* responsive something

* better flex

* polish

* more swag

* fix overlay

* hide trade form settings instead of comment out

* added pool asset list

* disable lbp pool fetching

* fix styles

* add placeholder

* xyk trade status handling

* extract trade settings as portal

* add updating of query params

* fix trade settings form submit

* settings

* button n info

* limit graph bounds

* icons~WIP

* icons something

* asset styling + longname

* swag, actually fix chart jail and rendering, disable tooltip logs

* style fixes

* trade balances before/after/%

* fix unique assets for asset selector

* no default values for calculated amount counterparts

* graph fix

* linechart x axis scale

* Trade info style

* moar space

* asset selector

* fix decimal input in BalanceInput

* USDC metadata

* use formattedbalance in chart & form

* fix straight graph

* fix clickable area for unit selector

* trade chart precision fix

* switchfix

* header fix

* trade form tweaks

* jumpy

* footer liveliness and spot price in graph fix

* colors for footer

* bring back notifs

* notifs v1

* spinner

* settings

* trade info errors

* swag

* Uupdate E2E testing workflow

* Update polkadot-dapp

* Unlock e2e tests

* warning styling

* more swag for trade info

* trade paddings

* new test for trade page

* clean console logs and remove graceful error handler from xyk.sell

* center modal close button

* add sha version to footer

* remove unit if value is 0

* switch to short sha version

* fix footer sha display

* short git hash version

* minor fixes

* spicy validations

* add small fix for calculated amounts

* Error styling

* trade balance fixes

* loading status fixes

* eerrrrs

* added faucete mutation + fixed % trade balance change

* add faucetg

* remove loader from faucet

* fix error timing

* fix alignment in tradeinfo

* fix % trade balances

* units and balance input remove trailing zeroes

* Adjust unit balance recalculation in inputs

* timeout hack for tradeinfo errors

* switch you get / pay with

* fix switching of in/out in form

* add help

* Fix graph loading status

* Fix chart loading text, fix block num loading status

* fix asset ordering

* Simplify wallet button logic (show connect account)

* Added debug box"

* fix debug box false

* debug stuff

* Moveup active account validation, move debugbox closer to root

* add pretty json view to debug box

* debug box details for trade form

* fix rerender of debug box

* debug box features

* Fix trade balances loading state

* Tweak trade balances display for none/some account connected + none/some amount input value

* Add extension availability pseudo-polling

* remove secondary account item address

* unify account address triming between mini wallet and account list item

* tweaks to account list / item

* Add horizontal bar when no asset is selected for unit selector

* Filter of trade form assets

* Added payment info estimation for xyk sell

* add multiple empty states with horizontal bar

* Added tooltip to formatted balance

* show spotprice in the tradeform as formattede balance

* update URLs for new testnet

* tokens

* styling error fix + hide faucet

* wallet genesis hash handling

* fix unnecessary display of trade balance change

* Align wallet correctly

* shorter tooltip delay

* adjust extension detection timeout

* revalidate when allowed slippage changes

* Add calculating of usable balance for the native asset + sufficient fee balance validation (#141)

* Add calculating of usable balance for the native asset

* Added fee balance validation to trade form

* Added handling of usable balances for tokens, fixed sub-zero balances for native asset

* added minor schema improvements to work with apollo vscode extension (#152)

* Feat/usable balance + notEnoughFeeBalance (#151)

* Add calculating of usable balance for the native asset

* Added fee balance validation to trade form

* feat: fetch all balances (multi) (#166)

* refactor: remove underline for used variables

* refactor: rm mockUsePolkadotJsContext;improve fn() mocking

* test: update balances test

* feat: update hook and error handler for balance resolver

* feat: fetch non-native token balances without any assetId

* feat: Add reporter workflow to issue comment (#117)

* Add reporter workflow to issue comment

* Fix github-script params

* Fix reporter env vars

* docs: update CI docs

* docs: fix image in CI docs

* refactor: refactor workflows titles and lables

* Fix permission issue in script

* refactor: Decorate steps names

* refactor: Add comment into workflows

* refactor: Remove redundant files

* refactor: rename workflow

* refactor: Rename job name

* Refactor github scripts

* docs: Update comments and docs in workflows

* docs: Update Ci docs

* Refactor steps params order

* docs: Fix image in CI docs

* dosc: Add comment into ggithub actions

* docs: Update ci docs

* docs: Improve CI docs

* refactor: rename wf files, update wf comments

* docs: Fix wf comments typos

* docs: Refactor CI docs

* Fix input name (#165)

Co-authored-by: Max Kravchuk <[email protected]>
Co-authored-by: Istvan <[email protected]>

* feat: fetch all balances (#168)

* feat: fetch all balances if no resolver args are provided

* test: rm only

* feat: claimable vesting amount (#169)

* feat: claimable amount for vesting schedule

* feat: return multiple vesting schedules and extract claim cal

* feat: add balance transfer mutation (#170)

* small build fixes

* feat: add function to fetch locked balances for given lockId (#94)

* feat: add function to fetch locked balance of native token

* feat: add fetching of locked balances

* feat: add lockedBalancesQueryResolver

* feat: add address parameter to locked balance fetching

* feat: Add reporter workflow to issue comment (#117)

* Add reporter workflow to issue comment

* Fix github-script params

* Fix reporter env vars

* docs: update CI docs

* docs: fix image in CI docs

* refactor: refactor workflows titles and lables

* Fix permission issue in script

* refactor: Decorate steps names

* refactor: Add comment into workflows

* refactor: Remove redundant files

* refactor: rename workflow

* refactor: Rename job name

* Refactor github scripts

* docs: Update comments and docs in workflows

* docs: Update Ci docs

* Refactor steps params order

* docs: Fix image in CI docs

* dosc: Add comment into ggithub actions

* docs: Update ci docs

* docs: Improve CI docs

* refactor: rename wf files, update wf comments

* docs: Fix wf comments typos

* docs: Refactor CI docs

* Fix input name (#165)

* feat: use generated resolver args for lockedBalance

* test: refactor

Co-authored-by: Max Kravchuk <[email protected]>
Co-authored-by: Istvan <[email protected]>

* refactor: resolve merge conflict

* feat: error handling for locked balance (#175)

* feat: Fix initial installation (#176)

* feat: fetch available non native balance, correct tests

* fix: graph timeframe updates after website idle

* fix: use lodash and add guard clause for refreshing

* forgotten merge conflicts

Co-authored-by: Václav Slavík <[email protected]>
Co-authored-by: dexterslabor <[email protected]>
Co-authored-by: Istvan <[email protected]>
Co-authored-by: Matej Sima <[email protected]>
Co-authored-by: Jakub Panik <[email protected]>
Co-authored-by: Jakub Panik <[email protected]>
Co-authored-by: Jakub Panik <[email protected]>
Co-authored-by: mckrava <[email protected]>
Co-authored-by: Jakub Vitek <[email protected]>
Co-authored-by: Ayoub Fakir <[email protected]>
Co-authored-by: Matej Šima <[email protected]>
  • Loading branch information
12 people authored Apr 26, 2022
1 parent b9bd747 commit caefc1c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"react-intl": "^5.20.12",
"react-json-view": "^1.21.3",
"react-multi-provider": "^0.1.5",
"react-page-visibility": "^6.4.0",
"react-router-dom": "^6.0.2",
"react-scripts": "5.0.0",
"react-text-mask": "^5.4.3",
Expand Down Expand Up @@ -209,6 +210,7 @@
"@storybook/react": "^6.3.11",
"@testing-library/react-hooks": "^7.0.2",
"@types/lodash": "^4.14.177",
"@types/react-page-visibility": "^6.4.1",
"babel-plugin-formatjs": "^10.3.9",
"bignumber.js": "^9.0.1",
"chai": "^4.3.4",
Expand Down
64 changes: 57 additions & 7 deletions src/pages/TradePage/TradePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NetworkStatus, useApolloClient } from '@apollo/client';
import classNames from 'classnames';
import { find, uniq } from 'lodash';
import { find, uniq, last } from 'lodash';
import moment from 'moment';
import { usePageVisibility } from 'react-page-visibility';
import {
Dispatch,
SetStateAction,
Expand Down Expand Up @@ -95,14 +96,18 @@ export const TradeChart = ({
spotPrice,
isPoolLoading,
}: TradeChartProps) => {
const isVisible = usePageVisibility();
const [historicalBalancesRange, setHistoricalBalancesRange] = useState({
from: moment().subtract(1, 'days').toISOString(),
to: moment().toISOString(),
});
const { math } = useMath();
const {
data: historicalBalancesData,
networkStatus: historicalBalancesNetworkStatus,
} = useGetHistoricalBalancesQuery(
{
from: useMemo(() => moment().subtract(1, 'days').toISOString(), []),
to: useMemo(() => moment().toISOString(), []),
...historicalBalancesRange,
quantity: 100,
// defaulting to an empty string like this is bad, if we want to use skip we should type the variables differently
poolId: pool?.id || '',
Expand All @@ -121,6 +126,7 @@ export const TradeChart = ({

const [dataset, setDataset] = useState<Array<any>>();
const [datasetLoading, setDatasetLoading] = useState(true);
const [datasetRefreshing, setDatasetRefreshing] = useState(false);

const assetOutLiquidity = useMemo(() => {
const assetId = assetIds.assetOut || undefined;
Expand Down Expand Up @@ -196,6 +202,7 @@ export const TradeChart = ({
});

setDataset(dataset);
setDatasetRefreshing(false);
setDatasetLoading(false);
}, [
historicalBalancesData?.historicalBalances,
Expand All @@ -205,6 +212,43 @@ export const TradeChart = ({
assetIds,
]);

useEffect(() => {
const lastRecordOutdatedBy = 60000;

if (
!isVisible ||
historicalBalancesLoading ||
datasetRefreshing
)
return;

const refetchHistoricalBalancesData = () => {
if (
isVisible && !historicalBalancesLoading && !datasetRefreshing &&
(!dataset?.length || last(dataset).x <= new Date().getTime() - lastRecordOutdatedBy)
) {
setDatasetRefreshing(true);
setHistoricalBalancesRange({
from: moment().subtract(1, 'days').toISOString(),
to: moment().toISOString(),
});
}
};

refetchHistoricalBalancesData();

const refetchData = setInterval(() => {
refetchHistoricalBalancesData();
}, lastRecordOutdatedBy)

return () => clearInterval(refetchData)
}, [
dataset,
isVisible,
historicalBalancesLoading,
datasetRefreshing,
]);

// useEffect(() => {
// setDataset(dataset => {
// if (!spotPrice || !dataset) return dataset;
Expand All @@ -220,10 +264,16 @@ export const TradeChart = ({
// })
// }, [pool, spotPrice,])

const _isPoolLoading = useMemo(
() => isPoolLoading || historicalBalancesLoading || datasetLoading,
[datasetLoading, isPoolLoading, historicalBalancesLoading]
);
const _isPoolLoading = useMemo(() => {
if (!isPoolLoading || datasetRefreshing) return false;

return isPoolLoading || historicalBalancesLoading || datasetLoading;
}, [
datasetRefreshing,
datasetLoading,
isPoolLoading,
historicalBalancesLoading,
]);

console.log('graph loading status _isPoolLoading', _isPoolLoading);

Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4795,6 +4795,13 @@
dependencies:
"@types/react" "*"

"@types/react-page-visibility@^6.4.1":
version "6.4.1"
resolved "https://registry.yarnpkg.com/@types/react-page-visibility/-/react-page-visibility-6.4.1.tgz#21c3bc4a3f310d38d188916cadc55f2bde65f27d"
integrity sha512-vNlYAqKhB2SU1HmF9ARFTFZN0NSPzWn8HSjBpFqYuQlJhsb/aSYeIZdygeqfSjAg0PZ70id2IFWHGULJwe59Aw==
dependencies:
"@types/react" "*"

"@types/[email protected]":
version "11.0.5"
resolved "https://registry.yarnpkg.com/@types/react-syntax-highlighter/-/react-syntax-highlighter-11.0.5.tgz#0d546261b4021e1f9d85b50401c0a42acb106087"
Expand Down Expand Up @@ -16261,6 +16268,13 @@ react-multi-provider@^0.1.5:
resolved "https://registry.yarnpkg.com/react-multi-provider/-/react-multi-provider-0.1.5.tgz#fd712b2340eca3311273fdd9e8e8efd3ac31d7e2"
integrity sha512-eJWrjtSPIXZKQxN6ieNPb1TaZHlHSqWFBrwAgvCrhRd2GIFVJqZz08/atQSY421kMVeravzFZv1HfiLbrltiZA==

react-page-visibility@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/react-page-visibility/-/react-page-visibility-6.4.0.tgz#0684fe80338e716c9ed2d34169fa3cbb3882096b"
integrity sha512-5vQ0zQU2DvKCQAxle9l5V6uxw2m180Lk7Jem+obmTeQ503fvMJLSUzFgWtTEgUVynhUx2pd+RzafnuMAG8uD6A==
dependencies:
prop-types "^15.7.2"

react-popper-tooltip@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/react-popper-tooltip/-/react-popper-tooltip-3.1.1.tgz#329569eb7b287008f04fcbddb6370452ad3f9eac"
Expand Down

0 comments on commit caefc1c

Please sign in to comment.