Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
fix(sdk): resolve immediately if already enabled with the same options
Browse files Browse the repository at this point in the history
  • Loading branch information
LeilaWang committed Feb 13, 2020
1 parent ccb3911 commit 5e2fd22
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/extension/src/client/Aztec/ApiManager.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isEqual from 'lodash/isEqual';
import {
getNetworkName,
} from '~/utils/network';
Expand All @@ -10,6 +11,7 @@ export default class ApiManager {
constructor() {
this.eventListeners = new EventListeners(['profileChanged']);
this.enableProfileChangeListener = null;
this.enabledOptions = null;

Web3Service.bindProfileChange((changedType, newTypeValue) => {
let objValue = newTypeValue || null;
Expand Down Expand Up @@ -65,6 +67,15 @@ export default class ApiManager {
callback = null,
setApis,
) => new Promise(async (resolve, reject) => {
if (isEqual(options, this.enabledOptions)) {
if (callback) {
callback(true, null);
}

resolve(true);
return;
}

const {
apiKey = '',
providerUrl = '',
Expand Down Expand Up @@ -92,7 +103,7 @@ export default class ApiManager {
}

if (!shouldReject) {
resolve(!!error);
resolve(!error);
} else if (!callback) {
reject(error);
}
Expand Down Expand Up @@ -178,6 +189,8 @@ export default class ApiManager {
callback(true, null);
}

this.enabledOptions = options;

doResolved({
aztecAccount,
});
Expand Down

0 comments on commit 5e2fd22

Please sign in to comment.