diff --git a/src/components/message/Message.js b/src/components/message/Message.js index 852b80b309..fc34c6c7b3 100644 --- a/src/components/message/Message.js +++ b/src/components/message/Message.js @@ -6,7 +6,6 @@ import { getActiveTags, ppDebug, createState, - parseObjFromEncoding, getRequestDuration, getTsCookieFromStorage, getOrCreateDeviceID @@ -187,8 +186,9 @@ const Message = function ({ markup, meta, parentStyles, warnings }) { request('GET', `${window.location.origin}/credit-presentment/smart/message?${query}`).then( ({ data: resData }) => { const jsonData = resData.slice(resData.indexOf('')); - // TODO: Cleanup ternary and remove 'parseObjFromEncoding' from utils; only JSON.parse will be needed. - const data = jsonData.startsWith('{') ? JSON.parse(jsonData) : parseObjFromEncoding(jsonData); + + const data = JSON.parse(jsonData); + button.innerHTML = data.markup ?? markup ?? ''; const buttonWidth = button.offsetWidth; const buttonHeight = button.offsetHeight; diff --git a/src/utils/miscellaneous.js b/src/utils/miscellaneous.js index 95850b1e67..37209d9f16 100644 --- a/src/utils/miscellaneous.js +++ b/src/utils/miscellaneous.js @@ -99,19 +99,6 @@ export function request(method, url, { data, headers, withCredentials } = {}) { xhttp.send(typeof data === 'object' ? JSON.stringify(data) : data); }); } - -export function parseObjFromEncoding(encodedStr) { - // equivalent to JSON.parse(fromBinary(atob(encodedStr))) as in initScript - const binary = atob(encodedStr); - const bytes = new Uint8Array(binary.length); - for (let i = 0; i < bytes.length; i++) { - bytes[i] = binary.charCodeAt(i); - } - // need to use .apply instead of spread operator so IE can understand - const decodedStr = String.fromCharCode.apply(null, new Uint16Array(bytes.buffer)); - return JSON.parse(decodedStr); -} - export function createEvent(name) { if (typeof Event === 'function') { return new Event(name); diff --git a/tests/unit/spec/src/components/message/Message.test.js b/tests/unit/spec/src/components/message/Message.test.js index 6cab7a3e38..dacdcb84a7 100644 --- a/tests/unit/spec/src/components/message/Message.test.js +++ b/tests/unit/spec/src/components/message/Message.test.js @@ -1,7 +1,7 @@ import { getByText, fireEvent, queryByText } from '@testing-library/dom'; import Message from 'src/components/message/Message'; -import { request, createState, parseObjFromEncoding } from 'src/utils'; +import { request, createState } from 'src/utils'; import xPropsMock from 'utils/xPropsMock'; const ts = { @@ -15,17 +15,10 @@ jest.mock('src/utils', () => ({ getOrCreateDeviceID: jest.fn(() => 'uid_26a2522628_mtc6mjk6nti'), request: jest.fn(() => Promise.resolve({ - data: '' + data: '' }) ), - parseObjFromEncoding: jest.fn(() => ({ - markup: '