From b81e0104ce2918ff0e04ee7d91b9bd174215d9d9 Mon Sep 17 00:00:00 2001 From: Luc Date: Fri, 16 Feb 2024 03:38:23 +0000 Subject: [PATCH] Bump --- .../thorin-core/src/connect-modal/index.ts | 78 +++++++++++++------ packages/thorin-core/src/modal/index.ts | 6 +- web/index.html | 8 ++ 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/packages/thorin-core/src/connect-modal/index.ts b/packages/thorin-core/src/connect-modal/index.ts index 24d0f97..a6774cd 100644 --- a/packages/thorin-core/src/connect-modal/index.ts +++ b/packages/thorin-core/src/connect-modal/index.ts @@ -5,29 +5,32 @@ import { walletConnect } from '@wagmi/connectors'; import { type Config, type Connector, - createConfig, + connect, + disconnect, + getConnections, getConnectors, - http, } from '@wagmi/core'; -import { mainnet } from '@wagmi/core/chains'; import { css, html, LitElement } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; -const wagmiConfig = createConfig({ - chains: [mainnet], - transports: { - [mainnet.id]: http(), - }, -}); +let wagmiConfig = {} as Config; + +export const setupConfig = (config: Config) => { + wagmiConfig = config; +}; + +// const wagmiConfig = createConfig({ +// chains: [mainnet], +// transports: { +// [mainnet.id]: http(), +// }, +// }); @customElement('thorin-connect-modal') export class ThorinConnectModal extends LitElement { @property({ type: Boolean, reflect: true }) open = false; - @property({}) - wagmiConfig: Config = wagmiConfig; - static override styles = css` .button-list { display: flex; @@ -126,20 +129,33 @@ export class ThorinConnectModal extends LitElement { console.log(topic, data); } }, - }; - const x = wc({ chains: [mainnet], emitter } as any) as any; + } as any; + const x = wc({ chains: wagmiConfig.chains, emitter }) as any; - this.connectors = [...getConnectors(this.wagmiConfig), x]; + this.connectors = [...getConnectors(wagmiConfig), x]; } override render() { - if (!this.myAddress && this.activeConnector) { + if (!this.connecting) { + this.activeConnector = getConnections(wagmiConfig)[0]?.connector; + } + + if (!this.myAddress && this.activeConnector && !this.connecting) { console.log('computing account'); this.activeConnector.getAccounts().then((accounts) => { - console.log('computing success'); - // eslint-disable-next-line prefer-destructuring + console.log({ accounts }); this.myAddress = accounts[0]; }); + // const x = getAccount(this.wagmiConfig); + + // if (x.address) { + // this.myAddress = x.address; + // } + // .then((accounts) => { + // console.log('computing success'); + // // eslint-disable-next-line prefer-destructuring + // this.myAddress = accounts[0]; + // }); } return html` @@ -148,8 +164,8 @@ export class ThorinConnectModal extends LitElement { modalTitle="${this.activeConnector && !this.connecting ? 'Wallet Settings' : 'Connect Wallet'}" - .onClose="${() => { - this.open = false; + @onClose="${() => { + this.close(); }}" >
@@ -253,25 +269,39 @@ export class ThorinConnectModal extends LitElement { `; } + close() { + this.dispatchEvent(new CustomEvent('onClose')); + } + _connect(connector: Connector) { this.connecting = true; this.activeConnector = connector; console.log(connector); - connector - .connect() + + connect(wagmiConfig, { connector }) .catch((error) => { console.log('failed to connect', error); - this.disconnect(); + this.connecting = false; + // this.disconnect(); }) .finally(() => { this.connecting = false; // this.disconnect(); // this.open = false; + this.activeConnector?.getAccounts()?.then((accounts) => { + console.log({ accounts }); + this.myAddress = accounts[0]; + }); }); } disconnect() { - this.activeConnector?.disconnect(); + disconnect(wagmiConfig).finally(() => { + console.log('disconnected wagmi'); + }); + this.activeConnector?.disconnect().finally(() => { + console.log('disconnected activeConnector'); + }); this.activeConnector = undefined; this.connecting = false; this.showQR = undefined; diff --git a/packages/thorin-core/src/modal/index.ts b/packages/thorin-core/src/modal/index.ts index d98bf4e..dfc32ae 100644 --- a/packages/thorin-core/src/modal/index.ts +++ b/packages/thorin-core/src/modal/index.ts @@ -12,9 +12,6 @@ export class ThorinModal extends LitElement { @property({ type: Boolean }) closeOnRequest = true; - @property() - onClose?: () => void; - static override styles = css` :host { display: none; @@ -164,8 +161,7 @@ export class ThorinModal extends LitElement { } close() { - this.onClose?.(); - this.open = false; + this.dispatchEvent(new CustomEvent('onClose')); } override firstUpdated() { diff --git a/web/index.html b/web/index.html index c475c50..04e0182 100644 --- a/web/index.html +++ b/web/index.html @@ -119,9 +119,17 @@

Modals