diff --git a/packages/widget/src/components/widget-app/widget-app.ts b/packages/widget/src/components/widget-app/widget-app.ts index d46fb578..f4887edf 100644 --- a/packages/widget/src/components/widget-app/widget-app.ts +++ b/packages/widget/src/components/widget-app/widget-app.ts @@ -21,10 +21,8 @@ export default class WidgetApp extends WidgetMixin(LitElement) { async getChainId(): Promise { if (this.walletManager?.evmWallet?.web3Provider) { - const chainId = ( - await this.walletManager?.evmWallet?.web3Provider?.getNetwork() - )?.chainId; - return chainId; + return (await this.walletManager?.evmWallet?.web3Provider?.getNetwork()) + ?.chainId; } } @@ -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() @@ -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; 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; 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; + this.selectedToken = detail; const tokenInfo = this.resources?.find( @@ -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(); } }); } diff --git a/packages/widget/src/components/widget-app/widget-mixin.ts b/packages/widget/src/components/widget-app/widget-mixin.ts index 83685b7b..b7235eef 100644 --- a/packages/widget/src/components/widget-app/widget-mixin.ts +++ b/packages/widget/src/components/widget-app/widget-mixin.ts @@ -69,11 +69,6 @@ const WidgetMixin = >( @state() tokenName?: string; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - constructor(...rest: any[]) { - super(rest); - } } return Mixin as Constructor & T; diff --git a/packages/widget/src/components/widget-app/widget-view.ts b/packages/widget/src/components/widget-app/widget-view.ts index 4db5a283..5843dd58 100644 --- a/packages/widget/src/components/widget-app/widget-view.ts +++ b/packages/widget/src/components/widget-app/widget-view.ts @@ -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 }) diff --git a/packages/widget/src/controllers/sdk-manager/SdkManagerContextProvider.ts b/packages/widget/src/controllers/sdk-manager/SdkManagerContextProvider.ts index 5387283b..7fa07e27 100644 --- a/packages/widget/src/controllers/sdk-manager/SdkManagerContextProvider.ts +++ b/packages/widget/src/controllers/sdk-manager/SdkManagerContextProvider.ts @@ -77,8 +77,7 @@ export class SdkManagerContextProvider extends LitElement { ); } - // eslint-disable-next-line @typescript-eslint/require-await - async connectedCallback(): Promise { + connectedCallback(): void { super.connectedCallback(); this.walletManager?.addAccountChangedEventListener(() => { diff --git a/packages/widget/src/controllers/wallet-manager/WalletManagerController.ts b/packages/widget/src/controllers/wallet-manager/WalletManagerController.ts index 5ea6a0ed..5189a67d 100644 --- a/packages/widget/src/controllers/wallet-manager/WalletManagerController.ts +++ b/packages/widget/src/controllers/wallet-manager/WalletManagerController.ts @@ -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); } @@ -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 { this.evmWallet?.addListener(customEVMEvents.CHAIN_CHANGE, () => { this.account = this.evmWallet?.address; - callback(); + void callback(); }); } diff --git a/packages/widget/src/controllers/wallet-manager/wallets/Evm/Evm.ts b/packages/widget/src/controllers/wallet-manager/wallets/Evm/Evm.ts index 5b4d6fca..81588f5c 100644 --- a/packages/widget/src/controllers/wallet-manager/wallets/Evm/Evm.ts +++ b/packages/widget/src/controllers/wallet-manager/wallets/Evm/Evm.ts @@ -47,34 +47,33 @@ 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); + }); } ); } @@ -82,11 +81,10 @@ class EvmWallet extends events.EventEmitter implements IEvmWallet { public async connect(): Promise { 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; + this.address = accounts[0]; this.signer = this.web3Provider.getSigner(); }