Skip to content

Commit

Permalink
Refactor to merge ViewController and PayloadTransport classes (#203)
Browse files Browse the repository at this point in the history
* (feat): Added 'web3-core' package v1.5.2  to import the new AbstractProvider Type

* (feat): fix #83

* First step to refactoring 'PayloadTransport' into 'ViewController'

* Fix remaining tests

* Update 'peerDependencies' for @magic-sdk/commons

* Fix clean script

Co-authored-by: Adenekan Wonderful <[email protected]>
  • Loading branch information
smithki and adenekan41 committed Sep 2, 2021
1 parent e2ccc67 commit d258eeb
Show file tree
Hide file tree
Showing 73 changed files with 662 additions and 812 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/node_modules
**/coverage
**/dist
**/.eslintrc.js
**/jest.config.ts
Expand Down
42 changes: 24 additions & 18 deletions .eslintrc → .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
{
"root": true,
module.exports = {
root: true,

"extends": ["@ikscodes/eslint-config"],
extends: ["@ikscodes/eslint-config"],

"rules": {
"import/extensions": 0,
rules: {
// ESLint rules
"no-alert": 0,
"@typescript-eslint/await-thenable": 0,
"no-underscore-dangle": 0,
"no-useless-constructor": 0,
"@typescript-eslint/no-useless-constructor": 0,
"@typescript-eslint/no-empty-function": 0,
"class-methods-use-this": 0,

// Import rules
"import/extensions": 0,
"import/no-extraneous-dependencies": 0,

// TypeScript rules
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/no-unsafe-call": 0,
"@typescript-eslint/await-thenable": 0,
"@typescript-eslint/no-unsafe-return": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-floating-promises": 0,
"@typescript-eslint/no-unsafe-assignment": 0,
"@typescript-eslint/no-useless-constructor": 0,
"@typescript-eslint/no-unsafe-member-access": 0,
"@typescript-eslint/no-floating-promises": 0,
"@typescript-eslint/no-unsafe-call": 0,
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/restrict-template-expressions": 0,
"class-methods-use-this": 0,
"import/no-extraneous-dependencies": 0
},

"settings": {
settings: {
"import/resolver": {
"typescript": {
"directory": ["**/tsconfig.json"]
}
}
}
"directory": ["**/tsconfig.json"],
},
},
},
}
1 change: 1 addition & 0 deletions packages/@magic-sdk/commons/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/coverage
/dist
/.eslintrc.js
/jest.config.ts
2 changes: 1 addition & 1 deletion packages/@magic-sdk/commons/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['../../../.eslintrc'],
extends: ['../../../.eslintrc.js'],
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
Expand Down
4 changes: 2 additions & 2 deletions packages/@magic-sdk/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"module": "dist/es/index.js",
"types": "dist/es/index.d.ts",
"peerDependencies": {
"@magic-sdk/provider": "^4.3.0",
"@magic-sdk/types": "^3.1.1",
"@magic-sdk/provider": ">=4.3.0",
"@magic-sdk/types": ">=3.1.1",
"tslib": "^2.0.3"
},
"gitHead": "1ef062ea699d48d5e9a9375a93b7c147632b05ca"
Expand Down
1 change: 1 addition & 0 deletions packages/@magic-sdk/provider/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/coverage
/dist
/.eslintrc.js
/jest.config.ts
2 changes: 1 addition & 1 deletion packages/@magic-sdk/provider/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['../../../.eslintrc'],
extends: ['../../../.eslintrc.js'],
parserOptions: {
project: ['./tsconfig.json', './test/tsconfig.json'],
tsconfigRootDir: __dirname,
Expand Down
8 changes: 4 additions & 4 deletions packages/@magic-sdk/provider/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There are numerous code paths that [`./modules`](./modules) can follow to intera
// `magic.auth` and `magic.user` methods follow this pattern.
magic.user.getMetadata();

BaseModule.request -> PayloadTransport.post -> Window.postMessage -> iframe
BaseModule.request -> ViewController.post -> Window.postMessage -> iframe
```

### Case #2: Web3 `>=1.0.0-beta.38` using `send`
Expand All @@ -26,7 +26,7 @@ This represents the most current behavior of Web3:
```ts
web3.eth.sendTransaction(...);

RPCProviderModule.send -> BaseModule.request -> PayloadTransport.post -> Window.postMessage -> iframe
RPCProviderModule.send -> BaseModule.request -> ViewController.post -> Window.postMessage -> iframe
```

### Case #3: Web3 `<=1.0.0-beta.37` using `send`
Expand All @@ -36,7 +36,7 @@ This is an edge case affecting a small subset of Web3 pre-`1.x` beta versions:
```ts
web3.eth.sendTransaction(...);

RPCProviderModule.send -> RPCProviderModule.sendAsync -> PayloadTransport.post -> Window.postMessage -> iframe
RPCProviderModule.send -> RPCProviderModule.sendAsync -> ViewController.post -> Window.postMessage -> iframe
```

### Case #4: Legacy Web3 using `sendAsync`
Expand All @@ -46,7 +46,7 @@ This is the legacy behavior of Web3 providers, though it is still widely support
```ts
web3.eth.sendTransaction(...);

RPCProviderModule.sendAsync -> PayloadTransport.post -> Window.postMessage -> iframe
RPCProviderModule.sendAsync -> ViewController.post -> Window.postMessage -> iframe
```

## React Native
Expand Down
2 changes: 1 addition & 1 deletion packages/@magic-sdk/provider/src/core/json-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-underscore-dangle, no-param-reassign */
/* eslint-disable no-param-reassign */

import { JsonRpcRequestPayload, JsonRpcResponsePayload, JsonRpcError } from '@magic-sdk/types';
import { isJsonRpcResponsePayload } from '../util/type-guards';
Expand Down
190 changes: 0 additions & 190 deletions packages/@magic-sdk/provider/src/core/payload-transport.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/@magic-sdk/provider/src/core/sdk-environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import localForage from 'localforage';
import { ViewController } from './view-controller';
import { PayloadTransport } from './payload-transport';
import { SDKBase } from './sdk';
import { WithExtensions } from '../modules/base-extension';

Expand All @@ -16,7 +15,6 @@ export interface SDKEnvironment {
platform: 'web' | 'react-native';
defaultEndpoint: string;
ViewController: ConstructorOf<ViewController>;
PayloadTransport: ConstructorOf<PayloadTransport>;
configureStorage: () => Promise<typeof localForage>;
}

Expand Down
Loading

0 comments on commit d258eeb

Please sign in to comment.