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

Tech/sync/master/1.2.0 #318

Merged
merged 6 commits into from
Jun 17, 2021
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
7 changes: 5 additions & 2 deletions src/store/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ const actions = {
accountAsset.externalAddress = externalAddress
}
if (accountAsset.externalAddress) {
const externalBalance = await dispatch('web3/getBalanceByEvmAddress', { address: accountAsset.externalAddress }, { root: true })
accountAsset.externalBalance = externalBalance
const { value, decimals } = await dispatch('web3/getBalanceByEvmAddress', { address: accountAsset.externalAddress }, { root: true })
accountAsset.externalBalance = value
if (!accountAsset.externalDecimals) {
accountAsset.externalDecimals = decimals
}
}
} catch (error) {
console.error(error)
Expand Down
9 changes: 5 additions & 4 deletions src/store/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,31 +357,32 @@ const actions = {

async getBalanceByEvmAddress ({ commit, getters, dispatch }, { address }) {
let value = ZeroStringValue
let decimals = 18
commit(types.GET_BALANCE_REQUEST)
try {
const web3 = await web3Util.getInstance()
const isNativeEvmToken = isEthereumAddress(address)
if (isNativeEvmToken) {
value = await dispatch('getEvmBalance')
} else {
const precision18 = new FPNumber(0)
const tokenInstance = new web3.eth.Contract(ABI.balance as any)
tokenInstance.options.address = address
const account = getters.evmAddress
const methodArgs = [account]
const balanceOfMethod = tokenInstance.methods.balanceOf(...methodArgs)
const decimalsMethod = tokenInstance.methods.decimals()
const balance = await balanceOfMethod.call()
const decimals = await decimalsMethod.call()
const precision18 = new FPNumber(0)
value = precision18.add(FPNumber.fromCodecValue(`${balance}`, +decimals)).toCodecString()
decimals = +(await decimalsMethod.call())
value = precision18.add(FPNumber.fromCodecValue(`${balance}`, decimals)).toCodecString()
}
commit(types.GET_BALANCE_SUCCESS)
} catch (error) {
console.error(error)
commit(types.GET_BALANCE_FAILURE)
}

return value
return { value, decimals }
},
async getEvmTokenAddressByAssetId ({ commit, getters }, { address }) {
commit(types.GET_EVM_TOKEN_ADDRESS_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Storage } from '@sora-substrate/util'
import { storage as soraStorage } from '@soramitsu/soraneo-wallet-web'

export const settingsStorage = new Storage('settings')
export const settingsStorage = new Storage('dexSettings')

export default soraStorage
21 changes: 13 additions & 8 deletions src/views/Bridge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<s-button
class="el-button--next s-typography-button--large"
type="primary"
:disabled="!isAssetSelected || !areNetworksConnected || !isValidNetworkType || !isAssetSelected || isZeroAmount || isInsufficientXorForFee || isInsufficientEvmNativeTokenForFee || isInsufficientBalance || !isRegisteredAsset"
:disabled="!isAssetSelected || !areNetworksConnected || !isValidNetworkType || !isAssetSelected || isZeroAmount || isInsufficientXorForFee || isInsufficientEvmNativeTokenForFee || isInsufficientBalance || !isRegisteredAsset || feesFetching"
@click="handleConfirmTransaction"
>
<template v-if="!isAssetSelected">
Expand Down Expand Up @@ -245,6 +245,7 @@ export default class Bridge extends Mixins(
showSelectTokenDialog = false
showSelectNetworkDialog = false
showConfirmTransactionDialog = false
feesFetching = false

get isNetworkAConnected () {
return this.isSoraToEvm ? this.isSoraAccountConnected : this.isExternalAccountConnected
Expand Down Expand Up @@ -361,7 +362,7 @@ export default class Bridge extends Mixins(
this.withApi(async () => {
await this.setEvmNetwork(bridgeApi.externalNetwork)
await this.getRegisteredAssets()
this.getNetworkFees()
await this.getNetworkFees()
})
}

Expand All @@ -384,9 +385,9 @@ export default class Bridge extends Mixins(
this.isFieldAmountFocused = true
}

handleSwitchItems (): void {
async handleSwitchItems (): Promise<void> {
this.setSoraToEvm(!this.isSoraToEvm)
this.getNetworkFees()
await this.getNetworkFees()
}

handleMaxValue (): void {
Expand Down Expand Up @@ -422,7 +423,7 @@ export default class Bridge extends Mixins(
async selectAsset (selectedAsset: any): Promise<void> {
if (selectedAsset) {
await this.setAssetAddress(selectedAsset?.address ?? '')
this.getNetworkFees()
await this.getNetworkFees()
}
}

Expand All @@ -434,10 +435,14 @@ export default class Bridge extends Mixins(
})
}

private getNetworkFees (): void {
private async getNetworkFees (): Promise<void> {
if (this.isRegisteredAsset) {
this.getNetworkFee()
this.getEvmNetworkFee()
this.feesFetching = true
await Promise.all([
this.getNetworkFee(),
this.getEvmNetworkFee()
])
this.feesFetching = false
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ module.exports = {
{ loader: require.resolve('css-unicode-loader') })
})
})

if (process.env.NODE_ENV === 'production') {
const buildDateTime = Date.now()
config.output.filename = `js/[name].[contenthash:8].${buildDateTime}.js`
config.output.chunkFilename = `js/[name].[contenthash:8].${buildDateTime}.js`
}
},
css: {
loaderOptions: {
Expand Down