Skip to content

Commit e2beba1

Browse files
sudokeyRexagon
authored andcommitted
fix microwave initialization
1 parent 2fee0eb commit e2beba1

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

src/providers/useMicrowave.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ref, watch } from 'vue';
2-
import { Address, Subscription, LT_COLLATOR, TransactionId, Transaction } from 'everscale-inpage-provider';
2+
import { Address, Subscription, LT_COLLATOR, TransactionId, Transaction, ProviderRpcClient } from 'everscale-inpage-provider';
33
import BigNumber from 'bignumber.js';
44
import * as core from '@core';
55
import { useTvmConnect } from './useTvmConnect';
@@ -60,12 +60,7 @@ type Addresses = {
6060
microwave: string;
6161
};
6262

63-
const getAddresses = async (): Promise<Addresses | undefined> => {
64-
const provider = tvmConnect.getProvider()
65-
if (!provider) {
66-
return undefined
67-
}
68-
63+
const getAddresses = async (provider: ProviderRpcClient): Promise<Addresses | undefined> => {
6964
await provider.ensureInitialized()
7065

7166
const [{ hash: factoryHash }, { hash: microwaveHash }] = await Promise.all([
@@ -105,9 +100,13 @@ const unfreezeContract = (args: UnfreezeContractParams, setStatus: (status?: str
105100
} = { cancelled: false };
106101

107102
const promise = (async () => {
108-
const addresses = await getAddresses();
109103
const provider = tvmConnect.getProvider();
110-
if (addresses == null || !provider) {
104+
if (!provider) {
105+
return;
106+
}
107+
108+
const addresses = await getAddresses(provider);
109+
if (addresses == null) {
111110
return;
112111
}
113112

@@ -332,8 +331,12 @@ const deployMicrowave = (setStatus: (status?: string) => void) => {
332331
};
333332

334333
const promise = (async () => {
335-
const addresses = await getAddresses();
336-
const provider = tvmConnect.getProvider()
334+
const provider = tvmConnect.getProvider();
335+
if (!provider) {
336+
return;
337+
}
338+
339+
const addresses = await getAddresses(provider);
337340
const selectedAccountAddress = tvmConnectState.value.account.address;
338341
if (addresses == null || selectedAccountAddress == null || state.cancelled || !provider) {
339342
return;
@@ -444,9 +447,9 @@ const deployMicrowave = (setStatus: (status?: string) => void) => {
444447
};
445448

446449
watch(
447-
[initialized, tvmConnectState.value.networkId],
448-
async ([initialized], _old, onCleanup) => {
449-
if (!initialized) {
450+
[initialized, () => tvmConnectState.value.isReady],
451+
async ([initialized, isReady], _old, onCleanup) => {
452+
if (!initialized || !isReady) {
450453
return;
451454
}
452455

@@ -463,8 +466,11 @@ watch(
463466
}
464467
});
465468

466-
const addresses = await getAddresses();
467469
const provider = tvmConnect.getProvider();
470+
if (!provider) {
471+
return;
472+
}
473+
const addresses = await getAddresses(provider);
468474
if (addresses == null || state.networkChanged || !provider) {
469475
return;
470476
}

0 commit comments

Comments
 (0)