Skip to content
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"editor.formatOnSave": false,
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
1,533 changes: 984 additions & 549 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"scripts": {
"watch": "webpack --watch",
"generateInterface": "npx ts-node generateInterface.ts",
"bundle:d": "npm run generateInterface && cross-env NODE_ENV=development webpack",
"bundle:p": "npm run generateInterface && cross-env NODE_ENV=production webpack",
"bundle:d": "npm run generateInterface && cross-env NODE_OPTIONS=--openssl-legacy-provider NODE_ENV=development webpack",
"bundle:p": "npm run generateInterface && cross-env NODE_OPTIONS=--openssl-legacy-provider NODE_ENV=production webpack",
"build:cjs": "shx rm -rf dist/cjs && tsc -p tsconfig.build.json -m commonjs --outDir dist/cjs",
"build:es": "shx rm -rf dist/es && tsc -p tsconfig.build.json -m es6 --outDir dist/es",
"build": "shx rm -rf dist && run-p build:* bundle:*",
Expand All @@ -44,6 +44,9 @@
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"moduleNameMapper": {
"^@waves/ts-lib-crypto/conversions/base-xx$": "<rootDir>/node_modules/@waves/ts-lib-crypto/dist/conversions/base-xx.js"
},
"testMatch": [
"**/test/*spec.+(ts)",
"**/test/**/*spec.+(ts)"
Expand All @@ -52,9 +55,11 @@
"dependencies": {
"@types/ramda": "^0.27.32",
"@waves/client-logs": "^1.0.0",
"@waves/node-api-js": "^1.3.0",
"@waves/ts-lib-crypto": "^1.4.3",
"@waves/ts-types": "^1.0.0",
"@waves/node-api-js": "^1.4.0",
"@waves/ts-lib-crypto": "^1.5.2",
"@waves/ts-types": "^1.3.1",
"@waves/waves-transactions": "^5.0.0",
"node-fetch": "^2.6.1",
"ramda": "^0.27.1"
},
"devDependencies": {
Expand All @@ -64,9 +69,8 @@
"@types/node-fetch": "^2.5.3",
"@typescript-eslint/eslint-plugin": "^2.22.0",
"@typescript-eslint/parser": "^2.22.0",
"@waves/js-test-env": "^0.7.4",
"@waves/js-test-env": "^1.1.5",
"@waves/node-state": "0.0.5",
"@waves/waves-transactions": "^4.3.11",
"cross-env": "^7.0.0",
"dotenv": "^8.2.0",
"eslint": "^6.8.0",
Expand All @@ -80,7 +84,6 @@
"fs-extra": "^8.1.0",
"jest": "^24.9.0",
"jest-extended": "^0.11.2",
"node-fetch": "^2.6.1",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"shx": "^0.3.2",
Expand Down
1 change: 1 addition & 0 deletions src/Signer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './fetch';
import { DEFAULT_OPTIONS } from './constants';
import {
AliasArgs,
Expand Down
16 changes: 16 additions & 0 deletions src/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const globalObject: any =
typeof globalThis === 'object'
? globalThis
: typeof self === 'object'
? self
: typeof global === 'object'
? global
: {};

if (typeof globalObject.globalThis === 'undefined') {
globalObject.globalThis = globalObject;
}

if (typeof globalObject.fetch !== 'function') {
globalObject.fetch = require('node-fetch');
}
2 changes: 1 addition & 1 deletion src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import includes from 'ramda/src/includes';
import flip from 'ramda/src/flip';
import always from 'ramda/src/always';
import tryCatch from 'ramda/src/tryCatch';
import { base58Decode } from '@waves/ts-lib-crypto';
import { base58Decode } from '@waves/ts-lib-crypto/conversions/base-xx';

const TX_DEFAULTS = {
MAX_ATTACHMENT: 140,
Expand Down
15 changes: 15 additions & 0 deletions test/fetch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe('fetch compatibility', () => {
const nativeFetch = (global as any).fetch;

afterAll(() => {
(global as any).fetch = nativeFetch;
});

it('provides fetch for Node.js runtimes without a native implementation', () => {
delete (global as any).fetch;

require('../src/fetch');

expect(typeof (global as any).fetch).toBe('function');
});
});
10 changes: 7 additions & 3 deletions test/test-env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import fetch from 'node-fetch';
import { TextDecoder, TextEncoder } from 'util';
import { waitTime } from './utils';

import nodeFetch = require('node-fetch');

(global as any).TextDecoder = (global as any).TextDecoder || TextDecoder;
(global as any).TextEncoder = (global as any).TextEncoder || TextEncoder;

export const NETWORK_BYTE = 87;
export const NODE_URL = 'https://nodes.wavesnodes.com';
export const MOCK_URL = 'https://mock.com';
Expand Down Expand Up @@ -31,7 +36,7 @@ type Fetch = typeof window.fetch;
// @ts-ignore
const f: Fetch = (url: string, options) => {
if (!url.includes(MOCK_URL)) {
return fetch(url, options as any);
return nodeFetch(url, options as any);
}

console.log(`Request ${url}, options: ${JSON.stringify(options, null, 4)}`);
Expand Down Expand Up @@ -69,4 +74,3 @@ const f: Fetch = (url: string, options) => {
};

(global as any).fetch = f;

13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"declaration": false,
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"@waves/ts-types/src": [
"node_modules/@waves/ts-types/dist/src/index.d.ts"
],
"@waves/ts-types/src/parts": [
"node_modules/@waves/ts-types/dist/src/parts.d.ts"
],
"@waves/ts-lib-crypto/conversions/base-xx": [
"node_modules/@waves/ts-lib-crypto/dist/conversions/base-xx.d.ts"
]
},
"lib": [
"es5",
"dom",
Expand Down
11 changes: 11 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ const commonConfig = (mode) => merge([{
],
},
resolve: {
alias: {
'@waves/ts-lib-crypto/conversions/base-xx$': path.join(
PATHS.root,
'node_modules',
'@waves',
'ts-lib-crypto',
'dist',
'conversions',
'base-xx.js'
),
},
extensions: ['.ts', '.tsx', '.js', '.json'],
modules: ['node_modules'],
},
Expand Down