Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit e36c75d

Browse files
authored
TxButton enhancement & general packages maintenance (#239)
* dev (wip) * Using prettier and added eslint for project * Using the latest package without changing package.json
1 parent 33592d3 commit e36c75d

File tree

4 files changed

+1599
-1402
lines changed

4 files changed

+1599
-1402
lines changed

.circleci/config.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ version: 2
1717
jobs:
1818
test:
1919
docker:
20-
- image: cimg/node:16.4
20+
- image: cimg/node:16.14
2121
working_directory: ~/repo
2222
steps:
2323
- checkout
@@ -37,8 +37,8 @@ jobs:
3737
- node_modules
3838
key: v1-dependencies-{{ checksum "package.json" }}
3939
- run:
40-
name: Prettier check
41-
command: yarn prettier:check
40+
name: ESLint / Prettier check
41+
command: yarn eslint:check && yarn prettier:check
4242
- run:
4343
name: Test
4444
command: yarn test
@@ -50,7 +50,7 @@ jobs:
5050

5151
deploy:
5252
docker:
53-
- image: cimg/node:16.4
53+
- image: cimg/node:16.14
5454
working_directory: ~/repo
5555
steps:
5656
- attach_workspace:

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"build": "react-app-rewired build",
1919
"test": "CI=true react-app-rewired test",
2020
"eject": "react-scripts eject",
21+
"eslint:check": "eslint --ext .jsx,.js src/",
22+
"eslint:write": "eslint --fix --ext .jsx,.js src/",
2123
"prettier:check": "prettier -c src/*",
2224
"prettier:write": "prettier -w src/*",
2325
"deploy": "gh-pages -d build -m '[ci skip] Updates'"
@@ -43,7 +45,9 @@
4345
"stream-browserify": "^3.0.0"
4446
},
4547
"devDependencies": {
48+
"eslint": "^8.10.0",
4649
"eslint-config-prettier": "^8.4.0",
50+
"eslint-config-react-app": "^7.0.0",
4751
"gh-pages": "^3.2.3",
4852
"prettier": "2.5.1",
4953
"react-app-rewired": "^2.2.1",
@@ -55,6 +59,7 @@
5559
"eslintConfig": {
5660
"extends": [
5761
"react-app",
62+
"eslint:recommended",
5863
"prettier"
5964
]
6065
},

src/substrate-lib/components/TxButton.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { useSubstrateState } from '../'
77
import utils from '../utils'
88

99
function TxButton({
10+
attrs = null,
11+
color = 'blue',
12+
disabled = false,
1013
label,
1114
setStatus,
12-
color = 'blue',
1315
style = null,
1416
type = 'QUERY',
15-
attrs = null,
16-
disabled = false,
17+
txOnClickHandler = null,
1718
}) {
1819
// Hooks
1920
const { api, currentAccount } = useSubstrateState()
@@ -158,13 +159,21 @@ function TxButton({
158159
}
159160

160161
setStatus('Sending...')
161-
;(isSudo() && sudoTx()) ||
162-
(isUncheckedSudo() && uncheckedSudoTx()) ||
163-
(isSigned() && signedTx()) ||
164-
(isUnsigned() && unsignedTx()) ||
165-
(isQuery() && query()) ||
166-
(isRpc() && rpc()) ||
167-
(isConstant() && constant())
162+
163+
const asyncFunc =
164+
(isSudo() && sudoTx) ||
165+
(isUncheckedSudo() && uncheckedSudoTx) ||
166+
(isSigned() && signedTx) ||
167+
(isUnsigned() && unsignedTx) ||
168+
(isQuery() && query) ||
169+
(isRpc() && rpc) ||
170+
(isConstant() && constant)
171+
172+
await asyncFunc()
173+
174+
return txOnClickHandler && typeof txOnClickHandler === 'function'
175+
? txOnClickHandler(unsub)
176+
: null
168177
}
169178

170179
const transformParams = (

0 commit comments

Comments
 (0)