Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test context in widget #23

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Sygma Widget UI
# Sygma Widget UI

test signing commit
2 changes: 1 addition & 1 deletion packages/wallet-manager/src/WalletManagerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ export class WalletManagerContextProvider extends LitElement {
}

render() {
return html` <slot></slot>`;
return html`<slot></slot>`;
}
}
17 changes: 17 additions & 0 deletions packages/widget/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Lit-Element App</title>
<script type="module" src="/src/index.ts"></script>
</head>

<body>
<widget-root>
</widget-root>
</body>

</html>
20 changes: 15 additions & 5 deletions packages/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@
"license": "LGPL-3.0-or-later",
"type": "module",
"scripts": {
"build": "tsc --build --clean && tsc --build ./tsconfig.json",
"dev": "tsc --build --clean && tsc --build ./tsconfig.json --watch",
"start": "npm run dev",
"dev": "vite",
"build": "tsc && vite build",
"serve": "tsc && vite preview",
"clean": "rm -rf ./build",
"lint": "eslint 'src/**/*.ts'",
"lint:fix": "yarn run lint --fix"
},
"author": "Sygmaprotocol Product Team",
"dependencies": {
"@buildwithsygma/sygma-sdk-core": "^2.2.0",
"ethers": "5.7.2",
"lit": "^2.8.0"
"@builtwithsygma/sygmaprotocol-wallet-manager": "1.0.0",
"@lit/context": "1.0.0",
"@lit/reactive-element": "2.0.0",
"ethers": "5.7",
"lit": "^3.0.0",
"lit-html": "^3.0.0"
},
"devDependencies": {
"@types/node": "20.8.4",
"typescript": "5.2.2",
"vite": "4.4.11"
}
}
24 changes: 24 additions & 0 deletions packages/widget/src/ConnectDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { consume } from '@lit/context';
import { LitElement, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import {
WalletManagerContext,

Check failure on line 5 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Delete `··`
WalletManagerController

Check failure on line 6 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Delete `··`
} from 'packages/wallet-manager/build';


Check failure on line 9 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Delete `⏎`
@customElement('connect-dialog')
class ConnectDialog extends LitElement {

Check failure on line 11 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

'ConnectDialog' is defined but never used
@consume({ context: WalletManagerContext, subscribe: true })

Check failure on line 12 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Delete `··`
@property({ attribute: false })

Check failure on line 13 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Replace `····` with `··`
walletManager?: WalletManagerController;

Check failure on line 14 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Delete `··`

render() {

Check failure on line 16 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Replace `····` with `··`
if (this.walletManager?.account) {

Check failure on line 17 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Replace `········` with `····`
return html`

Check failure on line 18 in packages/widget/src/ConnectDialog.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Delete `······`

</wallet-manager-context>`;

}
}
}
26 changes: 26 additions & 0 deletions packages/widget/src/connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { consume } from '@lit/context';
import { LitElement, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import {
WalletManagerContext,
WalletManagerController
} from 'packages/wallet-manager/build';

@customElement('connect-dialog')
class ConnectDialog extends LitElement {
@consume({ context: WalletManagerContext, subscribe: true })
@property({ attribute: false })
walletManager?: WalletManagerController;

render() {
if (!this.walletManager || !this.walletManager.account) {
return html`<button @click=${this.walletManager?.connectEvmWallet}>
Connect
</button> `;
} else {
return html`<p>EVM Account: ${this.walletManager.evmWallet?.address}</p>`;
}
}
}

export { ConnectDialog };
1 change: 1 addition & 0 deletions packages/widget/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WidgetRoot } from './widget-root';
14 changes: 14 additions & 0 deletions packages/widget/src/widget-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators.js';
import { WalletManagerContextProvider } from '@builtwithsygma/sygmaprotocol-wallet-manager'

@customElement('widget-root')
class WidgetRoot extends LitElement {
render() {
return html`<wallet-manager-context>
<connect-dialog></connect-dialog>
</wallet-manager-context>`;
}
}

export { WidgetRoot };
20 changes: 20 additions & 0 deletions packages/widget/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'vite';
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig({
base: '/',
build: {
outDir: 'build',
lib: {
entry: 'src/index.ts',
formats: ['es']
},
manifest: true,
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html')
}
}
}
});
Loading
Loading