Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api refactor #859

Draft
wants to merge 10 commits into
base: chainmanager-to-pinia
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ const esModules = ['quasar', 'quasar/lang', 'lodash-es'].join('|');
module.exports = {
globals: {
__DEV__: true,
// Remove if using `const enums`
// See https://huafu.github.io/ts-jest/user/config/isolatedModules#example
'ts-jest': {
isolatedModules: true,
},
},
testEnvironment: 'jsdom',
// noStackTrace: true,
// bail: true,
// cache: false,
Expand Down Expand Up @@ -67,7 +63,7 @@ module.exports = {
// See https://github.com/vuejs/vue-jest/issues/188#issuecomment-620750728
moduleFileExtensions: ['vue', 'js', 'jsx', 'json', 'ts', 'tsx'],
moduleNameMapper: {
'^quasar$': 'quasar/dist/quasar.esm.prod.js',
'^quasar$': 'quasar/dist/quasar.client.js',
'^~/(.*)$': '<rootDir>/$1',
'^src/(.*)$': '<rootDir>/src/$1',
'^app/(.*)$': '<rootDir>/$1',
Expand All @@ -77,16 +73,17 @@ module.exports = {
'^assets/(.*)$': '<rootDir>/src/assets/$1',
'^boot/(.*)$': '<rootDir>/src/boot/$1',
'.*css$': '@quasar/quasar-app-extension-testing-unit-jest/stub.css',
'^@vue/test-utils': '<rootDir>/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js',
},
transform: {
// See https://jestjs.io/docs/en/configuration.html#transformignorepatterns-array-string
[`^(${esModules}).+\\.js$`]: 'babel-jest',
'^.+\\.(ts|js|html)$': 'ts-jest',
'^.+\\.(ts|js|html)$': ['ts-jest', { isolatedModules: true }],
// vue-jest uses find-babel-file, which searches by this order:
// (async) .babelrc, .babelrc.js, package.json, babel.config.js
// (sync) .babelrc, .babelrc.js, babel.config.js, package.json
// https://github.com/tleunen/find-babel-config/issues/33
'.*\\.vue$': 'vue-jest',
'.*\\.vue$': '@vue/vue3-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub',
},
Expand Down
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
},
"dependencies": {
"@quasar/extras": "^1.13.4",
"@vueuse/core": "^10.9.0",
"@wharfkit/session": "^1.2.8",
"@wharfkit/transact-plugin-resource-provider": "^1.1.1",
"@wharfkit/wallet-plugin-anchor": "^1.3.4",
"@wharfkit/wallet-plugin-cleos": "^1.1.1",
"@wharfkit/wallet-plugin-privatekey": "^1.1.0",
"@wharfkit/web-renderer": "^1.2.4",
"@vueuse/core": "^10.9.0",
"axios": "^0.21.1",
"axios": "^1.7.2",
"core-js": "^3.6.5",
"csvtojson": "^2.0.10",
"fast-sha256": "^1.3.0",
Expand All @@ -31,27 +31,32 @@
"ol": "^6.14.1",
"pinia": "^2.1.6",
"quasar": "^2.6.2",
"vue": "^3.3.0",
"vue": "^3.4.27",
"vue-json-viewer": "^3.0.4",
"vue-router": "^4.0.0",
"vue3-openlayers": "^0.1.63"
},
"devDependencies": {
"@babel/eslint-parser": "^7.13.14",
"@jest/globals": "^29.7.0",
"@pinia/testing": "^0.1.3",
"@quasar/app-webpack": "^3.5.3",
"@quasar/quasar-app-extension-testing-unit-jest": "^3.0.0-alpha.10",
"@types/jest": "^27.4.0",
"@types/node": "^12.20.21",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@vue/test-utils": "^2.4.6",
"@vue/vue3-jest": "^29.2.6",
"dotenv": "^14.3.0",
"eslint": "^7.14.0",
"eslint-plugin-jest": "^25.2.2",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^27.1.3",
"eslint-plugin-unused-imports": "^3.0.0",
"eslint-plugin-vue": "^9.0.0",
"jest": "^29.2.2",
"jest-serializer-vue": "^3.1.0",
"node-polyfill-webpack-plugin": "^1.1.4",
"vue-property-decorator": "^9.1.2"
"ts-jest": "^29.1.4"
},
"browserslist": [
"last 10 Chrome versions",
Expand Down
Binary file added public/chains/wax-testnet/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/chains/wax-testnet/logo_lg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 183 additions & 0 deletions src/api/antelopeV1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/* see https://github.com/greymass/eosio-core/blob/master/test/api.ts for documentation */
import {
ABI,
ABIDef,
ABISerializable,
Action,
ActionType,
API,
APIClient,
Asset,
Name,
PublicKey,
Serializer,
} from '@wharfkit/session';
import axios from 'axios';
import { addInterceptors } from 'src/api/axiosInterceptors';
import { useNetworksStore } from 'src/stores/networks';
import {
GetProducers,
GetTableRowsParams,
} from 'src/types';

const networksStore = useNetworksStore();
const eosioAxios = axios.create({ baseURL: networksStore.getCurrentNetwork.getV1Endpoint() });
addInterceptors(eosioAxios);

const eosio = new APIClient({ url: networksStore.getCurrentNetwork.getV1Endpoint() });

export const getAccount = async function (
address: string,
): Promise<API.v1.AccountObject> {
try {
return await eosio.v1.chain.get_account(address);
} catch (e) {
console.error('Error on v1/chain/get_account', e);
}
};

export const getAccountsByPublicKey = async function (
key: PublicKey,
): Promise<{ account_names: Name[] }> {
try {
return await eosio.v1.history.get_key_accounts(key);
} catch(e) {
console.error('Error on v1/history/get_key_accounts', e);
}

};

export const getTokenBalances = async function (
address: string,
): Promise<Asset[]> {
const { contract } = networksStore.getCurrentNetwork.getSystemToken();
try {
return await eosio.v1.chain.get_currency_balance(contract, address);
} catch(e) {
console.error('Error on v1/chain/get_currency_balance', e);
}
};

export const getTableRows = async function (
tableInput: GetTableRowsParams,
): Promise<API.v1.GetTableRowsResponse> {
try {
return await eosio.v1.chain.get_table_rows(tableInput);
} catch(e) {
console.error('Error on v1/chain/get_table_rows', e);
}
};

export const getTableByScope = async function (
data: API.v1.GetTableByScopeParams,
): Promise<API.v1.GetTableByScopeResponse> {
try {
return await eosio.v1.chain.get_table_by_scope(data);
} catch(e) {
console.error('Error on v1/chain/get_table_by_scope', e);
}
};

export const getTransactionV1 = async function (
id?: string,
): Promise<API.v1.GetTransactionResponse> {
try {
return await eosio.v1.history.get_transaction(id);
} catch(e) {
console.error('Error on v1/history/get_transaction', e);
}
};

export const getBlock = async function (
block: string,
):Promise<API.v1.GetBlockResponse> {
try {
return await eosio.v1.chain.get_block(block);
} catch(e) {
console.error('Error on v1/chain/get_block', e);
}
};

export const getInfo = async function ():
Promise<API.v1.GetInfoResponse> {
try {
return await eosio.v1.chain.get_info();
} catch(e) {
console.error('Error on v1/chain/get_info', e);
}
};

export const getProducerSchedule = async function ():
Promise<API.v1.GetProducerScheduleResponse> {
try {
return await eosio.v1.chain.get_producer_schedule();
} catch(e) {
console.error('Error on v1/chain/get_producer_schedule', e);
}
};

export const getProducers = async function ():
Promise<GetProducers> {
try {
const response = await eosioAxios.post('v1/chain/get_producers', {
json: true,
limit: 10000,
});
return response.data as GetProducers;
} catch(e) {
console.error('Error on v1/chain/get_producers', e);
}
};

export const getABI = async function (
account: string,
): Promise<API.v1.GetAbiResponse> {
try {
return await eosio.v1.chain.get_abi(account);
} catch(e) {
console.error('Error on v1/chain/get_abi', e);
}
};


/** non API */
export const deserializeActionData = async function (
data: ActionType,
): Promise<ABISerializable> {
const contractAccount = data.account.toString();
const abi = await getABI(contractAccount);

if (!abi.abi) {
throw new Error(`No ABI for ${String(data.account)}`);
}

const action = Action.from(data, abi.abi);
return Serializer.objectify(action.decodeData(abi.abi)) as ABISerializable;
};

export const deserializeActionDataFromAbi = function (
data: ActionType,
abi: ABIDef,
): ABISerializable {
if (!abi) {
throw new Error(`No ABI for ${String(data.account)}`);
}
const action = Action.from(data, abi);
// eslint-disable-next-line
return Serializer.objectify(action.decodeData(abi));
};

export const serializeActionData = async function (
account: string,
name: string,
data: unknown,
): Promise<unknown> {
const response = await getABI(account);
if (!response) {
throw new Error(`No ABI for ${account}`);
}

const abi = ABI.from(response.abi);
const { hexString } = Serializer.encode({ object: data, abi, type: name });
return hexString;
};
38 changes: 38 additions & 0 deletions src/api/axiosInterceptors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
AxiosError,
AxiosInstance,
AxiosResponse,
InternalAxiosRequestConfig,
} from 'axios';

const MAX_REQUESTS_COUNT = 5;
let PENDING_REQUESTS = 0;

const onRequest = (config: InternalAxiosRequestConfig): InternalAxiosRequestConfig => {
if (PENDING_REQUESTS < MAX_REQUESTS_COUNT) {
PENDING_REQUESTS++;
return config;
}
};

const onRequestError = (error: AxiosError): Promise<AxiosError> => {
console.error(`[request error] [${JSON.stringify(error)}]`);
PENDING_REQUESTS--;
return Promise.reject(error);
};

const onResponse = (response: AxiosResponse) => {
PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1);
return response;
};

const onResponseError = (error: AxiosError) => {
PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1);
return error;
};

export const addInterceptors = (axiosInstance: AxiosInstance): AxiosInstance => {
axiosInstance.interceptors.request.use(onRequest, onRequestError);
axiosInstance.interceptors.response.use(onResponse, onResponseError);
return axiosInstance;
};
Loading
Loading