Skip to content

Commit

Permalink
feat: walletd-js
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed May 3, 2024
1 parent 78fe2e6 commit 9093112
Show file tree
Hide file tree
Showing 20 changed files with 601 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-llamas-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/walletd-js': minor
---

Introduced a new walletd-js library.
6 changes: 6 additions & 0 deletions .changeset/silent-pillows-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@siafoundation/walletd-js': patch
'@siafoundation/walletd-types': patch
---

Organized walletd types and constants.
4 changes: 4 additions & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
siad
sia
renterd
hostd
walletd
js
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ User interfaces for the Sia software. The latest Sia software takes a modular ap
The Sia web libraries provide developers with convenient TypeScript SDKs for using Sia core types, blockchain utilities, data fetching, daemon-specific React hooks, and components for common functionality such as Siacoin/fiat input fields, transaction lists, files, and more.

- [@siafoundation/sdk](libs/sdk) - SDK for interacting directly with the Sia network from browsers and web clients.
- [@siafoundation/renterd-types](libs/renterd-types) - Types for `renterd`.
- [@siafoundation/renterd-js](libs/renterd-js) - SDK for interacting with `renterd`.
- [@siafoundation/renterd-react](libs/renterd-react) - React hooks for interacting with `renterd`.
- [@siafoundation/hostd-types](libs/hostd-types) - Types for `hostd`.
- [@siafoundation/renterd-types](libs/renterd-types) - Types for `renterd`.
- [@siafoundation/hostd-react](libs/hostd-react) - React hooks for interacting with `hostd`.
- [@siafoundation/walletd-types](libs/walletd-types) - Types for `walletd`.
- [@siafoundation/hostd-types](libs/hostd-types) - Types for `hostd`.
- [@siafoundation/walletd-js](libs/walletd-js) - SDK for interacting with `walletd`.
- [@siafoundation/walletd-react](libs/walletd-react) - React hooks for interacting with `walletd`.
- [@siafoundation/walletd-types](libs/walletd-types) - Types for `walletd`.
- [@siafoundation/design-system](libs/design-system) - React-based design system used across Sia apps and websites.
- [@siafoundation/sia-central-types](libs/sia-central-types) - Types for the Sia Central API.
- [@siafoundation/sia-central-js](libs/sia-central-js) - SDK for interacting with the Sia Central API.
Expand Down
4 changes: 2 additions & 2 deletions apps/walletd/config/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { syncerPeersKey } from '@siafoundation/walletd-react'
import { syncerPeersRoute } from '@siafoundation/walletd-types'

export const routes = {
home: '/',
Expand All @@ -15,4 +15,4 @@ export const routes = {
login: '/login',
}

export const connectivityRoute = syncerPeersKey
export const connectivityRoute = syncerPeersRoute
12 changes: 12 additions & 0 deletions libs/walletd-js/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
21 changes: 21 additions & 0 deletions libs/walletd-js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"rules": {
"@nx/dependency-checks": [
"error",
{
"ignoredFiles": ["libs/walletd-js/rollup.config.js"]
}
]
},
"overrides": [
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
30 changes: 30 additions & 0 deletions libs/walletd-js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# walletd-js

SDK for interacting with `walletd`.

## Installation

```sh
npm install @siafoundation/walletd-js
```

## Usage

```js
import { Walletd } from '@siafoundation/walletd-js'

const walletd = Walletd({
api: 'http://localhost:9980/api',
password: 'password1337',
})

const events = await walletd.walletEvents({
params: {
id: 'wallet-1',
limit: 10,
offset: 0,
},
})
const peers = await walletd.syncerPeers()
console.log(events.data, peers.data)
```
17 changes: 17 additions & 0 deletions libs/walletd-js/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable */
export default {
displayName: 'walletd-js',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': [
'babel-jest',
{
presets: ['@nx/next/babel'],
plugins: ['@babel/plugin-transform-private-methods'],
},
],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/walletd-js',
}
11 changes: 11 additions & 0 deletions libs/walletd-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@siafoundation/walletd-js",
"description": "SDK for interacting with `walletd`.",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@siafoundation/request": "0.2.0",
"@siafoundation/walletd-types": "0.1.0"
},
"types": "./src/index.d.ts"
}
42 changes: 42 additions & 0 deletions libs/walletd-js/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "walletd-js",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/walletd-js/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/walletd-js",
"tsConfig": "libs/walletd-js/tsconfig.lib.json",
"project": "libs/walletd-js/package.json",
"entryFile": "libs/walletd-js/src/index.ts",
"external": ["react/jsx-runtime"],
"compiler": "tsc",
"outputFileName": "index.js",
"rollupConfig": "libs/walletd-js/rollup.config.js",
"assets": [
{
"glob": "libs/walletd-js/*.md",
"input": ".",
"output": "."
}
]
},
"configurations": {}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/libs/walletd-js"],
"options": {
"jestConfig": "libs/walletd-js/jest.config.ts"
}
}
}
}
18 changes: 18 additions & 0 deletions libs/walletd-js/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const preserveDirectives = require('rollup-plugin-preserve-directives')

// https://github.com/rollup/rollup/issues/4699#issuecomment-1465302665
function getRollupOptions(options) {
return {
...options,
output: {
...options.output,
preserveModules: true,
format: 'esm',
sourcemap: true,
},
plugins: options.plugins.concat(preserveDirectives.default()),
}
}

module.exports = getRollupOptions
18 changes: 18 additions & 0 deletions libs/walletd-js/src/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Walletd } from '.'

export async function example() {
const walletd = Walletd({
api: 'http://localhost:9980/api',
password: 'password1337',
})

const events = await walletd.walletEvents({
params: {
id: 'wallet-1',
limit: 10,
offset: 0,
},
})
const peers = await walletd.syncerPeers()
console.log(events.data, peers.data)
}
Loading

0 comments on commit 9093112

Please sign in to comment.