Skip to content

Commit

Permalink
modifying provider and config/state initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Jul 15, 2021
1 parent aa417d8 commit e69de03
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/assets/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export class TokensController extends BaseController<
TokensState
> {
private mutex = new Mutex();

private ethersProvider: any;

private failSuggestedAsset(
Expand Down Expand Up @@ -142,32 +141,39 @@ export class TokensController extends BaseController<
{
onPreferencesStateChange,
onNetworkStateChange,
config,
state,
}: {
onPreferencesStateChange: (
listener: (preferencesState: PreferencesState) => void,
) => void;
onNetworkStateChange: (
listener: (networkState: NetworkState) => void,
) => void;
config?: Partial<TokensConfig>,
state?: Partial<TokensState>,
},
config?: Partial<TokensConfig>,
state?: Partial<TokensState>,
) {
super(config, state);

this.defaultConfig = {
networkType: MAINNET,
selectedAddress: '',
chainId: '',
provider: undefined,
...config,
};

this.defaultState = {
allTokens: {},
ignoredTokens: [],
suggestedAssets: [],
tokens: [],
...state,
};

this.initialize();

onPreferencesStateChange(({ selectedAddress }) => {
const { allTokens } = this.state;
const { chainId } = this.config;
Expand All @@ -181,16 +187,13 @@ export class TokensController extends BaseController<
const { selectedAddress } = this.config;
const { chainId } = provider;
this.configure({ chainId });
this.ethersProvider = new ethers.providers.Web3Provider(this.config?.provider);
this.update({
tokens: allTokens[selectedAddress]?.[chainId] || [],
});
});
}

configureProvider(provider: any) {
this.ethersProvider = new ethers.providers.Web3Provider(provider);
}

/**
* Adds a token to the stored token list
*
Expand Down

0 comments on commit e69de03

Please sign in to comment.