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

feat: stated a LIT package #101

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
24 changes: 24 additions & 0 deletions packages/lit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
25 changes: 25 additions & 0 deletions packages/lit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@fedimint/lit",
"version": "0.0.0",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"source": "src/index.ts",
"scripts": {
"dev": "vite",
"build": "tsc --noEmit && vite build",
"clean": "rm -rf dist",
"preview": "vite preview"
},
"dependencies": {
"lit": "^3.2.1"
},
"peerDependencies": {
"@fedimint/core-web": "workspace:*"
},
"devDependencies": {
"typescript": "~5.6.2",
"vite": "^5.4.10",
"vite-plugin-wasm": "^3.3.0"
}
}
64 changes: 64 additions & 0 deletions packages/lit/src/fedimint-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { LitElement, html } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import { FedimintWallet } from '@fedimint/core-web'
import { wallet } from './fedimint'

/**
* An example element.
*
* @slot - This element has a slot
* @csspart button - The button
*/
@customElement('fedimint-wallet')
export class Fedimint extends LitElement {
wallet: FedimintWallet

private _balanceCleanup: undefined | (() => void)

private _setupSubscriptions() {
this._balanceCleanup = this.wallet.balance.subscribeBalance(
(balanceMsats) => {
console.warn('balance', balanceMsats)
this.balance = balanceMsats / 1000
},
)
}

private _teardownSubscriptions() {
this._balanceCleanup?.()
}

constructor() {
super()
this.wallet = wallet
}

async connectedCallback() {
super.connectedCallback()
console.warn('connectedCallback')
const isOpen = await this.wallet.open()
console.warn('isOpen', isOpen)
if (isOpen) {
this._setupSubscriptions()
}
}

disconnectedCallback() {
console.warn('disconnectedCallback')
super.disconnectedCallback()
this._teardownSubscriptions()
}

@property({ type: Number, reflect: true })
balance = 0

render() {
return html` <p>Balance is ${this.balance}</p> `
}
}

declare global {
interface HTMLElementTagNameMap {
'fedimint-wallet': Fedimint
}
}
12 changes: 12 additions & 0 deletions packages/lit/src/fedimint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { FedimintWallet } from '@fedimint/core-web'

const wallet = new FedimintWallet()

// @ts-ignore
globalThis.wallet = wallet

wallet.setLogLevel('debug')

wallet.open()

export { wallet }
1 change: 1 addition & 0 deletions packages/lit/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './fedimint-wallet'
31 changes: 31 additions & 0 deletions packages/lit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"target": "ES2020",
"experimentalDecorators": true,
"useDefineForClassFields": false,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "node",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true,
"plugins": [
{
"name": "ts-lit-plugin",
"strict": true
}
]
},
"include": ["src/*.ts"]
}
40 changes: 40 additions & 0 deletions packages/lit/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { defineConfig } from 'vite'
import { resolve } from 'path'
import wasm from 'vite-plugin-wasm'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [wasm()],

// These worker settings are required
worker: {
format: 'es',
plugins: () => [
wasm(), // Required for wasm
],
},
build: {
target: 'esnext',
sourcemap: true,
minify: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: '@fedimint/lit',
fileName: 'index',
formats: ['es'],
},
rollupOptions: {
external: ['@fedimint/core-web'],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
'@fedimint/core-web': '@fedimint/core-web',
},
},
},
optimizeDeps: {
exclude: ['@fedimint/core-web'],
},
},
})
Loading