Skip to content

Commit

Permalink
types: minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed Jan 30, 2023
1 parent 72104d0 commit 06227c7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ module.exports = {
'jsdoc/require-returns-description': 0,
'jsdoc/require-property-description': 0,
'jsdoc/newline-after-description': 0,
// e.g. export default from .vue
'jsdoc/require-jsdoc': 0,
// poor syntax validator
'jsdoc/valid-types': 0,
// @TODO allow both return and returns
Expand Down
2 changes: 1 addition & 1 deletion assets/axios-debounce.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare module 'axios' {
interface AxiosRequestConfig {
idDebounce?: string|number;
debounceOptions: AxiosDebounceAdapterOptions;
debounceOptions?: AxiosDebounceAdapterOptions;
}
}
/**
Expand Down
2 changes: 1 addition & 1 deletion assets/axios-to-camel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function toCamel(obj) {

/**
*
* @param {AxiosInstance} instance
* @param {import('axios').AxiosInstance} instance
*/
export default function addToCamelInterceptor(instance) {
instance.interceptors.response.use(function(response) {
Expand Down
21 changes: 11 additions & 10 deletions assets/server-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getServerValidator = (fieldName) => withParams({type: 'server'}, fu

/**
* Преобразование ответа от сервера в объект серверных ошибок валидации
* @param {AxiosError} error - axios error
* @param {import('axios').AxiosError} error - axios error
* @param {object} sve - server validation errors config
* @return {boolean} hasErrors - были найдены ошибки
*/
Expand All @@ -36,13 +36,13 @@ export function fillServerErrors(error, sve) {

/**
* Получает первую ошибку валидации из ответа сервера
* @param {AxiosError} error - axios error
* @param {import('axios').AxiosError} error - axios error
* @param {string} startErrorText
* @returns {String|boolean}
* @returns {string|false}
*/
export function getValidationError(error, startErrorText = 'Error: ') {
let resErrors = error.response && error.response.data && error.response.data.errors;
let errorMessage = false;
let errorMessage;
if (resErrors) {
Object.keys(resErrors).some((key) => {
const message = Array.isArray(resErrors[key]) ? resErrors[key][0] : resErrors[key];
Expand All @@ -53,18 +53,18 @@ export function getValidationError(error, startErrorText = 'Error: ') {
});
}

return errorMessage;
return errorMessage || false;
}


/**
* Получает ошибку из ответа сервера
* @param {AxiosError|Error} error - axios error
* @param {import('axios').AxiosError|Error} error - axios error
* @param {string} startErrorText
* @returns {String}
* @returns {string}
*/
export function getErrorText(error, startErrorText = 'Error: ') {
if (error.response?.data?.error || error.response?.data?.message) {
if ('response' in error && (error.response.data?.error || error.response.data?.message)) {
// server error
let errorText = error.response.data.error?.message || error.response.data.message || error.response.data.error;
if (errorText?.toLowerCase() === 'not possible to exchange') {
Expand All @@ -89,12 +89,13 @@ export function getErrorText(error, startErrorText = 'Error: ') {

/**
* Получает код ошибки из ответа сервера
* @param {AxiosError} error - axios error
* @returns {String}
* @param {import('axios').AxiosError} error - axios error
* @returns {number|string}
*/
export function getErrorCode(error) {
if (error.response && error.response.data && (error.response.data.code || error.response.data.error)) {
// server error
return (error.response.data.error && error.response.data.error.code) || error.response.data.code;
}
return 0;
}
9 changes: 5 additions & 4 deletions composables/use-portfolio-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import {isValidMnemonic, walletFromMnemonic} from 'minterjs-wallet';
*/

/**
* @type {Object.<number, PortfolioWallet>}
* @type {Object.<number, PortfolioWallet> & {mnemonic: string}}
*/
let wallets = {};
let wallets = {mnemonic: ''};

export default function usePortfolioWallet(mnemonic) {
if (!mnemonic || !isValidMnemonic(mnemonic)) {
throw new Error('Invalid mnemonic');
}
// clear wallet list for new mnemonic
if (wallets.mnemonic !== mnemonic) {
wallets = {};
wallets = {
mnemonic,
};
}
wallets.mnemonic = mnemonic;

/**
* @param {number|string} portfolioId
Expand Down

0 comments on commit 06227c7

Please sign in to comment.