Skip to content

Commit

Permalink
chore: code quality improvements 1 (#81)
Browse files Browse the repository at this point in the history
* chore: code quality improvements 1

* ci: updated sonar qube scanner

* chore: sonar qube suggestions applied

* ci: fixing version for workflow
  • Loading branch information
ohager authored Dec 30, 2024
1 parent 51644b2 commit c322dff
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-signumjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' lcov.info

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
uses: SonarSource/sonarqube-scan-action@v4.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/ContractDataView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ContractDataView {
*/
public static VariableLength = 16;

constructor(private _contract: Contract) {
constructor(private readonly _contract: Contract) {
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/calculateMinimumCreationFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function calculateMinimumCreationFee(args: CalculateMinimumCreationFeeArg
const {dataHex, codeHex} = args;

const codePagesCount = codeHex ? countCodePages(codeHex) : 0;
const dataPagesCount = dataHex && dataHex.length ? countDataPages(dataHex) : 1;
const dataPagesCount = dataHex?.length ? countDataPages(dataHex) : 1;

return Amount.fromPlanck(FeeQuantPlanck * 10 * (2 + codePagesCount + dataPagesCount));
}
7 changes: 2 additions & 5 deletions packages/core/src/api/apiComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ import {

class ApiImpl implements Api {

constructor(service: ChainService) {
this.service = service;
}
constructor(readonly service: ChainService) {}

service: ChainService;
alias: AliasApi;
account: AccountApi;
asset: AssetApi;
Expand Down Expand Up @@ -78,7 +75,7 @@ export class ApiComposer {
return new ApiComposer(service);
}

private constructor(private service: ChainService) {
private constructor(private readonly service: ChainService) {
this.api = new ApiImpl(service);
}

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/api/factories/contract/getContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import {ChainService} from '../../../service/chainService';
import {Contract} from '@signumjs/contracts';
// import {Contract} from '../../../typings/contract';

/**
* Use with {@link ApiComposer} and belongs to {@link ContractApi}.
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/constants/transactionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ export enum TransactionType {
/**
* @see TransactionArbitrarySubtype
*/
Arbitrary,
Arbitrary = 1,
/**
* @see TransactionAssetSubtype
*/
Asset,
Asset = 2,
/**
* @see TransactionMarketplaceSubtype
*/
Marketplace,
Marketplace= 3,
/**
* @see TransactionLeasingSubtype
*/
Leasing,
Leasing = 4,
/**
* @see TransactionMiningSubtype
*/
Expand Down
83 changes: 0 additions & 83 deletions packages/core/websandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,89 +75,6 @@ <h2 class="text-2xl font-bold mb-6">Send Message</h2>
</form>
</section>
</div>
<!-- <section class="space-y-2 bg-white p-10 rounded border">-->
<!-- <section class="">-->
<!-- <h2 class="text-2xl font-bold mb-6">Generate Mnemonic</h2>-->

<!-- <div class="space-y-2">-->
<!-- <h2 class="text-xl font-semibold">Mnemonic</h2>-->
<!-- <p id="mnemonic-output"-->
<!-- class="mt-2 text-sm font-italic"></p>-->
<!-- </div>-->
<!-- <hr class="my-4"/>-->
<!-- <div class="space-y-2 mb-2">-->
<!-- <h3 class="text-lg">Public Key</h3>-->
<!-- <p id="pubkey-output" class="mt-2 text-sm font-mono"></p>-->
<!-- </div>-->
<!-- <div class="space-y-2 mb-2">-->
<!-- <h3 class="text-lg">Sign Key</h3>-->
<!-- <p id="signkey-output" class="mt-2 text-sm font-mono"></p>-->
<!-- </div>-->
<!-- <div class="space-y-2 mb-2">-->
<!-- <h3 class="text-lg">Agreement Key (P2P Messages)</h3>-->
<!-- <p id="agreekey-output" class="mt-2 text-sm font-mono"></p>-->
<!-- </div>-->
<!-- <div class="space-y-2">-->
<!-- <h3 class="text-lg">Account Id</h3>-->
<!-- <p id="accountid-output" class="mt-2 text-sm font-mono"></p>-->
<!-- </div>-->
<!-- </section>-->
<!-- </section>-->

<!-- <section class="space-y-2 bg-white p-10 rounded border">-->
<!-- <h2 class="text-2xl font-bold">Encrypt</h2>-->
<!-- <input-->
<!-- id="encrypt-secret1-input"-->
<!-- class="flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full"-->
<!-- placeholder="Enter senders secret here"-->
<!-- />-->
<!-- <input-->
<!-- id="encrypt-secret2-input"-->
<!-- class="flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full"-->
<!-- placeholder="Enter receivers secret here"-->
<!-- />-->
<!-- <input-->
<!-- id="encrypt-text-input"-->
<!-- class="flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full mt-2"-->
<!-- placeholder="Enter some text here"-->
<!-- />-->
<!-- <button class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 px-4 py-2 h-10 mt-2 bg-green-500 hover:bg-green-600 text-white"-->
<!-- onclick="encrypt(event)"-->
<!-- >-->
<!-- Encrypt-->
<!-- </button>-->
<!-- <p id="encrypt-cipher-output" class="my-4 text-sm font-mono break-all"></p>-->
<!-- <button id="encrypt-copy-btn" class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 px-4 py-2 h-10 mt-2 bg-gray-500 hover:bg-gray-600 text-gray-200 hidden"-->
<!-- onclick="copyToClipboard('encrypt-cipher-output')"-->
<!-- >-->
<!-- Copy-->
<!-- </button>-->

<!-- </section>-->
<!-- <section class="space-y-2 bg-white p-10 rounded border">-->
<!-- <h2 class="text-2xl font-bold">Decrypt</h2>-->
<!-- <input-->
<!-- id="decrypt-secret1-input"-->
<!-- class="flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full"-->
<!-- placeholder="Enter senders secret here"-->
<!-- />-->
<!-- <input-->
<!-- id="decrypt-secret2-input"-->
<!-- class="flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full"-->
<!-- placeholder="Enter senders secret here"-->
<!-- />-->
<!-- <textarea-->
<!-- id="decrypt-cipher-textarea"-->
<!-- rows=6-->
<!-- class="flex rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full mt-2"-->
<!-- >[Enter Ciphertext here]</textarea>-->
<!-- <button class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 px-4 py-2 h-10 mt-2 bg-green-500 hover:bg-green-600 text-white"-->
<!-- onclick="decrypt(event)"-->
<!-- >-->
<!-- Decrypt-->
<!-- </button>-->
<!-- <p id="decrypt-plaintext-output" class="my-4 text-sm font-mono break-all"></p>-->
<!-- </section>-->
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/crypto/nodeJSCryptoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {CryptoParams} from './cryptoParams';
import {CryptoError} from '../typings/cryptoError';

export class NodeJSCryptoProvider implements CryptoProvider {
private crypto: any;
private readonly crypto: any;

constructor() {
this.crypto = require('crypto');
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/crypto/webCryptoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {CryptoParams} from './cryptoParams';
import {sha256 as sha256JS} from 'js-sha256'

export class WebCryptoProvider implements CryptoProvider {
private crypto: Crypto;
private readonly crypto: Crypto;

constructor() {
if (typeof window !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion packages/http/src/httpAdapterAxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DefaultAxiosOptions = {};
*/
export class HttpAdapterAxios implements Http {

private _clientImpl: AxiosInstance;
private readonly _clientImpl: AxiosInstance;

/**
* Creates your Http client
Expand Down
2 changes: 1 addition & 1 deletion packages/standards/src/src44/DescriptorData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { parseIpfsMedia } from './parseIpfsMedia';
*/
export class DescriptorData {

private constructor(private data: SRC44Descriptor, private strict: boolean) {
private constructor(private data: SRC44Descriptor, private readonly strict: boolean) {
this.validate();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/standards/src/src44/DescriptorDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ import {SetContractBrandingArgs} from './typings/args/setContractBrandingArgs';
*
*/
export class DescriptorDataClient {
private static SmartContractPublicKey = '0000000000000000000000000000000000000000000000000000000000000000';
private static readonly SmartContractPublicKey = '0000000000000000000000000000000000000000000000000000000000000000';

/**
* Instantiates the client.
* Mind the dependency of the ledger client.
* @param ledger
*/
constructor(private ledger: Ledger) {
constructor(private readonly ledger: Ledger) {
}

/**
Expand Down
6 changes: 2 additions & 4 deletions packages/standards/src/src47/URIResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface URI {
*
*/
export class URIResolver {
constructor(private ledger: Ledger) {
constructor(private readonly ledger: Ledger) {
}

/**
Expand All @@ -88,12 +88,10 @@ export class URIResolver {
const regex = /^(?<schema>http|https):\/\/(?<body>\$?[\w.]+?)(@(?<tld>\w+)?)?(\/(?<path>[\w-]+)?)?$/gm;
const result = regex.exec(uri.toLowerCase());

// @ts-ignore
if (!result || !result.groups) {
if (!result?.groups) {
throw new Error(`Invalid SRC47 URI: ${uri}`);
}

// @ts-ignore
const {schema, body, tld = 'signum', path} = result.groups;

const domains = body.replace('$', '').split('.');
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const AmountFormats = {
* @category value-objects
*/
export class Amount {
private _value: ChainValue;
private readonly _value: ChainValue;

private constructor(planck: number | string) {
this._value = new ChainValue(8).setAtomic(planck);
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/chainValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function assureValidValue(v: string): void {
export class ChainValue {

private _big: BigNumber;
private _decimals: number;
private readonly _decimals: number;

/**
* Constructs a value object instance for calculations. The initial value is 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export class GenericDeeplinkableWallet implements Wallet {
}

sendEncryptedMessage(_args: SendEncryptedMessageArgs): Promise<string> {
return Promise.reject('Not supported yet');
return Promise.reject(new Error('Not supported yet'));
}
}
2 changes: 1 addition & 1 deletion packages/wallets/src/extension/consoleExtensionAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {RequestSendEncryptedMessageArgs} from './args/requestSendEncryptedMessag
export class ConsoleExtensionAdapter implements ExtensionAdapter {

private static notAvailable() {
return Promise.reject('Not available');
return Promise.reject(new Error('Not available'));
}

onNotification(callback: (message: any, listener: ExtensionListener) => void): ExtensionListener {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/src/extension/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class InvalidNetworkError extends ExtensionWalletError {
* @internal
* @ignore
*/
export function createError(payload: any) {
export function createError(payload: ExtensionErrorType): ExtensionWalletError {
switch (payload) {
case ExtensionErrorType.NotGranted:
return new NotGrantedWalletError();
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/src/extension/genericExtensionWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class GenericExtensionWallet implements Wallet {
* @param adapter The adapter according your environment. See {@link ExtensionAdapterFactory}.
* It uses the default {@link ExtensionAdapterFactory} to determine the correct adapter.
*/
constructor(private adapter = ExtensionAdapterFactory.getAdapter()) {
constructor(private readonly adapter = ExtensionAdapterFactory.getAdapter()) {
}

private assertConnection() {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/src/extension/walletConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class WalletConnection {
public watchOnly: boolean,
public availableNodeHosts: string[],
public currentNodeHost: string,
private adapter: ExtensionAdapter,
private readonly adapter: ExtensionAdapter,
) {
}

Expand Down

0 comments on commit c322dff

Please sign in to comment.