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

fix: flakey connectors on re render #2943

Merged
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
29 changes: 16 additions & 13 deletions packages/account/src/connectors/fuel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
private _connectors: Array<FuelConnector> = [];
private _targetObject: TargetObject | null = null;
private _unsubscribes: Array<() => void> = [];
private _targetUnsubscribe: () => void;
private _targetUnsubscribe = () => {};
private _pingCache: CacheFor = {};
private _currentConnector?: FuelConnector | null;
private _initializationPromise: Promise<void>;
// private _initializationPromise: Promise<void>;

constructor(config: FuelConfig = Fuel.defaultConfig) {
super();
Expand All @@ -66,19 +66,22 @@
this._storage = config.storage === undefined ? this.getStorage() : config.storage;
// Setup all methods
this.setupMethods();
// Get the current connector from the storage
this._initializationPromise = this.initialize();
// Setup new connector listener for global events
this._targetUnsubscribe = this.setupConnectorListener();

(async () => {

Check failure on line 70 in packages/account/src/connectors/fuel.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check failure on line 70 in packages/account/src/connectors/fuel.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
await this.initialize();
})();
}

private async initialize(): Promise<void> {
// Get the current connector from the storage
await this.setDefaultConnector();
// Setup new connector listener for global events
this._targetUnsubscribe = this.setupConnectorListener();
}

private async ensureInitialized(): Promise<void> {
await this._initializationPromise;
}
// private async ensureInitialized(): Promise<void> {
// await this._initializationPromise;
// }

/**
* Return the target object to listen for global events.
Expand Down Expand Up @@ -309,7 +312,7 @@
* Return the list of connectors with the status of installed and connected.
*/
async connectors(): Promise<Array<FuelConnector>> {
await this.ensureInitialized();
// await this.ensureInitialized();
await this.fetchConnectorsStatus();
return this._connectors;
}
Expand All @@ -323,7 +326,7 @@
emitEvents: true,
}
): Promise<boolean> {
await this.ensureInitialized();
// await this.ensureInitialized();
const connector = this.getConnector(connectorName);
if (!connector) {
return false;
Expand Down Expand Up @@ -360,7 +363,7 @@
* Return true if any connector is available.
*/
async hasConnector(): Promise<boolean> {
await this.ensureInitialized();
// await this.ensureInitialized();
// If there is a current connector return true
// as the connector is ready
if (this._currentConnector) {
Expand All @@ -381,7 +384,7 @@
}

async hasWallet(): Promise<boolean> {
await this.ensureInitialized();
// await this.ensureInitialized();
return this.hasConnector();
}

Expand Down
Loading