Skip to content

Commit

Permalink
chore: fix eslint warnings/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sztok7 committed Jan 19, 2024
1 parent f23da2d commit 73dd0e9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 64 deletions.
42 changes: 18 additions & 24 deletions packages/widget/src/components/widget-app/widget-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ export default class WidgetApp extends WidgetMixin(LitElement) {

async getChainId(): Promise<number | undefined> {
if (this.walletManager?.evmWallet?.web3Provider) {
const chainId = (
await this.walletManager?.evmWallet?.web3Provider?.getNetwork()
)?.chainId;
return chainId;
return (await this.walletManager?.evmWallet?.web3Provider?.getNetwork())
?.chainId;
}
}

Expand All @@ -36,7 +34,6 @@ export default class WidgetApp extends WidgetMixin(LitElement) {
this.requestUpdate();
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.walletManager?.addChainChangedEventListener(async () => {
this.chainId = (
await this.walletManager?.evmWallet?.web3Provider?.getNetwork()
Expand All @@ -49,24 +46,20 @@ export default class WidgetApp extends WidgetMixin(LitElement) {

// listen to the custom event for network change
addEventListener('network-change', (event: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { detail } = event as CustomEvent;
const { detail } = event as CustomEvent<string>;
this.selectedNetworkChainId = Number(detail);
this.requestUpdate();
});

addEventListener('amount-selector-change', (event: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { detail } = event as CustomEvent;
const { detail } = event as CustomEvent<string>;
this.selectedAmount = Number(detail);
this.requestUpdate();
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
addEventListener('token-change', async (event: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { detail } = event as CustomEvent;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
addEventListener('token-change', (event: unknown) => {
const { detail } = event as CustomEvent<string>;

this.selectedToken = detail;

const tokenInfo = this.resources?.find(
Expand All @@ -77,19 +70,20 @@ export default class WidgetApp extends WidgetMixin(LitElement) {

if (this.homechain?.type === Network.EVM) {
this.selectedTokenAddress = (tokenInfo as EvmResource).address;
await this.fetchTokenBalance();
}

this.requestUpdate();
void this.fetchTokenBalance().then(() => this.requestUpdate());
} else {
this.requestUpdate();
}
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
addEventListener('connectionInitialized', async (event: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { detail } = event as CustomEvent;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (detail.connectionInitiliazed) {
await this.connect();
addEventListener('connectionInitialized', (event: unknown) => {
const { detail } = event as CustomEvent<{
connectionInitialized: boolean;
}>;

if (detail.connectionInitialized) {
void this.connect();
}
});
}
Expand Down
5 changes: 0 additions & 5 deletions packages/widget/src/components/widget-app/widget-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ const WidgetMixin = <T extends Constructor<LitElement>>(

@state()
tokenName?: string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(...rest: any[]) {
super(rest);
}
}

return Mixin as Constructor<IWidgetMixin> & T;
Expand Down
6 changes: 3 additions & 3 deletions packages/widget/src/components/widget-app/widget-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ export class WidgetView extends LitElement {
tokenBalance?: string;

@state()
connectionInitiliazed: boolean = false;
connectionInitialized: boolean = false;

initConnect = (): void => {
this.connectionInitiliazed = true;
this.connectionInitialized = true;
dispatchEvent(
new CustomEvent('connectionInitialized', {
detail: { connectionInitiliazed: this.connectionInitiliazed },
detail: { connectionInitialized: this.connectionInitialized },
bubbles: true,
composed: true
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ export class SdkManagerContextProvider extends LitElement {
);
}

// eslint-disable-next-line @typescript-eslint/require-await
async connectedCallback(): Promise<void> {
connectedCallback(): void {
super.connectedCallback();

this.walletManager?.addAccountChangedEventListener(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export class WalletManagerController implements IWalletManagerController {

if (network === Network.EVM) {
this.initWeb3Provider(initArgument.web3Provider);
} else if (network === Network.SUBSTRATE) {
this.initFromApiPromise(initArgument as ApiPromise);
// eslint-disable-next-line no-dupe-else-if
} else if (network === Network.SUBSTRATE && initArgument.apiPromise) {
this.initFromApiPromise(initArgument.apiPromise);
} else if (network === Network.SUBSTRATE && initArgument.wssConnectionUrl) {
void this.initFromWssProvider(initArgument as string);
}
Expand All @@ -45,18 +44,21 @@ export class WalletManagerController implements IWalletManagerController {
public addAccountChangedEventListener(
callback: (account: string) => void
): void {
this.evmWallet?.addListener(customEVMEvents.ACCOUNT_CHANGE, (account) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.account = account;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
callback(account);
});
this.evmWallet?.addListener(
customEVMEvents.ACCOUNT_CHANGE,
(account: string) => {
this.account = account;
callback(account);
}
);
}

public addChainChangedEventListener(callback: () => void): void {
public addChainChangedEventListener(
callback: () => void | Promise<void>
): void {
this.evmWallet?.addListener(customEVMEvents.CHAIN_CHANGE, () => {
this.account = this.evmWallet?.address;
callback();
void callback();
});
}

Expand Down
36 changes: 17 additions & 19 deletions packages/widget/src/controllers/wallet-manager/wallets/Evm/Evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,44 @@ class EvmWallet extends events.EventEmitter implements IEvmWallet {
private appendProviderEvents(): void {
checkWindow();

// eslint-disable-next-line @typescript-eslint/no-misused-promises
(this.web3Provider.provider as Provider).on('connect', async () => {
(this.web3Provider.provider as Provider).on('connect', () => {
this.reconnectToProvider();
await this.resetAccounts();

void this.resetAccounts();
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
(this.web3Provider.provider as Provider).on('disconnect', async () => {
(this.web3Provider.provider as Provider).on('disconnect', () => {
this.reconnectToProvider();
await this.resetAccounts();

void this.resetAccounts();
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
(this.web3Provider.provider as Provider).on('chainChanged', async () => {
(this.web3Provider.provider as Provider).on('chainChanged', () => {
this.reconnectToProvider();
await this.resetAccounts();

this.emit(customEVMEvents.CHAIN_CHANGE, this.web3Provider);
void this.resetAccounts().then(() => {
this.emit(customEVMEvents.CHAIN_CHANGE, this.web3Provider);
});
});

(this.web3Provider.provider as Provider).on(
'accountsChanged',
// eslint-disable-next-line @typescript-eslint/no-misused-promises
async (accounts: string[]) => {
(accounts: string[]) => {
this.reconnectToProvider();
await this.resetAccounts(accounts);

this.emit(customEVMEvents.ACCOUNT_CHANGE, this.address);
void this.resetAccounts(accounts).then(() => {
this.emit(customEVMEvents.ACCOUNT_CHANGE, this.address);
});
}
);
}

public async connect(): Promise<void> {
checkWindow();

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const accounts = await this.web3Provider.provider.request!({
const accounts = (await this.web3Provider.provider.request!({
method: 'eth_requestAccounts'
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
})) as Array<string>;

this.address = accounts[0];
this.signer = this.web3Provider.getSigner();
}
Expand Down

0 comments on commit 73dd0e9

Please sign in to comment.