diff --git a/package.json b/package.json index c25aed28..0bb782d9 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "@babel/preset-env": "7.12.7", "@babel/preset-react": "7.12.7", "@babel/runtime": "7.12.5", + "@types/chrome": "^0.0.193", "@types/prop-types": "^15.7.4", "@types/react": "^17.0.37", "@types/react-dom": "^17.0.11", diff --git a/src/background/api/index.js b/src/background/api/index.js index 1922d75e..01a345f6 100644 --- a/src/background/api/index.js +++ b/src/background/api/index.js @@ -18,7 +18,7 @@ function getSharePrice(pool) { * @returns {Promise} */ export async function getBalance(address) { - let url = "/chain/account/info/" + address; + let url = "/chain/account/info/" + encodeURIComponent(address); let account = await commonFetch(url).catch(() => {}); if (account && account.code === 0) { return { ...account.data, address }; @@ -101,7 +101,7 @@ export async function getTransactionList(address) { */ export async function getAccountStakeInfo(address) { let url = - "/chain/account/delegations?address=" + address + "&size=" + MAX_LENGTH; + "/chain/account/delegations?address=" + encodeURIComponent(address) + "&size=" + encodeURIComponent(MAX_LENGTH); let accountStakeInfo = await commonFetch(url).catch(() => []); return accountStakeInfo; } @@ -112,7 +112,7 @@ export async function getAccountStakeInfo(address) { * @returns */ export async function getNodeStakeInfo(address) { - let url = "/validator/info?address=" + address; + let url = "/validator/info?address=" + encodeURIComponent(address); let validatorInfo = await commonFetch(url).catch(() => {}); return validatorInfo; } @@ -124,7 +124,7 @@ export async function getNodeStakeInfo(address) { */ export async function getUserDebondInfo(address) { let url = - "/chain/account/debonding?address=" + address + "&size=" + MAX_LENGTH; + "/chain/account/debonding?address=" + encodeURIComponent(address) + "&size=" + encodeURIComponent(MAX_LENGTH); let userDebondInfo = await commonFetch(url).catch(() => {}); return userDebondInfo; } @@ -135,7 +135,7 @@ export async function getUserDebondInfo(address) { * @returns */ export async function getNodeStakeList() { - let url = "/validator/list?pageSize=" + MAX_LENGTH; + let url = "/validator/list?pageSize=" + encodeURIComponent(MAX_LENGTH); let validatorList = await commonFetch(url).catch(() => []); return validatorList; } @@ -146,7 +146,7 @@ export async function getNodeStakeList() { * @returns */ export async function getSubmitStatus(txhash) { - let url = "/chain/transaction/" + txhash; + let url = "/chain/transaction/" + encodeURIComponent(txhash); let txStatus = await commonFetch(url).catch(() => {}); if (txStatus && txStatus.code === 0) { return txStatus.data; @@ -202,7 +202,7 @@ export async function getRpcRuntimeList() { * @returns */ export async function getRuntimeTxDetail(txhash, runtimeId) { - let url = `/runtime/transaction/info?id=${runtimeId}&hash=${txhash}`; + let url = `/runtime/transaction/info?id=${encodeURIComponent(runtimeId)}&hash=${encodeURIComponent(txhash)}`; let txDetail = await commonFetch(url).catch(() => {}); if (txDetail && txDetail.code === 0) { return txDetail.data; diff --git a/src/background/service/APIService.js b/src/background/service/APIService.js index 73067c37..991b152c 100644 --- a/src/background/service/APIService.js +++ b/src/background/service/APIService.js @@ -919,29 +919,21 @@ class APIService { } } notification = (hash,runtimeId) => { - let notifyId = runtimeId ? hash +"?runtime="+runtimeId : hash - let myNotificationID - extension.notifications && - extension.notifications.onClicked.addListener(function (clickId) { - if(myNotificationID === clickId){ - let url - if(runtimeId){ - url = getExplorerUrl() + "paratimes/transactions/" + clickId - }else{ - url = getExplorerUrl() + "transactions/" + clickId - } - openTab(url) - } - }); - let title = getLanguage('notificationTitle') - let message = getLanguage('notificationContent') - extension.notifications.create(notifyId, { - title: title, - message: message, + const notificationLinkAsId = runtimeId + ? getExplorerUrl() + "paratimes/transactions/" + encodeURIComponent(hash) + "?runtime=" + encodeURIComponent(runtimeId) + : getExplorerUrl() + "transactions/" + encodeURIComponent(hash) + + const notificationListener = (clickedNotificationId) => { + if(notificationLinkAsId !== clickedNotificationId) return + extension.notifications.onClicked.removeListener(notificationListener) + openTab(notificationLinkAsId) + } + extension.notifications.onClicked.addListener(notificationListener) + extension.notifications.create(notificationLinkAsId, { + title: getLanguage('notificationTitle'), + message: getLanguage('notificationContent'), iconUrl: '/img/oasis.png', type: 'basic' - },(notificationItem)=>{ - myNotificationID = notificationItem }); return } diff --git a/src/popup/pages/Record/index.js b/src/popup/pages/Record/index.js index 8b7ec105..f798eece 100644 --- a/src/popup/pages/Record/index.js +++ b/src/popup/pages/Record/index.js @@ -125,9 +125,9 @@ class Record extends React.Component { let hash = this.state.txDetail.txHash || this.state.txDetail.hash let url if (this.state.isEvmTx) { - url = getExplorerUrl() + "paratimes/transactions/" + hash + "?runtime=" + this.state.txDetail.runtimeId + url = getExplorerUrl() + "paratimes/transactions/" + encodeURIComponent(hash) + "?runtime=" + encodeURIComponent(this.state.txDetail.runtimeId) } else { - url = getExplorerUrl() + "transactions/" + hash + url = getExplorerUrl() + "transactions/" + encodeURIComponent(hash) } openTab(url) } diff --git a/src/popup/pages/Wallet/index.js b/src/popup/pages/Wallet/index.js index 34a77942..49d28d61 100644 --- a/src/popup/pages/Wallet/index.js +++ b/src/popup/pages/Wallet/index.js @@ -505,7 +505,7 @@ class Wallet extends React.Component { return className } onClickGoExplorer = () => { - let url = getExplorerUrl() + "accounts/detail/" + this.props.currentAccount.address + let url = getExplorerUrl() + "accounts/detail/" + encodeURIComponent(this.props.currentAccount.address) openTab(url) } renderListExplorer = (index) => { diff --git a/src/utils/extensionizer.d.ts b/src/utils/extensionizer.d.ts new file mode 100644 index 00000000..fe5b289f --- /dev/null +++ b/src/utils/extensionizer.d.ts @@ -0,0 +1,3 @@ +declare module 'extensionizer' { + export default chrome +} diff --git a/yarn.lock b/yarn.lock index 1237160a..1365069a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3602,6 +3602,14 @@ "@types/filesystem" "*" "@types/har-format" "*" +"@types/chrome@^0.0.193": + version "0.0.193" + resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.193.tgz#cd0dc5033f27a243d228aebe566c3ec19ef17e36" + integrity sha512-R8C84oqvk8A8C8G1viBd8qLpDr86Y/jwD+KLgzUekbIT9RGds6a9GnlQyg8P7ltnGogTMHkiEQK0ZlcrvTeo3Q== + dependencies: + "@types/filesystem" "*" + "@types/har-format" "*" + "@types/eslint@^7.2.6": version "7.2.12" resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.2.12.tgz#fefaa48a4db2415b621fe315e4baeedde525927e"