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: walletd-js #616

Merged
merged 1 commit into from
May 3, 2024
Merged
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
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The Sia web libraries provide developers with convenient TypeScript SDKs for usi
- [@siafoundation/hostd-js](libs/hostd-js) - SDK for interacting with `hostd`.
- [@siafoundation/hostd-react](libs/hostd-react) - React hooks for interacting with `hostd`.
- [@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.
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
Loading