Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLA-1785] remove init promise #117

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resources/js/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const initialTheme = () => {
}
};

(() => {
appStore.init();
(async () => {
await appStore.init();
initialTheme();

if (window.bootstrap?.name) {
Expand Down
2 changes: 0 additions & 2 deletions resources/js/components/beam/BeamsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ const openTransactionSlide = async (transactionId: string) => {
};

onMounted(async () => {
await appStore.initPromise;
useAppStore().clearInitPromise();
getBeams();
loadMoreItemsWithObserver();
events.on('transaction', openTransactionSlide);
Expand Down
3 changes: 0 additions & 3 deletions resources/js/components/beam/ClaimsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ import CollapseFilter from '~/components/CollapseFilter.vue';
import NoItems from '~/components/NoItems.vue';
import snackbar from '~/util/snackbar';
import { BeamApi } from '~/api/beam';
import { useAppStore } from '~/store';

const isLoading = ref(true);
const isPaginationLoading = ref(false);
Expand Down Expand Up @@ -278,8 +277,6 @@ const closeModalSlide = () => {
};

(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
await getClaims();
})();

Expand Down
2 changes: 0 additions & 2 deletions resources/js/components/marketplace/BidsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ const closeModalSlide = () => {
};

(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
await getBids();
})();

Expand Down
2 changes: 0 additions & 2 deletions resources/js/components/marketplace/ListingsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ const closeModalSlide = () => {
};

(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
await getListings();
})();

Expand Down
2 changes: 0 additions & 2 deletions resources/js/components/marketplace/SalesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ const closeModalSlide = () => {
};

(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
await getSales();
})();

Expand Down
2 changes: 0 additions & 2 deletions resources/js/components/pages/Collections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ const openTransactionSlide = async (transactionId: string) => {
};

(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
await getCollections();
})();

Expand Down
3 changes: 0 additions & 3 deletions resources/js/components/pages/FuelTanks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ import { FuelTankApi } from '~/api/fueltank';
import { formatData } from '~/util';
import Btn from '../Btn.vue';
import { TransactionState } from '~/types/types.enums';
import { useAppStore } from '~/store';

const isLoading = ref(true);
const isPaginationLoading = ref(false);
Expand Down Expand Up @@ -329,8 +328,6 @@ const openTransactionSlide = async (transactionId: string) => {
};

(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
await getFuelTanks();
})();

Expand Down
3 changes: 0 additions & 3 deletions resources/js/components/pages/Tokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ import snackbar, { events } from '~/util/snackbar';
import FormInput from '~/components/FormInput.vue';
import NoItems from '~/components/NoItems.vue';
import Btn from '~/components/Btn.vue';
import { useAppStore } from '~/store';

const isLoading = ref(false);
const isPaginationLoading = ref(false);
Expand Down Expand Up @@ -342,8 +341,6 @@ const openTransactionSlide = async (transactionId: string) => {
};

onMounted(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
getTokens();
loadMoreTokensWithObserver();
events.on('transaction', openTransactionSlide);
Expand Down
3 changes: 0 additions & 3 deletions resources/js/components/pages/Transactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ import SignTransaction from '../SignTransaction.vue';
import { TransactionApi } from '~/api/transaction';
import DropdownMenu from '../DropdownMenu.vue';
import ConfirmModal from '../ConfirmModal.vue';
import { useAppStore } from '~/store';

const isLoading = ref(false);
const isPaginationLoading = ref(false);
Expand Down Expand Up @@ -550,8 +549,6 @@ const closeModalSlide = () => {
};

(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
getTransactions();
})();

Expand Down
3 changes: 0 additions & 3 deletions resources/js/components/pages/Wallets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ import FormInput from '~/components/FormInput.vue';
import NoItems from '~/components/NoItems.vue';
import { TransactionState } from '~/types/types.enums';
import Btn from '../Btn.vue';
import { useAppStore } from '~/store';

const isLoading = ref(false);
const isPaginationLoading = ref(false);
Expand Down Expand Up @@ -308,8 +307,6 @@ const openTransactionSlide = async (transactionId: string) => {
};

onMounted(async () => {
await useAppStore().initPromise;
useAppStore().clearInitPromise();
getWallets();
loadMoreItemsWithObserver();
events.on('transaction', openTransactionSlide);
Expand Down
4 changes: 1 addition & 3 deletions resources/js/components/pages/auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ const login = async (recaptcha?: string) => {

return;
}
appStore.init();
await appStore.initPromise;
appStore.clearInitPromise();
await appStore.init();
if (appStore.loggedIn) {
snackbar.success({ title: 'Logged in successfully', save: false });
if (appStore.hasValidConfig) {
Expand Down
94 changes: 45 additions & 49 deletions resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,64 +50,60 @@ export const useAppStore = defineStore('app', {
async init() {
try {
// eslint-disable-next-line
this.initPromise = new Promise(async (resolve) => {
if (this.config.network) {
return;
}
if (this.config.network) {
return;
}

this.setConfig();
this.setConfig();

if (!this.config.url) {
return false;
}
if (!this.isMultiTenant && !this.config.authorization_token.length) {
return false;
}
if (!this.config.url) {
return false;
}
if (!this.isMultiTenant && !this.config.authorization_token.length) {
return false;
}

const urlConfig = await this.checkURL(this.config.url);
try {
const internalConfig = await ApiService.fetchInternalUrl(this.config.url);
if (internalConfig) {
this.internal = true;
}
} catch {
this.internal = false;
const urlConfig = await this.checkURL(this.config.url);
try {
const internalConfig = await ApiService.fetchInternalUrl(this.config.url);
if (internalConfig) {
this.internal = true;
}
this.config.network = urlConfig?.network;
this.config.packages = Object.entries(urlConfig.packages).map(([key, value]: any[]) => {
let link =
urlConfig.url +
'/graphiql/' +
(key === 'enjin/platform-core' ? '' : key.replace('enjin/platform-', ''));
if (key === 'enjin/platform-ui') link = '';

return {
name: key.replace('enjin/', ''),
version: value.version,
link,
};
});
} catch {
this.internal = false;
}
this.config.network = urlConfig?.network;
this.config.packages = Object.entries(urlConfig.packages).map(([key, value]: any[]) => {
let link =
urlConfig.url +
'/graphiql/' +
(key === 'enjin/platform-core' ? '' : key.replace('enjin/platform-', ''));
if (key === 'enjin/platform-ui') link = '';

if (this.hasBeamPackage) {
this.addBeamNavigation();
}
if (this.hasFuelTanksPackage) {
this.addFuelTanksNavigation();
}
if (this.hasMarketplacePackage) {
this.addMarketplaceNavigation();
}
return {
name: key.replace('enjin/', ''),
version: value.version,
link,
};
});

if (this.loggedIn && this.hasMultiTenantPackage && this.config.tenant && !this.user) {
await this.getUser();
}
if (this.hasBeamPackage) {
this.addBeamNavigation();
}
if (this.hasFuelTanksPackage) {
this.addFuelTanksNavigation();
}
if (this.hasMarketplacePackage) {
this.addMarketplaceNavigation();
}

await useConnectionStore().getSession();
if (this.loggedIn && this.hasMultiTenantPackage && this.config.tenant && !this.user) {
await this.getUser();
}

await this.fetchCollectionIds();
await useConnectionStore().getSession();

resolve();
});
await this.fetchCollectionIds();
} catch (error: any) {
snackbar.error({ title: error });
if (this.config.tenant) {
Expand Down
Loading