Skip to content

Commit

Permalink
Merge pull request #339 from Conflux-Chain/Version-v0.6.6
Browse files Browse the repository at this point in the history
Release: Version v0.6.6 RC
  • Loading branch information
yqrashawn committed May 18, 2021
2 parents d6b0e0c + cd3cf80 commit e473e80
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Current Develop Branch

## 0.6.6 Tue May 18 2021

- fix: block adding tokens without decimal() method (#338)

## 0.6.5 Wed May 12 2021

- fix: internal contract get code (#335)
Expand Down
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json
Expand Up @@ -396,6 +396,9 @@
"dataBackupFoundInfo": {
"message": "Some of your account data was backed up during a previous installation of ConfluxPortal. This could include your settings, contacts, and tokens. Would you like to restore this data now?"
},
"decimalMethodNotFound": {
"message": "Don't support token without decimal() method"
},
"decimalsMustZerotoTen": {
"message": "Decimals must be at least 0, and not over 36."
},
Expand Down
3 changes: 3 additions & 0 deletions app/_locales/zh_CN/messages.json
Expand Up @@ -350,6 +350,9 @@
"data": {
"message": "数据"
},
"decimalMethodNotFound": {
"message": " 钱包目前不支持没有 decimal() 方法的代币"
},
"decimalsMustZerotoTen": {
"message": "小数位最小为0并且不超过36位."
},
Expand Down
2 changes: 1 addition & 1 deletion app/manifest.json
@@ -1,7 +1,7 @@
{
"name": "ConfluxPortal",
"short_name": "ConfluxPortal",
"version": "0.6.5",
"version": "0.6.6",
"manifest_version": 2,
"author": "https://conflux-chain.org",
"description": "__MSG_appDescription__",
Expand Down
47 changes: 31 additions & 16 deletions ui/app/helpers/utils/token-util.js
Expand Up @@ -5,7 +5,7 @@ import BigNumber from 'bignumber.js'
const DEFAULT_SYMBOL = ''
const DEFAULT_DECIMALS = '0'

async function getSymbolFromContract (tokenAddress) {
async function getSymbolFromContract(tokenAddress) {
const token = util.getContractAtAddress(tokenAddress)

try {
Expand All @@ -19,7 +19,7 @@ async function getSymbolFromContract (tokenAddress) {
}
}

async function getDecimalsFromContract (tokenAddress) {
async function getDecimalsFromContract(tokenAddress) {
const token = util.getContractAtAddress(tokenAddress)

try {
Expand All @@ -34,11 +34,11 @@ async function getDecimalsFromContract (tokenAddress) {
}
}

function getContractMetadata (tokenAddress, casedContractMap) {
function getContractMetadata(tokenAddress, casedContractMap) {
return tokenAddress && casedContractMap[tokenAddress.toLowerCase()]
}

async function getSymbol (tokenAddress, contractMap) {
async function getSymbol(tokenAddress, contractMap) {
let symbol = await getSymbolFromContract(tokenAddress)

if (!symbol) {
Expand All @@ -52,7 +52,7 @@ async function getSymbol (tokenAddress, contractMap) {
return symbol
}

async function getDecimals (tokenAddress, contractMap) {
async function getDecimals(tokenAddress, contractMap) {
let decimals = await getDecimalsFromContract(tokenAddress)

if (!decimals || decimals === '0') {
Expand All @@ -66,7 +66,7 @@ async function getDecimals (tokenAddress, contractMap) {
return decimals
}

export async function fetchSymbolAndDecimals (tokenAddress, contractMap) {
export async function fetchSymbolAndDecimals(tokenAddress, contractMap) {
let symbol, decimals

try {
Expand All @@ -85,7 +85,11 @@ export async function fetchSymbolAndDecimals (tokenAddress, contractMap) {
}
}

export async function getSymbolAndDecimals (tokenAddress, contractMap, existingTokens = []) {
export async function getSymbolAndDecimals(
tokenAddress,
contractMap,
existingTokens = []
) {
const existingToken = existingTokens.find(
({ address }) => tokenAddress === address
)
Expand All @@ -101,10 +105,21 @@ export async function getSymbolAndDecimals (tokenAddress, contractMap, existingT

try {
symbol = await getSymbol(tokenAddress, contractMap)
} catch (error) {
log.warn(
`symbol() calls for token at address ${tokenAddress} resulted in error:`,
error
)
}

try {
decimals = await getDecimals(tokenAddress, contractMap)
if (decimals === undefined) {
decimals = 'FAILED'
}
} catch (error) {
log.warn(
`symbol() and decimal() calls for token at address ${tokenAddress} resulted in error:`,
`decimal() calls for token at address ${tokenAddress} resulted in error:`,
error
)
}
Expand All @@ -115,10 +130,10 @@ export async function getSymbolAndDecimals (tokenAddress, contractMap, existingT
}
}

export function tokenInfoGetter (contractMap) {
export function tokenInfoGetter(contractMap) {
const tokens = {}

return async (address) => {
return async address => {
if (tokens[address]) {
return tokens[address]
}
Expand All @@ -129,22 +144,22 @@ export function tokenInfoGetter (contractMap) {
}
}

export function calcTokenAmount (value, decimals) {
export function calcTokenAmount(value, decimals) {
const multiplier = Math.pow(10, Number(decimals || 0))
return new BigNumber(String(value)).div(multiplier)
}

export function calcTokenValue (value, decimals) {
export function calcTokenValue(value, decimals) {
const multiplier = Math.pow(10, Number(decimals || 0))
return new BigNumber(String(value)).times(multiplier)
}

export function getTokenValue (tokenParams = []) {
const valueData = tokenParams.find((param) => param.name === '_value')
export function getTokenValue(tokenParams = []) {
const valueData = tokenParams.find(param => param.name === '_value')
return valueData && valueData.value
}

export function getTokenToAddress (tokenParams = []) {
const toAddressData = tokenParams.find((param) => param.name === '_to')
export function getTokenToAddress(tokenParams = []) {
const toAddressData = tokenParams.find(param => param.name === '_to')
return toAddressData ? toAddressData.value : tokenParams[0].value
}
5 changes: 5 additions & 0 deletions ui/app/pages/add-token/add-token.component.js
Expand Up @@ -159,6 +159,11 @@ class AddToken extends Component {

async attemptToAutoFillTokenParams(address) {
const { symbol = '', decimals = 0 } = await this.tokenInfoGetter(address)
if (decimals === 'FAILED') {
return this.setState({
customDecimalsError: this.context.t('decimalMethodNotFound'),
})
}

const autoFilled = Boolean(symbol && decimals)
this.setState({ autoFilled })
Expand Down

0 comments on commit e473e80

Please sign in to comment.