Skip to content

Commit

Permalink
Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Feb 16, 2024
1 parent 4cd4bac commit b81e010
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 29 deletions.
78 changes: 54 additions & 24 deletions packages/thorin-core/src/connect-modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`
Expand All @@ -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();
}}"
>
<div class="space-y-2">
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions packages/thorin-core/src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export class ThorinModal extends LitElement {
@property({ type: Boolean })
closeOnRequest = true;

@property()
onClose?: () => void;

static override styles = css`
:host {
display: none;
Expand Down Expand Up @@ -164,8 +161,7 @@ export class ThorinModal extends LitElement {
}

close() {
this.onClose?.();
this.open = false;
this.dispatchEvent(new CustomEvent('onClose'));
}

override firstUpdated() {
Expand Down
8 changes: 8 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,17 @@ <h2>Modals</h2>
<script>
function opentestmodal() {
document.getElementById("testmodal").open = true;
document.getElementById("testmodal").addEventListener("onClose", () => {
console.log("modal closed");
document.getElementById("testmodal").open = false;
});
}
function openconnectmodal() {
document.getElementById("connectmodal").open = true;
document.getElementById("connectmodal").addEventListener("onClose", () => {
console.log("connectmodal closed");
document.getElementById("connectmodal").open = false;
});
}

let height = 5;
Expand Down

0 comments on commit b81e010

Please sign in to comment.