Skip to content

Commit

Permalink
Init tracking in initApp
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Sep 13, 2024
1 parent f601426 commit 3f1da8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/core/methods/initApp/initApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InitAppType } from './initApp.types';
import { getIsLoggedIn } from '../account/getIsLoggedIn';
import { restoreProvider } from 'core/providers/helpers/restoreProvider';
import { registerWebsocketListener } from './websocket/registerWebsocket';
import { refreshAccount } from 'utils';
import { trackTransactions } from '../trackTransactions/trackTransactions';

const defaultInitAppProps = {
storage: {
Expand All @@ -34,6 +34,9 @@ export const initApp = async ({
}: InitAppType) => {
initStore(storage.getStorageCallback);

const shouldEnableTransactionTracker =
dAppConfig.enableTansactionTracker !== false;

if (dAppConfig?.nativeAuth) {
const nativeAuthConfig: NativeAuthConfigType =
typeof dAppConfig.nativeAuth === 'boolean'
Expand All @@ -48,6 +51,10 @@ export const initApp = async ({
environment: dAppConfig.environment
});

if (shouldEnableTransactionTracker) {
trackTransactions();
}

const isLoggedIn = getIsLoggedIn();

if (isLoggedIn) {
Expand Down
6 changes: 2 additions & 4 deletions src/core/methods/initApp/initApp.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { StorageCallback } from 'store/storage';
import { CustomNetworkType } from 'types/network.types';
import { EnvironmentsEnum } from 'types/enums.types';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { TransactionsTrackerType } from '../trackTransactions/trackTransactions.types';

type BaseDappConfigType = {
/**
Expand All @@ -13,10 +12,9 @@ type BaseDappConfigType = {
*/
nativeAuth?: boolean | NativeAuthConfigType;
/**
* Transactions tracker configuration for the dApp.
* If set to `null`, will disable transaction tracking.
* default: `true`
*/
tansactionTracker?: TransactionsTrackerType | null;
enableTansactionTracker?: boolean;
};

export type EnvironmentDappConfigType = BaseDappConfigType & {
Expand Down
5 changes: 5 additions & 0 deletions src/core/methods/trackTransactions/trackTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
import { getStore } from 'store/store';
import { websocketEventSelector } from 'store/selectors/accountSelectors';

/**
* Tracks transactions using websocket or polling
* @param props - optional object with additional websocket parameters
* @returns cleanup function
*/
export async function trackTransactions(props?: TransactionsTrackerType) {
const store = getStore();
const pollingInterval = getPollingInterval();
Expand Down

0 comments on commit 3f1da8d

Please sign in to comment.