Skip to content

Commit

Permalink
fix: Unify Prettier and ESLint scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Aug 8, 2024
1 parent 0699b43 commit 5832d62
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 175 deletions.
6 changes: 2 additions & 4 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
],
"scripts": {
"build": "tsup",
"lint": "eslint",
"lint:fix": "yarn lint --fix",
"format": "prettier src/ --check",
"format:fix": "prettier src/ --write",
"lint": "prettier src/ --check && eslint",
"lint:fix": "prettier src/ --write && eslint --fix",
"test": "jest",
"test:ci": "jest --coverage --passWithNoTests "
},
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EMessageType } from "./types";
import { EMessageType } from './types';

export { EMessageType };
export * from "./methods";
export * from './methods';
12 changes: 6 additions & 6 deletions packages/sdk/src/methods/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OnAccountChangeFunc, OnEventType, OnNetworkChangeFunc } from "../types/methods/events";
import { getAdena } from "../utils";
import { OnAccountChangeFunc, OnEventType, OnNetworkChangeFunc } from '../types/methods/events';
import { getAdena } from '../utils';

/**
* Add a listener on connected account changes
Expand All @@ -8,9 +8,9 @@ import { getAdena } from "../utils";
* @returns Nothing, throws an error if it fails
*/
export const onAccountChange = async (func: OnAccountChangeFunc): Promise<void> => {
const adena = getAdena();
const adena = getAdena();

adena.On(OnEventType.CHANGED_ACCOUNT, func);
adena.On(OnEventType.CHANGED_ACCOUNT, func);
};

/**
Expand All @@ -20,7 +20,7 @@ export const onAccountChange = async (func: OnAccountChangeFunc): Promise<void>
* @returns Nothing, throws an error if it fails
*/
export const onNetworkChange = async (func: OnNetworkChangeFunc): Promise<void> => {
const adena = getAdena();
const adena = getAdena();

adena.On(OnEventType.CHANGED_NETWORK, func);
adena.On(OnEventType.CHANGED_NETWORK, func);
};
46 changes: 23 additions & 23 deletions packages/sdk/src/methods/general.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EAdenaResponseStatus } from "../types/common";
import { getAdena } from "../utils";
import { AddEstablishResponse, AddEstablishResponseType, GetAccountResponseData } from "../types/methods/general";
import { EAdenaResponseStatus } from '../types/common';
import { getAdena } from '../utils';
import { AddEstablishResponse, AddEstablishResponseType, GetAccountResponseData } from '../types/methods/general';

/**
* Establish a connection to your site from Adena
Expand All @@ -9,23 +9,23 @@ import { AddEstablishResponse, AddEstablishResponseType, GetAccountResponseData
* @returns Original Adena response, useful to check if the site was already connected
*/
export const establishConnection = async (name: string): Promise<AddEstablishResponse> => {
const adena = getAdena();
const adena = getAdena();

// Establish a connection to the wallet
const response = await adena.AddEstablish(name);
// Establish a connection to the wallet
const response = await adena.AddEstablish(name);

if (
response.status === EAdenaResponseStatus.SUCCESS &&
(response.type === AddEstablishResponseType.ALREADY_CONNECTED ||
response.type === AddEstablishResponseType.CONNECTION_SUCCESS)
) {
// Adena establishes a connection if:
// - the app was not connected before, and the user approves
// - the app was connected before
return response;
}
if (
response.status === EAdenaResponseStatus.SUCCESS &&
(response.type === AddEstablishResponseType.ALREADY_CONNECTED ||
response.type === AddEstablishResponseType.CONNECTION_SUCCESS)
) {
// Adena establishes a connection if:
// - the app was not connected before, and the user approves
// - the app was connected before
return response;
}

throw new Error(`Unable to establish connection: ${response.message}`);
throw new Error(`Unable to establish connection: ${response.message}`);
};

/**
Expand All @@ -34,12 +34,12 @@ export const establishConnection = async (name: string): Promise<AddEstablishRes
* @returns Original Adena response with the account information
*/
export const getAccountInfo = async (): Promise<GetAccountResponseData> => {
const adena = getAdena();
const adena = getAdena();

const response = await adena.GetAccount();
if (response.status !== EAdenaResponseStatus.SUCCESS) {
throw new Error(`Unable to fetch account info: ${response.message}`);
}
const response = await adena.GetAccount();
if (response.status !== EAdenaResponseStatus.SUCCESS) {
throw new Error(`Unable to fetch account info: ${response.message}`);
}

return response.data;
return response.data;
};
8 changes: 4 additions & 4 deletions packages/sdk/src/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { addNetwork, switchNetwork } from "./network";
export { signAndSendTransaction, signTransaction } from "./transactions";
export { establishConnection, getAccountInfo } from "./general";
export { onAccountChange, onNetworkChange } from "./events";
export { addNetwork, switchNetwork } from './network';
export { signAndSendTransaction, signTransaction } from './transactions';
export { establishConnection, getAccountInfo } from './general';
export { onAccountChange, onNetworkChange } from './events';
40 changes: 20 additions & 20 deletions packages/sdk/src/methods/network.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAdena } from "../utils";
import { EAdenaResponseStatus } from "../types/common";
import { SwitchNetworkResponseType } from "../types/methods/network";
import { getAdena } from '../utils';
import { EAdenaResponseStatus } from '../types/common';
import { SwitchNetworkResponseType } from '../types/methods/network';

/**
* Switches the Adena network to the given chain ID
Expand All @@ -9,19 +9,19 @@ import { SwitchNetworkResponseType } from "../types/methods/network";
* @returns Nothing, throws an error if it fails
*/
export const switchNetwork = async (chainId: string): Promise<void> => {
const adena = getAdena();
const adena = getAdena();

const response = await adena.SwitchNetwork(chainId);
if (
(response.status === EAdenaResponseStatus.SUCCESS &&
response.type === SwitchNetworkResponseType.SWITCH_NETWORK_SUCCESS) ||
(response.status === EAdenaResponseStatus.FAILURE &&
response.type === SwitchNetworkResponseType.REDUNDANT_CHANGE_REQUEST)
) {
return;
}
const response = await adena.SwitchNetwork(chainId);
if (
(response.status === EAdenaResponseStatus.SUCCESS &&
response.type === SwitchNetworkResponseType.SWITCH_NETWORK_SUCCESS) ||
(response.status === EAdenaResponseStatus.FAILURE &&
response.type === SwitchNetworkResponseType.REDUNDANT_CHANGE_REQUEST)
) {
return;
}

throw new Error(`Unable to switch Adena network: ${response.message}`);
throw new Error(`Unable to switch Adena network: ${response.message}`);
};

/**
Expand All @@ -33,13 +33,13 @@ export const switchNetwork = async (chainId: string): Promise<void> => {
* @returns Nothing, throws an error if it fails
*/
export const addNetwork = async (chainId: string, chainName: string, rpcUrl: string): Promise<void> => {
const adena = getAdena();
const adena = getAdena();

const response = await adena.AddNetwork({ chainId, chainName, rpcUrl });
const response = await adena.AddNetwork({ chainId, chainName, rpcUrl });

if (response.status === EAdenaResponseStatus.SUCCESS) {
return;
}
if (response.status === EAdenaResponseStatus.SUCCESS) {
return;
}

throw new Error(`Unable to add network ${response.message}`);
throw new Error(`Unable to add network ${response.message}`);
};
72 changes: 36 additions & 36 deletions packages/sdk/src/methods/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BroadcastTxCommitResult } from "@gnolang/tm2-js-client";
import { BroadcastTxCommitResult } from '@gnolang/tm2-js-client';

import { getAdena } from "../utils";
import { EAdenaResponseStatus } from "../types/common";
import { ContractMessage } from "../types/methods/transactions";
import { getAdena } from '../utils';
import { EAdenaResponseStatus } from '../types/common';
import { ContractMessage } from '../types/methods/transactions';

const DEFAULT_GAS_FEE = 1000000;
const DEFAULT_GAS_LIMIT = 5000000;
Expand All @@ -17,26 +17,26 @@ const DEFAULT_GAS_LIMIT = 5000000;
* @returns {BroadcastTxCommitResult} Result of the broadcast transaction
*/
export const signAndSendTransaction = async (
messages: ContractMessage[],
gasFee: number = DEFAULT_GAS_FEE,
gasWanted: number = DEFAULT_GAS_LIMIT,
memo?: string,
messages: ContractMessage[],
gasFee: number = DEFAULT_GAS_FEE,
gasWanted: number = DEFAULT_GAS_LIMIT,
memo?: string
): Promise<BroadcastTxCommitResult> => {
const adena = getAdena();
const adena = getAdena();

// Sign and send the transaction
const response = await adena.DoContract({
messages,
gasFee,
gasWanted,
memo,
});
// Sign and send the transaction
const response = await adena.DoContract({
messages,
gasFee,
gasWanted,
memo,
});

if (response.status !== EAdenaResponseStatus.SUCCESS) {
throw new Error(`Unable to send transaction: ${response.message}`);
}
if (response.status !== EAdenaResponseStatus.SUCCESS) {
throw new Error(`Unable to send transaction: ${response.message}`);
}

return response.data;
return response.data;
};

/**
Expand All @@ -49,24 +49,24 @@ export const signAndSendTransaction = async (
* @returns {string} Encoded transaction
*/
export const signTransaction = async (
messages: ContractMessage[],
gasFee: number = DEFAULT_GAS_FEE,
gasWanted: number = DEFAULT_GAS_LIMIT,
memo?: string,
messages: ContractMessage[],
gasFee: number = DEFAULT_GAS_FEE,
gasWanted: number = DEFAULT_GAS_LIMIT,
memo?: string
): Promise<string> => {
const adena = getAdena();
const adena = getAdena();

// Sign the transaction
const response = await adena.SignTx({
messages,
gasFee,
gasWanted,
memo,
});
// Sign the transaction
const response = await adena.SignTx({
messages,
gasFee,
gasWanted,
memo,
});

if (response.status !== EAdenaResponseStatus.SUCCESS) {
throw new Error(`Unable to sign transaction ${response.message}`);
}
if (response.status !== EAdenaResponseStatus.SUCCESS) {
throw new Error(`Unable to sign transaction ${response.message}`);
}

return response.data.encodedTransaction;
return response.data.encodedTransaction;
};
14 changes: 7 additions & 7 deletions packages/sdk/src/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export enum EAdenaResponseStatus {
SUCCESS = "success",
FAILURE = "failure",
SUCCESS = 'success',
FAILURE = 'failure',
}

export interface IAdenaResponse<T, D> {
code: number;
status: EAdenaResponseStatus;
type: T;
message: string;
data: D;
code: number;
status: EAdenaResponseStatus;
type: T;
message: string;
data: D;
}
38 changes: 19 additions & 19 deletions packages/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { AdenaDoContract, AdenaSignTx } from "./methods/transactions";
import { AdenaAddNetwork, AdenaSwitchNetwork } from "./methods/network";
import { AdenaAddEstablish, AdenaGetAccount } from "./methods/general";
import { AdenaOnEvent } from "./methods/events";
import { AdenaDoContract, AdenaSignTx } from './methods/transactions';
import { AdenaAddNetwork, AdenaSwitchNetwork } from './methods/network';
import { AdenaAddEstablish, AdenaGetAccount } from './methods/general';
import { AdenaOnEvent } from './methods/events';

export type AdenaWallet = {
// General
AddEstablish: AdenaAddEstablish;
GetAccount: AdenaGetAccount;
// General
AddEstablish: AdenaAddEstablish;
GetAccount: AdenaGetAccount;

// Network
SwitchNetwork: AdenaSwitchNetwork;
AddNetwork: AdenaAddNetwork;
// Network
SwitchNetwork: AdenaSwitchNetwork;
AddNetwork: AdenaAddNetwork;

// Transactions
SignTx: AdenaSignTx;
DoContract: AdenaDoContract;
// Transactions
SignTx: AdenaSignTx;
DoContract: AdenaDoContract;

// Events
On: AdenaOnEvent;
// Events
On: AdenaOnEvent;
};

export enum EMessageType {
MSG_SEND = "/bank.MsgSend",
MSG_CALL = "/vm.m_call",
MSG_ADD_PKG = "/vm.m_addpkg",
MSG_RUN = "/vm.m_run",
MSG_SEND = '/bank.MsgSend',
MSG_CALL = '/vm.m_call',
MSG_ADD_PKG = '/vm.m_addpkg',
MSG_RUN = '/vm.m_run',
}
4 changes: 2 additions & 2 deletions packages/sdk/src/types/methods/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export type OnAccountChangeFunc = (address: string) => void;
export type OnNetworkChangeFunc = (network: string) => void;

export enum OnEventType {
CHANGED_ACCOUNT = "changedAccount",
CHANGED_NETWORK = "changedNetwork",
CHANGED_ACCOUNT = 'changedAccount',
CHANGED_NETWORK = 'changedNetwork',
}

type OnEventFunc = OnAccountChangeFunc | OnNetworkChangeFunc;
Expand Down
Loading

0 comments on commit 5832d62

Please sign in to comment.