Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Feature/web3 provider #6

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ lerna.json
esbuild.js
babel.config.json
babel.config.node.json

8 changes: 4 additions & 4 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module.exports = {
...baseConfig,
roots: ['<rootDir>/src'],
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)"
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)',
],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest"
'^.+\\.(ts|tsx)$': 'ts-jest',
},
moduleNameMapper: {
"^@/(.*)": "<rootDir>/src/$1",
'^@/(.*)': '<rootDir>/src/$1',
},
}
25 changes: 19 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,34 @@
"lint": "eslint packages/* --ext .ts,.tsx --fix",
"build": "lerna run build",
"docs": "typedoc --options typedoc.json",
"test": "jest --verbose true",
"test": "jest --verbose true --coverage",
"test:watch": "jest --watch"
},
"devDependencies": {
"@babel/cli": "^7.18.10",
"@babel/core": "^7.19.1",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.19.1",
"@babel/preset-env": "^7.19.1",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^26.0.21",
"@types/lodash": "^4.14.184",
"@types/node": "^18.7.23",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0",
"babel-plugin-root-import": "^6.6.0",
"esbuild": "^0.15.9",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.1.2",
"lerna": "^5.1.8",
"node-stdlib-browser": "^1.2.0",
"prettier": "^2.7.1",
"ts-jest": "^29.0.0",
"tsc-alias": "^1.7.0",
"typedoc": "^0.23.8",
"yorkie": "^2.0.0",
"@types/jest": "^26.0.21",
"jest": "^26.6.3",
"ts-jest": "^26.5.4"
"typescript": "^4.8.3",
"yorkie": "^2.0.0"
}
}
39 changes: 39 additions & 0 deletions packages/json-api-client/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/.github/
/.vscode/
/node_modules/
packages/**/node_modules/
/tmp/
.idea/*
/docs/

coverage
*.log

package-lock.json
/*.tgz
/tmp*
/mnt/
/package/
/src/test/
*.test.ts

npm-debug.log*
yarn-debug.log*
yarn-error.log*
babel-debug.log

.browserslistrc
.editorconfig
.eslintignore
.eslintrc.js
.gitlab-ci.yml
jest.config.js
.prettierrc
tsconfig.json
tsconfig.base.json
lerna.json
/scripts/
esbuild.js
babel.config.json
babel.config.node.json

2 changes: 1 addition & 1 deletion packages/json-api-client/src/helpers/case-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function convertCaseDeep<T>(object: T, converter: CaseConverter): T {
if (isPlainObject(object)) {
const convertedObject: Record<string, unknown> = {}

Object.keys(object).forEach(key => {
Object.keys(object as Record<string, unknown>).forEach(key => {
const objectRecord = object as Record<string, unknown>
convertedObject[toCase(key, converter)] = convertCaseDeep(
objectRecord[key],
Expand Down
6 changes: 2 additions & 4 deletions packages/json-api-client/src/json-api.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import axios from 'axios'
import { RAW_RESPONSE, PARSED_RESPONSE } from './test'
import { JsonApiClient } from './json-api'
import { mocked } from 'ts-jest/utils'
import { MockWrapper } from './test'

jest.mock('axios')

const mockedAxios = mocked(axios, true)
const mockedAxios = axios as jest.MockedFunction<typeof axios>

const mockedData = {
foo: {
Expand Down Expand Up @@ -171,12 +170,11 @@ describe('performs JsonApiClient request unit test', () => {
})
})

test('should return correct data', () => {
test('should return correct data', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove

const rawResponse = MockWrapper.makeAxiosResponse(RAW_RESPONSE)
mockedAxios.mockResolvedValueOnce(rawResponse)

const api = new JsonApiClient({ baseUrl: 'http://localhost:8095' })

return api.get('').then(({ data }) => expect(data).toEqual(PARSED_RESPONSE))
})
})
39 changes: 39 additions & 0 deletions packages/utils/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/.github/
/.vscode/
/node_modules/
packages/**/node_modules/
/tmp/
.idea/*
/docs/

coverage
*.log

package-lock.json
/*.tgz
/tmp*
/mnt/
/package/
/src/test/
*.test.ts

npm-debug.log*
yarn-debug.log*
yarn-error.log*
babel-debug.log

.browserslistrc
.editorconfig
.eslintignore
.eslintrc.js
.gitlab-ci.yml
jest.config.js
.prettierrc
tsconfig.json
tsconfig.base.json
lerna.json
/scripts/
esbuild.js
babel.config.json
babel.config.node.json

2 changes: 1 addition & 1 deletion packages/utils/src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dayjs, {
} from 'dayjs'
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
import { IsoDate, UnixDate } from '../types/date'
import { IsoDate, UnixDate } from './types'

export class DateUtil {
private static _dayjs(date: ConfigType, format?: OptionType): Dayjs {
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './promise-helpers'
3 changes: 3 additions & 0 deletions packages/utils/src/helpers/promise-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './math'
export * from './date'
export * from '../types/index'
export * from './helpers'
39 changes: 39 additions & 0 deletions packages/web3-provider/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/.github/
/.vscode/
/node_modules/
packages/**/node_modules/
/tmp/
.idea/*
/docs/

coverage
*.log

package-lock.json
/*.tgz
/tmp*
/mnt/
/package/
/src/test/
*.test.ts

npm-debug.log*
yarn-debug.log*
yarn-error.log*
babel-debug.log

.browserslistrc
.editorconfig
.eslintignore
.eslintrc.js
.gitlab-ci.yml
jest.config.js
.prettierrc
tsconfig.json
tsconfig.base.json
lerna.json
/scripts/
esbuild.js
babel.config.json
babel.config.node.json

31 changes: 31 additions & 0 deletions packages/web3-provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# @distributedlab/utils
Typescript-based utils for Distributed Lab projects

![version (scoped package)](https://badgen.net/npm/v/@distributedlab/utils)
![types](https://badgen.net/npm/types/@distributedlab/utils)
![tree-shaking](https://badgen.net/bundlephobia/tree-shaking/@distributedlab/utils)
![checks](https://badgen.net/github/checks/distributed-lab/web-kit/main)

## Changelog
ArtSuslov marked this conversation as resolved.
Show resolved Hide resolved
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
<details><summary>1.0.0</summary>
<h4>Under the hood changes</h4>
<ul>
<li>Initiated project</li>
</ul>
</details>
<details><summary>1.0.1</summary>
<h4>Fixed</h4>
<ul>
<li>Readme</li>
</ul>
</details>
<details><summary>1.0.2</summary>
<h4>Fixed</h4>
<ul>
<li>@babel/runtime dependency</li>
</ul>
</details>
3 changes: 3 additions & 0 deletions packages/web3-provider/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../babel.config.base.json"
}
3 changes: 3 additions & 0 deletions packages/web3-provider/babel.config.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../babel.config.base.node.json"
}
22 changes: 22 additions & 0 deletions packages/web3-provider/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

const esbuild = require('esbuild')
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin')
const stdLibBrowser = require('node-stdlib-browser')

;(async () => {
await esbuild.build({
entryPoints: ['src/browser.ts'],
bundle: true,
minify: true,
sourcemap: 'external',
outfile: 'lib/web3-provider.min.js',
inject: [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
define: {
global: 'global',
process: 'process',
Buffer: 'Buffer',
},
plugins: [plugin(stdLibBrowser)],
})
})()
5 changes: 5 additions & 0 deletions packages/web3-provider/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const baseConfig = require('../../jest.config.base')

module.exports = {
...baseConfig,
}
43 changes: 43 additions & 0 deletions packages/web3-provider/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@distributedlab/web3-provider",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about rename it to @distributedlab/web3

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a lib to work with providers, and web3 - is a common term and can we like web3.js, etc...

"description": "Web3 Provider",
"version": "1.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.0.0

"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"browser": "./lib/web3-provider.min.js",
"unpkg": "./lib/web3-provider.min.js",
"types": "./lib/types/index.d.ts",
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
}
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"displayName": "@distributedlab/web3-provider"
},
"sideEffects": false,
"scripts": {
"type-check": "tsc --noEmit",
"build": "yarn clean && yarn build:types && yarn build:cjs && yarn build:esm && yarn build:browser",
"build:cjs": "babel src --out-dir lib/cjs --extensions \".ts,.tsx\" --config-file ./babel.config.node.json",
"build:esm": "babel src --out-dir lib/esm --extensions \".ts,.tsx\" --config-file ./babel.config.json",
"build:types": "tsc --emitDeclarationOnly && tsc-alias -p tsconfig.json",
"build:browser": "node ./esbuild.js",
"clean": "rm -rf lib"
},
"dependencies": {
"@babel/runtime": "^7.19.0",
"@distributedlab/utils": "*",
"@solana/web3.js": "^1.63.1",
"@vue/reactivity": "^3.2.39",
"bs58": "^5.0.0",
"ethers": "^5.7.1"
}
}
10 changes: 10 additions & 0 deletions packages/web3-provider/src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file is the entrypoint of browser builds.
* The code executes when loaded in a browser.
*/
import * as Web3Provider from './index'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(window as any).webKitWeb3Provider = Web3Provider

console.warn('Web3 provider was added to the window object.')
1 change: 1 addition & 0 deletions packages/web3-provider/src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useProvider'
3 changes: 3 additions & 0 deletions packages/web3-provider/src/composables/useProvider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './use-provider'
export * from './providers'
export * from './use-web3'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './use-coinbase'
export * from './use-metamask'
export * from './use-solflare'
export * from './use-phantom'
Loading