Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sterliakov committed May 31, 2023
1 parent 2193883 commit 0aea707
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 deletions.
12 changes: 11 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
version: 'detect',
},
},
plugins: ['react', 'sonarjs'],
plugins: ['react', 'sonarjs', 'unused-imports'],
rules: {
'linebreak-style': [2, 'unix'],
quotes: [1, 'single', 'avoid-escape'],
Expand All @@ -51,6 +51,16 @@ module.exports = {
'no-constant-condition': ['error', {checkLoops: false}],
'no-unused-vars': 0,
'react/prop-types': 0,
'unused-imports/no-unused-imports': 2,
'unused-imports/no-unused-vars': [
2,
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
},
overrides: [
{
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ repos:
hooks:
- id: eslint
files: \.jsx?$
exclude: ui/config/
types: [file]
args: ['--fix', '--config', '.eslintrc.js']
additional_dependencies:
- eslint
- eslint-config-prettier
- eslint-plugin-sonarjs
- eslint-plugin-react
- eslint-plugin-unused-imports
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
Expand Down
2 changes: 1 addition & 1 deletion ui/src/content/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function () {
container.insertBefore(scriptElement, container.children[0]);
scriptElement.remove();

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
chrome.runtime.onMessage.addListener((msg) => {
if (msg.type.endsWith('-result')) {
console.warn('Result received (content-script)', msg);
document.dispatchEvent(new CustomEvent(msg.type, {detail: msg}));
Expand Down
4 changes: 3 additions & 1 deletion ui/src/internal/chains.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {coins} from '@cosmjs/stargate';

export const EXECUTE_MSG_TYPE_URL = '/cosmwasm.wasm.v1.MsgExecuteContract';

export const HOST_CHAIN = {
Expand Down Expand Up @@ -28,4 +30,4 @@ export const SLAVE_CHAINS = {
};
export const FACTORY_CONTRACT_ADDRESS =
'inj1nlu6djpsq22rfees323r8yl8vt8cjwwufc8vks';
export const BASE_FEE = coins(1000000000000000, 'inj');
export const BASE_FEE = coins(1000000000000000, 'inj');
42 changes: 25 additions & 17 deletions ui/src/internal/ward.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import {toBinary} from '@cosmjs/cosmwasm-stargate';
import {stringToPath} from '@cosmjs/crypto';
import {DirectSecp256k1HdWallet, Registry} from '@cosmjs/proto-signing';
import {makeAuthInfoBytes, makeSignDoc} from '@cosmjs/proto-signing';
import {
AminoTypes,
SigningStargateClient,
coins,
createDefaultAminoConverters,
defaultRegistryTypes,
} from '@cosmjs/stargate';
import {TxRaw} from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
import {MsgExecuteContract} from 'cosmjs-types/cosmwasm/wasm/v1/tx.js';

import {
EXECUTE_MSG_TYPE_URL,
FACTORY_CONTRACT_ADDRESS,
HOST_CHAIN,
SLAVE_CHAINS,
} from './chains';
import {CosmWasmClient} from './injectiveCompat';
import {EXECUTE_MSG_TYPE_URL, HOST_CHAIN, SLAVE_CHAINS, FACTORY_CONTRACT_ADDRESS} from './chains';
export {EXECUTE_MSG_TYPE_URL, HOST_CHAIN, SLAVE_CHAINS, FACTORY_CONTRACT_ADDRESS, BASE_FEE} from './chains';

export {
EXECUTE_MSG_TYPE_URL,
HOST_CHAIN,
SLAVE_CHAINS,
FACTORY_CONTRACT_ADDRESS,
BASE_FEE,
} from './chains';

export function request(args, wait) {
if (wait) {
const eventName = `${wait}-result`;
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
const receiveResponse = (e) => {
document.removeEventListener(eventName, receiveResponse);
resolve(e.detail);
Expand Down Expand Up @@ -220,18 +230,16 @@ export default class Ward {
async getAllBalances() {
const slaves = await this.getSlaveContracts();
return Promise.all(
Object.entries(SLAVE_CHAINS).map(
async ([chainId, {rpc, name, denoms}]) => ({
chainId,
name,
address: slaves[chainId],
balances: await Promise.all(
denoms.map(async (denom) =>
this.getBalance(chainId, denom.coinDenom),
),
Object.entries(SLAVE_CHAINS).map(async ([chainId, {name, denoms}]) => ({
chainId,
name,
address: slaves[chainId],
balances: await Promise.all(
denoms.map(async (denom) =>
this.getBalance(chainId, denom.coinDenom),
),
}),
),
),
})),
);
}

Expand Down Expand Up @@ -414,7 +422,7 @@ export default class Ward {
);
}

async signDirect(signerAddress, signDoc, password = null) {
async signDirect(signerAddress, signDoc, _password = null) {
throw new Error('Direct signing not supported yet.');
}
}
9 changes: 3 additions & 6 deletions ui/src/login/accountScreen.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {makeSignDoc} from '@cosmjs/amino';
import {toBinary} from '@cosmjs/cosmwasm-stargate';
import {coins} from '@cosmjs/stargate';
import React from 'react';
Expand All @@ -17,9 +16,7 @@ import Table from 'react-bootstrap/Table';
import Ward, {
BASE_FEE,
EXECUTE_MSG_TYPE_URL,
FACTORY_CONTRACT_ADDRESS,
HOST_CHAIN,
SLAVE_CHAINS,
} from '../internal/ward';

export class BalanceRow extends React.Component {
Expand Down Expand Up @@ -398,9 +395,9 @@ export class ManageOwnScreen extends MessageSender {
async componentDidMount() {
const {
members,
recovery_approvals_count,
transfer_approvals_count,
recovery_progress,
// recovery_approvals_count,
// transfer_approvals_count,
// recovery_progress,
recovery_method,
new_owner,
} = await this.ward.getRecoveryState();
Expand Down
4 changes: 0 additions & 4 deletions ui/src/login/signupScreen.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {makeSignDoc} from '@cosmjs/amino';
import {toBinary} from '@cosmjs/cosmwasm-stargate';
import {Bip39, Random} from '@cosmjs/crypto';
import {coins} from '@cosmjs/stargate';
import React from 'react';
import {ArrowClockwise} from 'react-bootstrap-icons';
import Alert from 'react-bootstrap/Alert';
import Button from 'react-bootstrap/Button';
import Col from 'react-bootstrap/Col';
import FloatingLabel from 'react-bootstrap/FloatingLabel';
import Form from 'react-bootstrap/Form';
import Nav from 'react-bootstrap/Nav';
import Row from 'react-bootstrap/Row';
import Spinner from 'react-bootstrap/Spinner';
import Tab from 'react-bootstrap/Tab';

import Ward, {
BASE_FEE,
Expand Down

0 comments on commit 0aea707

Please sign in to comment.