Skip to content

Commit

Permalink
Update thorin-core wagmi support & line-height
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Oct 29, 2024
1 parent 6a0cecb commit 17de40c
Show file tree
Hide file tree
Showing 8 changed files with 1,053 additions and 128 deletions.
1 change: 1 addition & 0 deletions packages/thorin-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './src/components/connect-modal/index.js';
export * from './src/components/label/index.js';
export * from './src/components/modal/index.js';
export * from './src/components/tag/index.js';
export * from './src/wagmi.js';
import './index.js';

export const hello = () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/thorin-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ens-tools/thorin-core",
"version": "0.1.3",
"version": "0.1.4-1",
"type": "module",
"main": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
Expand Down Expand Up @@ -31,6 +31,7 @@
"@rollup/plugin-json": "^6.1.0",
"lit": "^3.1.2",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rxjs": "^7.8.1",
"ts-pattern": "^5.5.0",
"webcomponent-qr-code": "^1.2.0"
},
Expand All @@ -48,6 +49,7 @@
"peerDependencies": {
"@wagmi/connectors": "^4.1.14",
"@wagmi/core": "^2.6.5",
"viem": "2.x"
"viem": "2.x",
"wagmi": "^2.12.25"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class ThorinConnectModalConnected extends LitElement {
align-items: center;
gap: var(--thorin-spacing-4);
font-size: 1.1em;
line-height: 1.3;
}
.profile .row-1 .left {
display: flex;
Expand All @@ -90,6 +91,7 @@ export class ThorinConnectModalConnected extends LitElement {
.profile .row-1 .subtext {
color: var(--thorin-text-secondary);
font-size: 0.75em;
line-height: 1.1;
}
.external-link-icon {
width: 16px;
Expand Down
30 changes: 12 additions & 18 deletions packages/thorin-core/src/components/connect-modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import 'webcomponent-qr-code';
import './connected';

// import { walletConnect } from '@wagmi/connectors';
import {
type Config,
type Connection,
type Connector,
type ConnectorEventMap,
Expand All @@ -22,18 +20,7 @@ import { property, state } from 'lit/decorators.js';

import { customElement } from '../../internal/component';
import { styles } from '../../styles';

let getWagmiConfig = () => ({} as Config);

export const setupConfig = (config: Config | (() => Config)) => {
console.log(
'%c[Thorin Connect]',
'color: #3396ff',
'Setting up config',
config
);
getWagmiConfig = typeof config === 'function' ? config : () => config;
};
import { getWagmiConfig } from '../../wagmi.js';

const wcLog = (event: string, ...data: (string | object)[]) => {
console.log(
Expand Down Expand Up @@ -196,12 +183,17 @@ export class ThorinConnectModal extends LitElement {
console.log('updated');
}

override firstUpdated() {
window.addEventListener('wagmiConfigChangedThorin', () => {
this.updateWagmiState();
});
}

override render() {
const wagmiConfig = getWagmiConfig();
const account =
wagmiConfig && wagmiConfig?.state
? getAccount(wagmiConfig)
: undefined;
const account = wagmiConfig // && wagmiConfig?.state
? getAccount(wagmiConfig)
: undefined;

const isWalletConnect = this.activeConnector?.type === 'walletConnect';

Expand All @@ -213,6 +205,8 @@ export class ThorinConnectModal extends LitElement {

const connectors = getConnectors(wagmiConfig);

console.log({ account });

return html`
<thorin-modal
?open="${this.open}"
Expand Down
26 changes: 26 additions & 0 deletions packages/thorin-core/src/wagmi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Config } from '@wagmi/core';

const globalThing: {
config: Config | undefined;
} = {
config: undefined,
};

export const getWagmiConfig = () => {
return globalThing.config;
};

export const THORIN_CONNECT_PREFIX = '%c[Thorin Connect]';

export const setupConfig = (config: Config | (() => Config)) => {
console.log(
THORIN_CONNECT_PREFIX,
'color: #3396ff',
'Setting up config',
config
);
globalThing.config = typeof config === 'function' ? config() : config;
window.dispatchEvent(
new CustomEvent('wagmiConfigChangedThorin', { detail: config })
);
};
1,110 changes: 1,003 additions & 107 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ <h2>Modals</h2>
<thorin-button onClick="openconnectmodal()"
>Open Connect Modal</thorin-button
>
<thorin-button onClick="fakeconnect()"
>Open Connect Modal</thorin-button
>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { setupConfig } from '@ens-tools/thorin-core';
import '@ens-tools/thorin-core/style.css';
import 'webcomponent-qr-code';
import { mainnet, sepolia } from 'wagmi/chains';
import { createConfig, http, injected } from '@wagmi/core'
import { createConfig, createStorage, http, injected } from '@wagmi/core'
import { walletConnect } from '@wagmi/connectors';

const config = createConfig(
Expand All @@ -17,6 +17,7 @@ const config = createConfig(
showQrModal: false,
}),
],
storage: createStorage({ storage: window.localStorage }),
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
Expand Down

0 comments on commit 17de40c

Please sign in to comment.