From f397b54f272091e440f8729aaf7bd659ae1c6e7f Mon Sep 17 00:00:00 2001 From: esaminu Date: Wed, 9 Feb 2022 12:10:12 +0400 Subject: [PATCH] fix: revert query-string append changes --- packages/frontend/.eslintrc.js | 4 ---- .../frontend/src/redux/actions/account.js | 22 ++++++------------- .../frontend/src/redux/slices/sign/index.js | 13 +++++------ 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/packages/frontend/.eslintrc.js b/packages/frontend/.eslintrc.js index a0f4872409..ef7f1a06e9 100644 --- a/packages/frontend/.eslintrc.js +++ b/packages/frontend/.eslintrc.js @@ -29,10 +29,6 @@ module.exports = { 'name': 'URLSearchParams', 'message': 'Use `query-string` package instead' }], - 'no-restricted-properties': ['error', { - 'property': 'searchParams', - 'message': 'Use `query-string` package instead' - }], 'no-restricted-syntax': ['error', { 'selector': `VariableDeclarator[id.type='ObjectPattern'] Property[key.name='searchParams']`, 'message': 'URL.searchParams is not allowed, Use `query-string` package instead' diff --git a/packages/frontend/src/redux/actions/account.js b/packages/frontend/src/redux/actions/account.js index 37c8f501b1..78ca4b3b38 100644 --- a/packages/frontend/src/redux/actions/account.js +++ b/packages/frontend/src/redux/actions/account.js @@ -207,21 +207,13 @@ export const allowLogin = () => async (dispatch, getState) => { const availableKeys = await wallet.getAvailableKeys(); const allKeys = availableKeys.map(key => key.toString()); - const url = new URL(successUrl); - const originalSearchParams = parse(url.search); - window.location = successUrl.replace(url.search, `?${stringify( - { - ...originalSearchParams, - account_id: wallet.accountId, - public_key: publicKey, - all_keys: allKeys.join(","), - }, - { - skipEmptyString: true, - skipNull: true, - arrayFormat: "comma" - } - )}`); + const parsedUrl = new URL(successUrl); + parsedUrl.searchParams.set('account_id', wallet.accountId); + if (publicKey) { + parsedUrl.searchParams.set('public_key', publicKey); + } + parsedUrl.searchParams.set('all_keys', allKeys.join(',')); + window.location = parsedUrl.href; } else { await dispatch(withAlert(addAccessKey(wallet.accountId, contractId, publicKey, false, methodNames), { data: { title } })); dispatch(redirectTo('/authorized-apps', { globalAlertPreventClear: true })); diff --git a/packages/frontend/src/redux/slices/sign/index.js b/packages/frontend/src/redux/slices/sign/index.js index b7a4afd84e..3b020d722f 100644 --- a/packages/frontend/src/redux/slices/sign/index.js +++ b/packages/frontend/src/redux/slices/sign/index.js @@ -1,7 +1,6 @@ import { createAsyncThunk, createAction } from "@reduxjs/toolkit"; import BN from 'bn.js'; import cloneDeep from 'lodash.clonedeep'; -import { parse, stringify } from "query-string"; import { createSelector } from "reselect"; import { Mixpanel } from "../../../mixpanel"; @@ -80,13 +79,13 @@ export const handleSignTransactions = createAsyncThunk( } ); -export function addQueryParams(baseUrl, queryParams = {}) { +export function addQueryParams(baseUrl, queryParams) { const url = new URL(baseUrl); - const originalSearchParams = parse(url.search); - return baseUrl.replace(url.search,`?${stringify({...originalSearchParams, ...queryParams}, { - skipEmptyString: true, - skipNull: true, - })}`); + for (let key in queryParams) { + const param = queryParams[key]; + if(param) url.searchParams.set(key, param); + } + return url.toString(); } export const removeSuccessTransactions = ({ transactions, successHashes }) => {