Skip to content

Commit

Permalink
1.17.1 (#902)
Browse files Browse the repository at this point in the history
* TW-487: APY of tzBTC from Yupana (#850)

* TW-459: [e2e] Import account by Mnemonic (#852)

* [e2e] Import account by Mnemonic

* env fix

* env fix

* env fix

* env fix

* env fix

* env fix

* TW-459: [e2e] Import account by Mnemonic. Refactor

* TW-459: [e2e] Import account by Mnemonic. Refactor

* TW-459: [e2e] Import account by Mnemonic. Refactor + CopyButton selector fix

---------

Co-authored-by: alex-seleznov <alex.seleznov@gmail.com>

* TW-486 Migrated from segment to Jitsu (#851)

* TW-486 Migrated from segment to Jitsu

* TW-486 Commented perform end-to-end tests

* TW-486 Fixed pipeline

* TW-486 Commented perform end-to-end tests

* TW-486 Fixed pipeline

* TW-486 Fixed pipeline

* TW-460: Import an account by private key (#855)

* merging TW-409-e2e-reveal-seed-phrase-and-private-key into development

* [e2e] Import an account by private key

* TW-498: Fix Everstake affiliate keys (#853)

* TW-498: Fix Everstake affiliate keys

* TW-498: Fix Everstake affiliate keys. Refactor

* TW-498: Fix Everstake affiliate keys. Env vars refactor

* TW-498: Fix Everstake affiliate keys. Env vars refactor

* TW-498: Fix Everstake affiliate keys. Refactor

* TW-487: APY of tzBTC from Yupana. Fix persisted links (#857)

* TW-487: APY of tzBTC from Yupana

* TW-487: APY of tzBTC from Yupana. Fix persisted links

* TW-452: Change places of 'Swap' & 'Withdraw' buttons (#858)

* TW-493: Sync Total Equity Value with displayed tokens (#859)

* TW-493: Sync Total Equity Value with displayed tokens

* TW-493: Sync Total Equity Value with displayed tokens. Fix tokens balance calculation

* TW-493: Sync Total Equity Value with displayed tokens. Refactor

* TW-493: Sync Total Equity Value with displayed tokens. Refactor

* TW-458: Create or restore an account (#856)

* create or restore account

* Create or restore an account

* common step refactor + env refactor

* browser context refactor

* browser context refactor + condition refactor

* TW-458: [e2e] Create-or-restore account. + Required env vars check at build

* TW-458: [e2e] Create-or-restore account. -- Required env vars check at runtime

---------

Co-authored-by: alex-seleznov <alex.seleznov@gmail.com>

* TW-489: Refactor event name (#860)

* refactor event name

* TW-489: [e2e] Refactor selectors' names. + SwapForm testIDs

* refactor event name + fix e2e BDD

* refactor event name + fix e2e BDD + dead code fix

* fix comment

* fix comment

---------

Co-authored-by: alex-seleznov <alex.seleznov@gmail.com>

* TW-497: e2e import account by watch only (#864)

* import account by watch-only

* import account by watch-only

* TW-505: Assets selector unified design (#861)

* TW-505: Assets selector unified design. Swap selectors

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Send selectors menus

* TW-505: Assets selector unified design. + Search to 'Send' asset field

* TW-505: Assets selector unified design. Fix 'Send' asset field

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Finish re-design

* TW-505: Assets selector unified design. + Search to selects in 'Settings' page

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Fix after tested

* TW-505: Assets selector unified design. + Currencies names in Utorg selector

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Refactor

* TW-505: Assets selector unified design. Refactor

* TW-358 Add cut decimals to value greater then 1000 (#867)

* TW-358 Add cut decimals to value grather then 1000

* TW-358 Add the correct balance formatter

* TW-358 Fix review

* TW-358 Fix review

---------

Co-authored-by: svyatoslavtt <stiven22235@gmail.com>

* TW-448 Added fetching balances from tzkt (#847)

* TW-448 Added fetching balances from tzkt

* TW-448 Improved balances

* TW-448 Fixed tokens loading

* TW-448 Fixed balance decimals

* TW-448 Fixed balance decimals

* TW-448 Fixed comment

* TW-448 Fixed tzks tokens metadata

* TW-448 Deleted console.logs

* TW-448 Fixed balances loading

* TW-448 Added balances store

* TW-448 Fixed comments

* TW-448 Fixed comments

* TW-448 Fixed loading balances

* TW-448 Fixed balances bugs

* TW-448 Fixed comments

* TW-557 - delegation on tezos forked blockchain (#866)

* change tzkt api base url for dcp

* fix api for t3l4nt mainnet

* TW-464: e2e-Unlock screen (#871)

* Unlock screen

* Magick number fix

* TW-463: e2e-Delegate + timeouts increased(pipeline fix) (#870)

* e2e-Delegate + timeouts increased(pipeline fix)

* e2e-Delegate + timeouts increased(pipeline fix)

* e2e-Delegate + timeouts increased(pipeline fix)

* e2e-Delegate + timeouts increased(pipeline fix)

* test pipeline

* test pipeline

* test pipeline

* test pipeline macos env

* test pipeline

* Delegate step refactor

* Delegate step refactor

* fix comments

* fix comments

* TW-560: Analytics. Track all events (#865)

* TW-560: Analytics. Track all events. Checkboxes

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. + Anchors analytics

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. + Drop-down analytics

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. + Analytics on tokens balances

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. + ReduxStore.settings

* TW-560: Analytics. Track all events. Refactor

* TW-560: Analytics. Track all events. + Events

* TW-560: Analytics. Track all events. Fix e2e

* TW-560: Analytics. Track all events. ++[e2e]

* TW-560: Analytics. Track all events. Fix Jitsu SDK

* TW-560: Analytics. Track all events. Fix Jitsu SDK on MV2 + Fix analytics checkbox on 'Create Password' page

* TW-560: Analytics. Track all events. Refactor <HelpAndCommunity />

* TW-560: Analytics. Track all events. Jitsu. Fix with empty commit

* TW-560: Analytics. Track all events. [e2e] ++Timeouts

* TW-560: Analytics. Track all events. Jitsu. Fix with empty commit

* Tw 605 change the link for support (#876)

* TW-605: Change the link for support

* TW-605: Add constant for url

---------

Co-authored-by: svyatoslavtt <stiven22235@gmail.com>

* Tw 583 A/B testing for not delegate button (#872)

* TW-413: Add A/B testing for the delegate button

* TW-413: Add request for ab-testing to redux

* TW-413: Remove unused file

* TW-413: Fix imports

* TW-413: Add animation & track analytics

* e2e delegate apy button FIX

* TW-583: Fix review

* TW-583: Fix review

* TW-583: Fix review

* TW-583: Fix review

* TW-583: Add ab-testing request to unlock screen

---------

Co-authored-by: svyatoslavtt <stiven22235@gmail.com>
Co-authored-by: Vlad Novak <purch2442@gmail.com>

* TW-588: Block duration is 15 sec (#873)

* TW-588: Block duration is 15 sec

* TW-588: Block duration is 15 sec. BALANCES_SYNC_INTERVAL = BLOCK_DURATION

* TW-554: Add correct display of total balance in gas token (#877)

* TW-554: Add correct display of total balance in gas token

* TW-554: Remove unused code

* TW-554: Remove unused imports

---------

Co-authored-by: svyatoslavtt <stiven22235@gmail.com>

* TW-461: e2e send (#875)

* e2e-Delegate + timeouts increased(pipeline fix)

* e2e-Delegate + timeouts increased(pipeline fix)

* e2e-Delegate + timeouts increased(pipeline fix)

* e2e-Delegate + timeouts increased(pipeline fix)

* test pipeline

* test pipeline

* test pipeline

* test pipeline macos env

* test pipeline

* Delegate step refactor

* Delegate step refactor

* send first stage

* fix comments

* fix comments

* second send

* clearInput method added, send e2e completed

* hooks

* feature file fix

* puppeteer perfomance speed reduced

* TW-461: [e2e] Send. + Other selectors

---------

Co-authored-by: Alex <alex.seleznov@gmail.com>

* TW-453 Implement sorting tokens by USD equity (#874)

* TW-453 Implement sorting tokens by USD equity

* TW-453 Refactor sorting tokens for 'Send' page

* TW-453 Refactor useUsdToTokenRates function

* TW-534 Added partners promotion from 0xOptimal (#862)

* TW-362: Fix bug with network (#878)

* TW-455 Added route3 api to form (#854)

* TW-455 Added route3 api to form

* TW-445 Used route3 for swaps

* TW-455 Added 3route layout

* TW-455 Fixed deadcode

* TW-455 Finished 3route integration

* TW-455 deleted unnecessary files

* TW-455 Fixed added translations

* TW-455 Fixed pipeline

* TW-455 Added route3 contract to envs

* TW-455 fixed conflicts

* TW-455: 3-route integration. + env var to GitHub workflow

* TW-455 Moved route3 contract to constants

* TW-455 Deleted ROUTE3_CONTRACT from vars

* TW-455 Fixed comments

* TW-455 Added Auth token to .env

* TW-455 Commented e2e tests

* TW-455 Uncommented tests

* TW-455 Fixed rounding

* TW-455 Deleted uunecessary files

* TW-455 Fixed comments

* TW-455 Fixed .env.dist

* TW-455 Fixed manual build and release

* TW-455 Fixed bugs

* TW-455 Fixed comments

* TW-455 Added dex types

* TW-455 Fixed bugs after review

* TW-455 Fixed exports

* TW-455 Deleted unnecessary comment

* TW-455 Fixed kusd decimals

* TW-455 Fixed bugs after testing

* TW-455 deleted unneecessary file

* TW-455 Fixed bugs after testing

* TW-455 Moved loading swapParams to Epic

* TW-455 Fixed bugs after testing

* TW-455 Fixed toggle icon click

* TW-455 removed swap-router-sdk

* TW-455 Added isDefined helper

* TW-455 Fixed comment about undefined

* TW-455 Added tezos to deps

* TW-455 Fixed swap assets button

---------

Co-authored-by: alex-seleznov <alex.seleznov@gmail.com>

* TW-571 Fix errors not being properly reset in AddAsset form (#882)

* Remove legacy networks from default list; Add mumbainet (#885)

* TW-471: e2e change node (#886)

* change node

* change node

* timeouts added to every 'given'

* TW-623: e2e video-recorder setup (#883)

* e2e recorder (without fails)

* timeout increased

* timeout increased

* workflow fix

* minor fixes

---------

Co-authored-by: Alex <alex.seleznov@gmail.com>

* TW-641 The swap section is not sorted by dollar value (#892)

* sorting fixed

* useMemo update

Co-authored-by: Innokentiy Mazhara <keshan3262@gmail.com>

---------

Co-authored-by: Innokentiy Mazhara <keshan3262@gmail.com>

* TW-655 Don't render promotion in case it's empty (#890)

* TW-655 Don't render promotion in case it's empty

* TW-655 Handle broken images in promotions

* TW-655 Fix broken wallet one receiving unexpected response from optimal

* Tw 511 temple token (#884)

* TW-455 Added route3 api to form

* TW-445 Used route3 for swaps

* TW-455 Added 3route layout

* TW-455 Fixed deadcode

* TW-455 Finished 3route integration

* TW-455 deleted unnecessary files

* TW-455 Fixed added translations

* TW-455 Fixed pipeline

* TW-455 Added route3 contract to envs

* TW-455 fixed conflicts

* TW-455: 3-route integration. + env var to GitHub workflow

* TW-455 Moved route3 contract to constants

* TW-455 Deleted ROUTE3_CONTRACT from vars

* TW-455 Fixed comments

* TW-455 Added Auth token to .env

* TW-455 Commented e2e tests

* TW-455 Uncommented tests

* TW-455 Fixed rounding

* TW-455 Deleted uunecessary files

* TW-455 Fixed comments

* TW-455 Fixed .env.dist

* TW-455 Fixed manual build and release

* TW-455 Fixed bugs

* TW-455 Fixed comments

* TW-455 Added dex types

* TW-455 Fixed bugs after review

* TW-455 Fixed exports

* TW-455 Deleted unnecessary comment

* TW-455 Fixed kusd decimals

* TW-455 Fixed bugs after testing

* TW-455 deleted unneecessary file

* TW-455 Fixed bugs after testing

* TW-455 Moved loading swapParams to Epic

* TW-455 Fixed bugs after testing

* TW-455 Fixed toggle icon click

* TW-455 removed swap-router-sdk

* TW-455 Added isDefined helper

* TW-455 Fixed comment about undefined

* TW-455 Added tezos to deps

* TW-455 Fixed swap assets button

* TW-511 Added temple token as a fee

* TW-511 Fixed bug with swap Temple to Temple

* TW-511 Change fee calculation for SwapForm.tsx

* TW-511 Finished swap with first temple token

* TW-511 Added some refactoring

* TW-511 Fixed minimum received amount

* TW-511 added 10$ threshold

* TW-511 Added cashback field in swap form

* TW-511 Fixed swap params

* TW-511 Fixed comments

* TW-511 Fixed bugs after testing

* TW-511 Deleted console.log

* TW-511 Fixed bugs after testing

* TW-511 Fixed comments

---------

Co-authored-by: alex-seleznov <alex.seleznov@gmail.com>
Co-authored-by: Korney Vasilchenko <starkkor@gmail.com>

* TW-677 Change hardcoded token information (#893)

* bump version to 1.17.0

* TW-685 Balances not loading after block explorer change (#901)

* tezblock explorer removed + balances load fixed

* e2e

* -export

* TW-686 Wrong total Tezos balance displayed if fiat is not USD (#900)

* fixed

* e2e

* review fixes

---------

Co-authored-by: Alex <alexseleznov@madfish.solutions>
Co-authored-by: Vlad <95026747+NovakVlad2424@users.noreply.github.com>
Co-authored-by: alex-seleznov <alex.seleznov@gmail.com>
Co-authored-by: Dmytro Herko <61412282+herkoss@users.noreply.github.com>
Co-authored-by: Svyatoslav Tyutyunnik <svyatoslavtt.work@gmail.com>
Co-authored-by: svyatoslavtt <stiven22235@gmail.com>
Co-authored-by: Aleks Razbeikov <58780063+Boltman92@users.noreply.github.com>
Co-authored-by: Vlad Novak <purch2442@gmail.com>
Co-authored-by: Innokentiy Mazhara <keshan3262@gmail.com>
Co-authored-by: Danyl Mishyn <35381314+lendihop@users.noreply.github.com>
  • Loading branch information
11 people committed May 16, 2023
1 parent e3b41e5 commit c292879
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 142 deletions.
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "./node_modules/.bin/cucumber-js --fail-fast",
"start:dev": "yarn start --tags @dev",
"test": "yarn start --exit",
"test": "yarn start --exit --tags 'not @dev'",
"ts": "tsc --pretty"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/features/delegate.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: Delegate

@dev
Scenario: As a user, i'd like to re-delegate TEZ to a baker
Given I have imported an existing account
And I press Asset Item Apy Button on the Assets page
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/features/send.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: Send

@dev
Scenario: As a user, I'd like to send my funds to another account
Given I have imported an existing account
And I press Send Button on the Home page
Expand Down
Binary file removed public/misc/explorer-logos/tezblock.ico
Binary file not shown.
21 changes: 3 additions & 18 deletions src/app/store/balances/actions.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
import { createActions } from 'lib/store/utils/action.utils';
import { IAccountToken } from 'lib/temple/repo';

interface BalancesPayloadAbstract {
interface BalancesTzktPayloadSubmit {
publicKeyHash: string;
chainId: string;
}
interface BalancesPayloadSuccess extends BalancesPayloadAbstract {
interface BalancesPayloadSuccess extends BalancesTzktPayloadSubmit {
balances: Record<string, string>;
}
interface BalancesPayloadFail extends BalancesPayloadAbstract {
interface BalancesPayloadFail extends BalancesTzktPayloadSubmit {
error: string;
}

interface BalancesTzktPayloadSubmit extends BalancesPayloadAbstract {
apiUrl: string;
}

export const loadTokensBalancesFromTzktAction = createActions<
BalancesTzktPayloadSubmit,
BalancesPayloadSuccess,
BalancesPayloadFail
>('balances/LOAD_TOKENS_BALANCES');

interface BalancesChainPayloadSubmit extends BalancesPayloadAbstract {
rpcUrl: string;
tokens: Array<IAccountToken>;
}
export const loadTokensBalancesFromChainAction = createActions<
BalancesChainPayloadSubmit,
BalancesPayloadSuccess,
BalancesPayloadFail
>('balances/LOAD_TEZOS_BALANCE');
47 changes: 8 additions & 39 deletions src/app/store/balances/epics.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { TezosToolkit } from '@taquito/taquito';
import { BigNumber } from 'bignumber.js';
import { combineEpics, Epic } from 'redux-observable';
import { catchError, forkJoin, from, map, Observable, of, switchMap } from 'rxjs';
import { catchError, forkJoin, map, Observable, of, switchMap } from 'rxjs';
import { Action } from 'ts-action';
import { ofType, toPayload } from 'ts-action-operators';

import { fecthTezosBalanceFromTzkt, fetchAllTokensBalancesFromTzkt } from 'lib/apis/tzkt/api';
import { fetchBalance, fetchTezosBalanceAtomic, toTokenSlug } from 'lib/temple/assets';
import { TEZ_TOKEN_SLUG } from 'lib/temple/front';
import { toTokenSlug } from 'lib/temple/assets';
import { atomsToTokens } from 'lib/temple/helpers';
import { IAccountToken } from 'lib/temple/repo';

import { loadTokensBalancesFromChainAction, loadTokensBalancesFromTzktAction } from './actions';
import { loadTokensBalancesFromTzktAction } from './actions';

const YUPANA_TOKENS = [
'KT1Rk86CX85DjBKmuyBhrCyNsHyudHVtASec_0',
Expand All @@ -23,15 +20,15 @@ const YUPANA_TOKENS = [
];
const YUPANA_MULTIPLIER = 18;

const fetchTokensBalances$ = (apiUrl: string, account: string) =>
forkJoin([fecthTezosBalanceFromTzkt(apiUrl, account), fetchAllTokensBalancesFromTzkt(apiUrl, account)]);
const fetchTokensBalances$ = (account: string, chainId: string) =>
forkJoin([fecthTezosBalanceFromTzkt(account, chainId), fetchAllTokensBalancesFromTzkt(account, chainId)]);

const loadTokensBalancesFromTzktEpic: Epic = (action$: Observable<Action>) =>
action$.pipe(
ofType(loadTokensBalancesFromTzktAction.submit),
toPayload(),
switchMap(({ apiUrl, publicKeyHash, chainId }) =>
fetchTokensBalances$(apiUrl, publicKeyHash).pipe(
switchMap(({ publicKeyHash, chainId }) =>
fetchTokensBalances$(publicKeyHash, chainId).pipe(
map(([tezosBalances, tokensBalances]) => {
const balances: Record<string, string> = {
tez: new BigNumber(tezosBalances.balance ?? 0).minus(tezosBalances.frozenDeposit ?? 0).toFixed()
Expand All @@ -52,32 +49,4 @@ const loadTokensBalancesFromTzktEpic: Epic = (action$: Observable<Action>) =>
)
);

const fetchTokensBalancesFromChain = async (tokens: Array<IAccountToken>, rpcUrl: string, publicKeyHash: string) => {
const tezos = new TezosToolkit(rpcUrl);

const balances: Record<string, string> = {};

for (const { tokenSlug } of tokens) {
const balance = await fetchBalance(tezos, tokenSlug, publicKeyHash);
balances[tokenSlug] = balance.toFixed();
}

const tezosBalance = await fetchTezosBalanceAtomic(tezos, publicKeyHash);
balances[TEZ_TOKEN_SLUG] = tezosBalance.toFixed();

return balances;
};

const loadTokensBalancesFromChainEpic: Epic = (action$: Observable<Action>) =>
action$.pipe(
ofType(loadTokensBalancesFromChainAction.submit),
toPayload(),
switchMap(({ rpcUrl, tokens, publicKeyHash, chainId }) =>
from(fetchTokensBalancesFromChain(tokens, rpcUrl, publicKeyHash)).pipe(
map(balances => loadTokensBalancesFromChainAction.success({ publicKeyHash, chainId, balances })),
catchError(err => of(loadTokensBalancesFromChainAction.fail(err.message)))
)
)
);

export const balancesEpics = combineEpics(loadTokensBalancesFromTzktEpic, loadTokensBalancesFromChainEpic);
export const balancesEpics = combineEpics(loadTokensBalancesFromTzktEpic);
20 changes: 1 addition & 19 deletions src/app/store/balances/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createReducer } from '@reduxjs/toolkit';
import { getKeyForBalancesRecord } from 'lib/balances';
import { createEntity } from 'lib/store/utils/entity.utils';

import { loadTokensBalancesFromChainAction, loadTokensBalancesFromTzktAction } from './actions';
import { loadTokensBalancesFromTzktAction } from './actions';
import { balancesInitialState } from './state';

export const balancesReducer = createReducer(balancesInitialState, builder => {
Expand All @@ -24,22 +24,4 @@ export const balancesReducer = createReducer(balancesInitialState, builder => {
[getKeyForBalancesRecord(payload.publicKeyHash, payload.chainId)]: createEntity({}, false, payload.error)
};
});
builder.addCase(loadTokensBalancesFromChainAction.submit, (state, { payload }) => {
state.balancesAtomic = {
...state.balancesAtomic,
[getKeyForBalancesRecord(payload.publicKeyHash, payload.chainId)]: createEntity({}, true)
};
});
builder.addCase(loadTokensBalancesFromChainAction.success, (state, { payload }) => {
state.balancesAtomic = {
...state.balancesAtomic,
[getKeyForBalancesRecord(payload.publicKeyHash, payload.chainId)]: createEntity(payload.balances, false)
};
});
builder.addCase(loadTokensBalancesFromChainAction.fail, (state, { payload }) => {
state.balancesAtomic = {
...state.balancesAtomic,
[getKeyForBalancesRecord(payload.publicKeyHash, payload.chainId)]: createEntity({}, false, payload.error)
};
});
});
46 changes: 28 additions & 18 deletions src/lib/apis/tzkt/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,41 @@ export async function refetchOnce429<R>(fetcher: () => Promise<R>, delayAroundIn
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

export const fecthTezosBalanceFromTzkt = (
apiUrl: string,
account: string
): Promise<{ frozenDeposit?: string; balance: string }> =>
axios
.get(`${apiUrl}/v1/accounts/${account}`)
.then(({ data: { frozenDeposit, balance } }) => ({ frozenDeposit, balance }));
account: string,
chainId: string
): Promise<{ frozenDeposit?: string; balance: string }> => {
if (isKnownChainId(chainId)) {
return axios
.get(`${TZKT_API_BASE_URLS[chainId]}/accounts/${account}`)
.then(({ data: { frozenDeposit, balance } }) => ({ frozenDeposit, balance }));
}

return Promise.resolve({ balance: '0' });
};

const LIMIT = 10000;

const fecthTokensBalancesFromTzktOnce = (
apiUrl: string,
account: string,
chainId: string,
limit: number,
offset = 0
): Promise<Array<TzktAccountToken>> =>
axios
.get<Array<TzktAccountToken>>(`${apiUrl}/v1/tokens/balances`, {
params: {
account,
'balance.gt': 0,
limit,
offset
}
})
.then(({ data }) => data);
): Promise<Array<TzktAccountToken>> => {
if (isKnownChainId(chainId)) {
return axios
.get<Array<TzktAccountToken>>(`${TZKT_API_BASE_URLS[chainId]}/tokens/balances`, {
params: {
account,
'balance.gt': 0,
limit,
offset
}
})
.then(({ data }) => data);
}

return Promise.resolve([]);
};

export const fetchAllTokensBalancesFromTzkt = async (selectedRpcUrl: string, account: string) => {
const balances: TzktAccountToken[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/temple/assets/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { atomsToTokens } from '../helpers';
import { TEZOS_METADATA, AssetMetadata } from '../metadata';
import { fromAssetSlug, isFA2Token } from './utils';

export async function fetchTezosBalanceAtomic(tezos: TezosToolkit, account: string) {
async function fetchTezosBalanceAtomic(tezos: TezosToolkit, account: string) {
let nat = (await getBalanceSafe(tezos, account)) ?? new BigNumber(0);
nat = toSafeBignum(nat);

Expand Down
15 changes: 1 addition & 14 deletions src/lib/temple/front/blockexplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMemo } from 'react';
import { useChainId, useStorage } from 'lib/temple/front';
import { isKnownChainId, TempleChainId } from 'lib/temple/types';

type BlockExplorerId = 'tzkt' | 'tzstats' | 'bcd' | 'tezblock' | 't4l3nt';
type BlockExplorerId = 'tzkt' | 'tzstats' | 'bcd' | 't4l3nt';

type BaseUrls = { account?: string; transaction: string; api?: string };

Expand Down Expand Up @@ -104,19 +104,6 @@ export const BLOCK_EXPLORERS: BlockExplorer[] = [
}
]
])
},
{
id: 'tezblock',
name: 'tezblock',
baseUrls: new Map([
[
TempleChainId.Mainnet,
{
account: 'https://tezblock.io/account',
transaction: 'https://tezblock.io/transaction'
}
]
])
}
];

Expand Down
27 changes: 4 additions & 23 deletions src/lib/temple/front/load-balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import { useCallback } from 'react';

import { useDispatch } from 'react-redux';

import { loadTokensBalancesFromChainAction, loadTokensBalancesFromTzktAction } from 'app/store/balances/actions';
import { loadTokensBalancesFromTzktAction } from 'app/store/balances/actions';
import { BALANCES_SYNC_INTERVAL } from 'lib/fixed-times';
import {
useAccount,
useChainId,
useDisplayedFungibleTokens,
useExplorerBaseUrls,
useNetwork
} from 'lib/temple/front/index';
import { useAccount, useChainId, useNetwork } from 'lib/temple/front/index';
import { useSyncTokens } from 'lib/temple/front/sync-tokens';
import { useInterval } from 'lib/ui/hooks';

Expand All @@ -22,25 +16,12 @@ export const useBalancesLoading = () => {
const { rpcBaseURL: rpcUrl } = useNetwork();

const { publicKeyHash } = useAccount();
const { api: apiUrl } = useExplorerBaseUrls();
const { data: tokens = [] } = useDisplayedFungibleTokens(chainId, publicKeyHash);

const load = useCallback(() => {
if (isSyncing !== false) return;

if (apiUrl !== undefined) {
dispatch(loadTokensBalancesFromTzktAction.submit({ apiUrl, publicKeyHash, chainId }));
} else {
dispatch(
loadTokensBalancesFromChainAction.submit({
rpcUrl,
tokens,
publicKeyHash,
chainId
})
);
}
}, [isSyncing, chainId, publicKeyHash, apiUrl, rpcUrl]);
dispatch(loadTokensBalancesFromTzktAction.submit({ publicKeyHash, chainId }));
}, [isSyncing, chainId, publicKeyHash, rpcUrl]);

useInterval(load, BALANCES_SYNC_INTERVAL, [load]);
};
20 changes: 13 additions & 7 deletions src/lib/temple/front/use-total-balance.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,32 @@ export const useTotalBalance = () => {
[tokens]
);

const totalBalanceInFiat = useMemo(() => {
const totalBalanceInDollar = useMemo(() => {
let dollarValue = new BigNumber(0);

if (!isTruthy(fiatToUsdRate)) return dollarValue;

for (const slug of slugs) {
const balance = tokensBalances[slug];
const usdToTokenRate = allUsdToTokenRates[slug];
const tokenDollarValue = isDefined(balance) && isTruthy(usdToTokenRate) ? balance.times(usdToTokenRate) : 0;
dollarValue = dollarValue.plus(tokenDollarValue);
}

return dollarValue.times(fiatToUsdRate);
}, [slugs, tokensBalances, allUsdToTokenRates, fiatToUsdRate]);
return dollarValue;
}, [slugs, tokensBalances, allUsdToTokenRates]);

const totalBalanceInFiat = useMemo(() => {
if (!isTruthy(fiatToUsdRate)) return new BigNumber(0);

return totalBalanceInDollar.times(fiatToUsdRate);
}, [totalBalanceInDollar, fiatToUsdRate]);

const totalBalanceInGasToken = useMemo(() => {
const tezosToUsdRate = allUsdToTokenRates[TEZ_TOKEN_SLUG];

return totalBalanceInFiat.dividedBy(tezosToUsdRate).decimalPlaces(gasToken.metadata.decimals) || new BigNumber(0);
}, [totalBalanceInFiat, allUsdToTokenRates, gasToken.metadata.decimals]);
if (!isTruthy(tezosToUsdRate)) return new BigNumber(0);

return totalBalanceInDollar.dividedBy(tezosToUsdRate).decimalPlaces(gasToken.metadata.decimals) || new BigNumber(0);
}, [totalBalanceInDollar, allUsdToTokenRates, gasToken.metadata.decimals]);

return { totalBalanceInFiat, totalBalanceInGasToken };
};

0 comments on commit c292879

Please sign in to comment.