Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use encodeURIComponent everywhere #280

Merged
merged 3 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions src/background/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getSharePrice(pool) {
* @returns {Promise<Balance>}
*/
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 };
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 13 additions & 21 deletions src/background/service/APIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)=>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol what even was this callback

https://developer.chrome.com/docs/extensions/reference/notifications/#method-create

the docs don't give any info on when the browser will call it

myNotificationID = notificationItem
});
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/popup/pages/Record/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/popup/pages/Wallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/extensionizer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'extensionizer' {
export default chrome
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extensionizer doesn't have types, but it essentially does: globalThis.chrome || globalThis.browser https://github.com/MetaMask/extensionizer/blob/main/extension-instance.js#L39-L57. Those APIs are nearly identical https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities#javascript_apis, so I'm just using chrome's.

That makes all our extension.tabs.create({ calls typed!

I guess I should explicitly install @types/chrome tho.

}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down