Skip to content

Commit

Permalink
updated wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlwn123 committed Sep 4, 2024
1 parent d865ba8 commit f8e98d1
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 129 deletions.
5 changes: 1 addition & 4 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/cli/changelog",
{ "repo": "alexlwn123/fedimint-ts" }
],
"changelog": "@changesets/cli/changelog",
"commit": false,
"access": "public",
"baseBranch": "main",
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: pnpm publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
55 changes: 55 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Verify
on:
workflow_call:
workflow_dispatch:

jobs:
lint:
name: Lint
permissions:
contents: write
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-deps

- name: Lint repo
run: pnpm lint:repo

- name: Lint code
run: pnpm lint

build:
name: Build
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-deps

- name: Build
run: pnpm build

types:
name: Types
needs: lint
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-deps

- name: Check types
run: pnpm typecheck
4 changes: 2 additions & 2 deletions examples/vite-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ This is an example application demonstrating the usage of Fedimint client in a s
1. Clone the repository and navigate to the example directory:

```
git clone https://github.com/alexlwn123/fedimint-client-ts.git
cd fedimint-client-ts/examples/vite-core
git clone https://github.com/fedimint/fedimint-web-sdk.git
cd fedimint-web-sdk/examples/vite-core
```

2. Install dependencies:
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean:deep": "pnpm run clean && rm -rf node_modules"
},
"dependencies": {
"fedimint-web": "workspace:*",
"@fedimint/fedimint-web": "workspace:*",
"react": "^18.3.1",
"react-dom": ">=18.3.1"
},
Expand Down
43 changes: 21 additions & 22 deletions examples/vite-core/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import { wallet } from './wallet'

function App() {
const App = () => {
useEffect(() => {
return () => {
wallet?.cleanup().catch(console.error)
Expand All @@ -16,7 +16,7 @@ function App() {
)
}

function Header() {
const Header = () => {
return (
<header>
<h1>Fedimint Typescript Library Demo</h1>
Expand All @@ -25,7 +25,7 @@ function Header() {
)
}

function Main() {
const Main = () => {
return (
<main>
<Wallet />
Expand All @@ -35,41 +35,40 @@ function Main() {
)
}

function Wallet() {
const Wallet = () => {
const [balance, setBalance] = useState(0)
const [error, setError] = useState(0)

const refreshBalance = async () => {
// TODO: Implement balance refresh logic
console.log('Refreshing balance...', wallet)
await wallet
?.getBalance()
.then((b) => {
console.warn('balance', b)
setBalance(b)
})
.catch((e) => {
console.log('Error refreshing balance', e)
})
try {
const bal = await wallet?.getBalance()
console.warn('balance', bal)
setBalance(bal || 0)
} catch (e) {
console.log('Error refreshing balance', e)
setError(e?.message)
}
}

return (
<div className="section">
<h3>Fedimint Wallet</h3>
<div className="row">
<strong>Balance:</strong>
<div className="row">
<div className="balance">{balance}</div>
sats
<button type="button" onClick={refreshBalance}>
refresh
</button>
</div>
<div className="balance">{balance}</div>
sats
<button type="button" onClick={refreshBalance}>
refresh
</button>
</div>
{error && <div className="error">{error}</div>}
</div>
)
}

function RedeemEcash() {
const RedeemEcash = () => {
const [ecashInput, setEcashInput] = useState('')

const handleSubmit = (e: React.FormEvent) => {
Expand Down Expand Up @@ -97,7 +96,7 @@ function RedeemEcash() {
)
}

function PayLightning() {
const PayLightning = () => {
const [lightningInput, setLightningInput] = useState('')

const handleSubmit = (e: React.FormEvent) => {
Expand Down
20 changes: 20 additions & 0 deletions examples/vite-core/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
font-weight: 400;
line-height: 1.5;
text-rendering: optimizeLegibility;
margin: 1rem;

-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand All @@ -19,3 +20,22 @@
color: #181818;
}
}

button {
color: rgba(255, 255, 255, 0.87);
border-radius: 8px;
border: none;
padding: 0.3em 1em;
cursor: pointer;
}

.row {
display: flex;
flex-direction: row;
align-items: center;
gap: 0.5rem;
}

.error {
color: red;
}
19 changes: 11 additions & 8 deletions examples/vite-core/src/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { FedimintWallet } from 'fedimint-web'
import { FedimintWallet } from '@fedimint/fedimint-web'

const inviteCode =
'fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75'

await FedimintWallet.initWasm()
export const wallet = await FedimintWallet.joinFederation(
'CLIENT_NAME1',
inviteCode,
).then((res) => {
console.warn('JOINED', res)
return res
await FedimintWallet.initWasm().catch((err) => {
console.warn('INIT FAILED', err)
})
export const wallet = await FedimintWallet.open('CLIENT_NAME1')
.then((res) => {
console.warn('JOINED', res)
return res
})
.catch((e) => {
console.warn('JOIN FAILED', e)
})
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"preinstall": "pnpx only-allow pnpm",
"prepare": "pnpm simple-git-hooks",
"publish": "pnpm run build && pnpm changesets publish",
"typecheck": "pnpm run --r --parallel typecheck && tsc --noEmit",
"changeset": "changesets",
"version": "changesets version",
"typecheck": "pnpm run --r --parallel typecheck",
"format": "prettier --write .",
"watch": "pnpm run --r --parallel --filter \"./packages/**\" watch"
},
Expand Down
10 changes: 8 additions & 2 deletions packages/fedimint-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"name": "fedimint-web",
"version": "0.0.5",
"name": "@fedimint/fedimint-web",
"description": "Library for building web apps with a fedimint client",
"version": "0.0.0-alpha.1",
"repository": {
"type": "git",
"url": "https://github.com/fedimint/fedimint-web-sdk.git",
"directory": "packages/fedimint-web"
},
"scripts": {
"build": "pnpm run clean && tsc --project tsconfig.json",
"clean": "rm -rf dist tsconfig.tsbuildinfo",
Expand Down
4 changes: 1 addition & 3 deletions packages/fedimint-web/src/FedimintWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ type Body = string | null | Record<string, string>
export class FedimintWallet {
// private _client: InitOutput;
private _fed: WasmClient
static initWasm = async () => {
return await init()
}
static initWasm = init

private constructor(wasm: WasmClient) {
this._fed = wasm
Expand Down
16 changes: 10 additions & 6 deletions packages/fedimint-web/wasm/fedimint_client_wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ export interface InitOutput {
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hc084c31f1f28c9b8: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4dd814b8ece8133b: (a: number, b: number) => void;
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hc4ce6c5cec9839fc: (a: number, b: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h9e6e02ca82bce998: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h68e3ee1a8a347c24: (a: number, b: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h30ddf3bee31ebb33: (a: number, b: number, c: number, d: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h31a94cc9a05d5ca0: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4d11ec113460b95d: (a: number, b: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he7056307c6986185: (a: number, b: number, c: number, d: number) => void;
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5b16159cdfa166b0: (a: number, b: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hebf1bd391d12b3cb: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h09ee3e3abd173580: (a: number, b: number) => void;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
readonly __wbindgen_exn_store: (a: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h1ded20bdc1d87605: (a: number, b: number, c: number, d: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h8bdaa9faeb7d5075: (a: number, b: number, c: number, d: number) => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
Expand Down
Loading

0 comments on commit f8e98d1

Please sign in to comment.