Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function changeHistory({ pathname = null, params, push }) {
const p = Object.assign(params);
Object.keys(p).forEach(key => p[key] === undefined && delete p[key]);
const s = qs.parse(window.location.search);
Object.assign(s, p);
Object.keys(s).forEach(key => s[key] === null && delete s[key]);
const search = qs.stringify(s);
//############################################################################
// TERRIBLE WORKAROUND FOR ISSUE https://github.com/focallocal/fl-maps/issues/742
if (pathname && pathname !== location.pathname) {
console.log("##########", pathname + "?" + search);
location.href = pathname + "?" + search;
return;
}
//############################################################################
pathname = pathname || window.location.pathname;
if (push) {
history.push({ pathname, search });
} else {
history.replace({ pathname, search });
}
}
public async startWithdraw(
params: WithdrawRequest,
): Promise {
const request = { ...params, account: this.account };
const isAuthRequired = this.getAuthStatus("withdraw", params.asset_code);
const qs = queryString.stringify(request);
const response = await fetch(`${this.transferServer}/withdraw?${qs}`, {
headers: isAuthRequired ? this.getHeaders() : undefined,
});
const json = (await response.json()) as TransferResponse;
if (json.error) {
const error: TransferError = new Error(json.error);
error.originalResponse = json;
throw error;
}
// if this was an auth-required token, insert the JWT
if (
isAuthRequired &&
json.type === TransferResponseType.interactive_customer_info_needed &&
request({ url, method, params = {}, body }) {
if (this.authToken) {
/* eslint-disable */
params.token = this.authToken;
/* eslint-enable */
}
const urlWithQuery = `${url}?${queryString.stringify(params)}`;
const init = {
method,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
};
if (method !== 'get' && method !== 'head') {
init.body = JSON.stringify(body);
}
return fetch(`${this.prefix}/${urlWithQuery}`, init).then(res => {
if (res.status >= 400) {
throw new Error('Bad response from server');
componentWillMount() {
if (APITestStore.getApiDetail.description === '[]') {
const { controller, version, service, operationId } = this.state;
const queryObj = {
version,
operation_id: operationId,
};
defaultAxios.get(`${urlPrefix}/manager/v1/swaggers/${service}/controllers/${controller}/paths?${querystring.stringify(queryObj)}`).then((data) => {
data.paths.some((item) => {
if (item.operationId === operationId) {
const { basePath, url } = item;
APITestStore.setApiDetail(item);
this.setState({
loading: false,
requestUrl: `${urlPrefix}${basePath}${url}`,
});
return true;
}
return false;
});
});
} else {
const { basePath, url } = APITestStore.getApiDetail;
this.setState({
export const sendDataWithParams = (baseUrl, method, params, bodyObj) => {
const { url, query } = queryString.parseUrl(baseUrl);
const newQueryString = queryString.stringify({ ...query, ...params });
const newURL = newQueryString ? `${url}?${newQueryString}` : url;
return fetchData(newURL, {
method,
mode: 'cors',
cache: 'default',
redirect: 'follow',
headers: {
'Accept': 'application/json',
},
body: bodyObj ? JSON.stringify(bodyObj) : null,
});
};
private handleLoadLess() {
const query = queryString.parse(this.props.location.search);
query.page_size = (Number(query.page_size) - this.pageSize).toString();
history.push({ ...this.props.location, "search": queryString.stringify(query) });
}
'content-type': 'application/json;charset=utf-8',
};
let finalUrl = usev4 ? originalUrl : `${originalUrl}api_key=${v3Key}&`;
const method = httpMethod.toLowerCase();
const v4Token = userAccessToken ? userAccessToken : v4Key;
const headers = usev4
? { ...originalHeaders, authorization: `Bearer ${v4Token}` }
: originalHeaders;
const fetchOptions = {
method,
headers,
};
if (['get', 'delete'].includes(method)) {
finalUrl = finalUrl.concat(queryString.stringify(data));
} else {
fetchOptions.body = prepareData(data);
}
const response = await fetch(finalUrl, fetchOptions);
if (response.ok) {
return await response.json();
}
throw new Error(response.statusText);
} catch (error) {
return Promise.reject(error);
}
};
page: current - 1,
size: pageSize,
instanceId,
version,
params,
service: serviceName,
};
if (columnKey) {
const sorter = [];
sorter.push(columnKey);
if (order === 'asc') {
sorter.push('asc');
}
queryObj.sort = sorter.join(',');
}
return axios.get(`/manager/v1/instances?${querystring.stringify(queryObj)}`);
}
if (scrollTo === ScrollTarget.firstDiff) {
anchor = _getRelativeDiffAnchor({ diff });
} else {
const anchors = _getDiffAnchors(diff);
if (anchors.length) {
anchor = anchors[anchors.length - 1];
}
}
if (anchor) {
const newParams = { ...queryParams };
delete newParams.scrollTo;
const newLocation = {
...location,
hash: `#${anchor}`,
search: queryString.stringify(newParams),
};
history.push(newLocation);
}
}
}
if (!location.hash.length) {
return;
}
const element = _document.querySelector(location.hash);
if (element) {
element.scrollIntoView();
}
const makeHistoryOf: (params: any) => History = (params) => [
{
state: { name: 'courseSearch', data: { params } },
title: '',
url: `/search?${stringify(params)}`,
},
historyPushState,
historyReplaceState,
];