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

Misc improvements #282

Merged
merged 7 commits into from
Aug 5, 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
5 changes: 2 additions & 3 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"scripts": ["common.js", "background.js"],
"persistent": true
},
"web_accessible_resources": [
"oasis-xu-frame.html"
]
"web_accessible_resources": ["oasis-xu-frame.html"],
"externally_connectable": { "ids": [] }
Copy link
Contributor

Choose a reason for hiding this comment

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

What's a benefit of adding this entry when empty ids array is the same as unspecified externally_connectable manifest key (as long as this theory is true)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Empty externally_connectable would do the same. But I think this is easier to understand intuitively, without looking at documentation :D
and I can't add a comment

}
32 changes: 16 additions & 16 deletions src/background/api/txHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ export async function getTxFee(tw, publicKey, retryTime) {
const oasisClient = getOasisClient()
let gasResult = await tw.estimateGas(oasisClient, publicKey)
resolve(gasResult)
} catch (error) {
} catch (errorOnFirstTry) {
if (retryTime > 0) {
setTimeout(async () => {
try {
resolve(await getTxFee(tw, publicKey, retryTime))
} catch (error) {
reject(error)
} catch (errorOnRetry) {
reject(errorOnFirstTry)
}
}, RETRY_DELAY);
} else {
reject(error)
reject(errorOnFirstTry)
}
}
})
Expand All @@ -88,17 +88,17 @@ export async function getChainContext(retryTime) {
const oasisClient = getOasisClient()
let chainContext = await oasisClient.consensusGetChainContext()
resolve(chainContext)
} catch (error) {
} catch (errorOnFirstTry) {
if (retryTime > 0) {
setTimeout(async () => {
try {
resolve(await getChainContext(retryTime))
} catch (error) {
reject(error)
} catch (errorOnRetry) {
reject(errorOnFirstTry)
}
}, RETRY_DELAY);
} else {
reject(error)
reject(errorOnFirstTry)
}
}
})
Expand All @@ -121,17 +121,17 @@ export async function submitTx(tw, retryTime) {
const oasisClient = getOasisClient()
let signSubmit = await tw.submit(oasisClient)
resolve(signSubmit)
} catch (error) {
} catch (errorOnFirstTry) {
if (retryTime > 0) {
setTimeout(async () => {
try {
resolve(await submitTx(tw, retryTime))
} catch (err) {
reject(err)
} catch (errorOnRetry) {
reject(errorOnFirstTry)
}
}, RETRY_DELAY);
} else {
reject(error)
reject(errorOnFirstTry)
}
}
})
Expand Down Expand Up @@ -254,17 +254,17 @@ function getRuntimeNonce(accountsWrapper,address,retryTime){
const oasisClient = getOasisClient()
let nonceResult = await accountsWrapper.queryNonce().setArgs({ address: address }).query(oasisClient);
resolve(nonceResult)
} catch (error) {
} catch (errorOnFirstTry) {
if (retryTime > 0) {
setTimeout(async () => {
try {
resolve(await getRuntimeNonce(accountsWrapper,address,retryTime))
} catch (error) {
reject(error)
} catch (errorOnRetry) {
reject(errorOnFirstTry)
}
}, RETRY_DELAY);
} else {
reject(error)
reject(errorOnFirstTry)
}
}
})
Expand Down
4 changes: 3 additions & 1 deletion src/background/service/APIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ class APIService {
const tw = oasis.staking.allowWrapper()
params.method = TRANSACTION_TYPE.StakingAllow
params.toAddress = oasis.staking.addressToBech32(await oasis.staking.addressFromRuntimeID(oasis.misc.fromHex(params.runtimeId)))
let result = await this.submitTxBody(params, tw,true,(data)=>this.depositToParatimeAccount(params,resolve,reject,data)).catch(err=>err)
let result = await this.submitTxBody(params, tw, true, (data) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to use curly braces here

Copy link
Member Author

Choose a reason for hiding this comment

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

My preference is to have a curly for multiline

Copy link
Contributor

Choose a reason for hiding this comment

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

also nice to use braces for statements (even single statements imo) and no braces for expressions

this.depositToParatimeAccount(params, resolve, reject, data)
}).catch(err=>err)
if(result&&result.error){
reject({error:result.error})
}
Expand Down
2 changes: 1 addition & 1 deletion src/popup/pages/NodeDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class StakeNodeDetail extends React.Component {
let entityId = addressSlice(this.state.entityId)
let validatorName = nodeDetail.validatorName || nodeDetail.name || addressSlice(address, 6)
let statusText = nodeDetail.commission || this.state.commission || 0
statusText = new BigNumber(statusText).multipliedBy(100).toFixed(1, 1).toString() + "%"
statusText = new BigNumber(statusText).multipliedBy(100).toFixed(1, 1) + "%"
let icon = nodeDetail.icon || DEFAULT_VALIDATOR_ICON
return (
<div className={"node-detail-top-detail"}>
Expand Down
3 changes: 1 addition & 2 deletions src/popup/pages/Send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,7 @@ class SendPage extends React.Component {
let accountInfo = this.props.accountInfo

let shares = this.state.reclaimShare
let amount = new BigNumber(this.state.amount).toString()
amount = toNonExponential(amount)
let amount = new BigNumber(this.state.amount).toFixed()
let toAddress = this.getToAddress()

let nonce = trimSpace(this.state.nonce) || accountInfo.nonce
Expand Down
2 changes: 1 addition & 1 deletion src/popup/pages/Staking/MyStaking.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MyStaking extends React.Component {
getStakePercent = (total_balance, delegations_balance) => {
let percent = "0"
if (new BigNumber(total_balance).gt(0)) {
percent = new BigNumber(delegations_balance).dividedBy(total_balance).multipliedBy(100).toFixed(4, 1).toString()
percent = new BigNumber(delegations_balance).dividedBy(total_balance).multipliedBy(100).toFixed(4, 1)
}
percent = percent + "%"
return percent
Expand Down
2 changes: 1 addition & 1 deletion src/popup/pages/Staking/StakeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class StakeNode extends React.Component {
renderNodeItem = (item, index) => {
let showAddress = addressSlice(item.entityAddress, 8)
let statusText = item.commission || 0
statusText = new BigNumber(statusText).multipliedBy(100).toFixed(1, 1).toString() + "%"
statusText = new BigNumber(statusText).multipliedBy(100).toFixed(1, 1) + "%"
let validatorName = item.name || showAddress
let icon = item.icon || DEFAULT_VALIDATOR_ICON
let delegators = item.delegators
Expand Down
33 changes: 4 additions & 29 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function getDisplayAmount(number, fixed = 4) {
if (isNaN(parseFloat(number)) || number === 0) {
return '0.00';
}
let showAmount = new BigNumber(number).toFixed(fixed, 1).toString()
let showAmount = new BigNumber(number).toFixed(fixed, 1)
return toNonExponential(showAmount)
}

Expand Down Expand Up @@ -87,7 +87,7 @@ export function getAmountForUI(rawAmount, decimal = cointypes.decimals) {
* @param {string} str
*/
export function trimSpace(str) {
return str.replace(/(^\s*)|(\s*$)/g, "").replace(/[\r\n]/g, "")
return str.trim().replace(/[\r\n]/g, "")
}

/**
Expand Down Expand Up @@ -164,14 +164,7 @@ export function copyText(text) {
*/
export function getNumberDecimals(number) {
if (isNumber(number)) {
let newNumber = new BigNumber(number).minus(new BigNumber(number).toFixed(0, 1).toString()).toString()
let splitList = newNumber.split('.');
if (splitList.length > 1) {
let littleNumber = splitList[1]
return littleNumber.length
} else {
return 0
}
return new BigNumber(number).decimalPlaces()
} else {
return 0
}
Expand Down Expand Up @@ -218,25 +211,7 @@ export function getPrettyAddress(address) {
* @returns
*/
export function getQueryStringArgs(url) {
let qs = url || ""
let paramSplit = qs.split("?")
let paramStr = ''
if (paramSplit.length > 1) {
paramStr = paramSplit[1]
}
var args = {};
var items = paramStr.length > 0 ? paramStr.split("&") : [],
item = null, name = null, value = null;
var len = items.length;
for (var i = 0; i < len; i++) {
item = items[i].split("=");
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if (name.length > 0) {
args[name] = value
}
}
return args;
return Object.fromEntries(new URLSearchParams(url.split('?')[1]))
}

export function getOriginFromUrl(url) {
Expand Down