Skip to content

Commit

Permalink
fix: getTokenBalance in InterlayXcmRepository.ts (#850)
Browse files Browse the repository at this point in the history
* fix: getTokenBalance in InterlayXcmRepository.ts

* refactor: comments

* fix: add an error message logic

* fix: Also includes a fix when destination address to the EVM is blank.
  • Loading branch information
impelcrypto authored Jul 4, 2023
1 parent c52cdc8 commit c5f062e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/components/assets/transfer/XcmBridge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@
<span class="text--dot">・</span>
<span class="text--warning">{{ $t('assets.modals.xcmWarning.minBalIsRequired') }}</span>
</div>
<div
v-click-away="setIsMobileDisplayTooltip"
class="icon--help"
@click="setIsMobileDisplayTooltip"
>
<div v-click-away="setIsMobileDisplayTooltip" @click="setIsMobileDisplayTooltip">
<astar-icon-help size="20" />
<q-tooltip
v-model="isDisplayTooltip"
Expand Down
5 changes: 0 additions & 5 deletions src/components/assets/transfer/styles/xcm-bridge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@
font-weight: 700;
}

.icon--help {
font-size: 20px;
margin-bottom: -6px;
}

.container--warning {
display: flex;
flex-direction: column;
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/xcm/useXcmBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ export function useXcmBridge(selectedToken: Ref<Asset>) {
return;
}

const isBlankDestAddressToEvm =
isWithdrawalEthChain.value && sendingAmount && !inputtedAddress.value;
if (isBlankDestAddressToEvm) {
errMsg.value = t('warning.blankDestAddress');
return;
}

if (isDeposit.value) {
if (!checkIsEnoughMinBal(sendingAmount)) {
errMsg.value = t('warning.insufficientOriginChainBalance', {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default {
insufficientBalance: 'Insufficient {token} balance',
insufficientFee: 'Warning! Transaction might fail due to insufficient fee',
inputtedInvalidDestAddress: 'Inputted invalid destination address',
blankDestAddress: 'Destination address is blank',
inputtedInvalidAddress: 'Inputted invalid address',
selectedInvalidNetworkInWallet: 'Selected invalid network in your wallet',
insufficientBridgeAmount: 'Minimum transfer amount is {amount} {token}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { XcmTokenInformation } from 'src/modules/xcm';
import { container } from 'src/v2/common';
import { ExtrinsicPayload, IApi, IApiFactory } from 'src/v2/integration';
import { Asset } from 'src/v2/models';
import { XcmChain } from 'src/v2/models/XcmModels';
import { Chain, XcmChain } from 'src/v2/models/XcmModels';
import { TokensAccounts } from 'src/v2/repositories/implementations/xcm/AcalaXcmRepository';
import { Symbols } from 'src/v2/symbols';
import { XcmRepository } from '../XcmRepository';
Expand Down Expand Up @@ -71,6 +71,12 @@ export class InterlayXcmRepository extends XcmRepository {
token: Asset,
isNativeToken: boolean
): Promise<string> {
// Memo: avoid getting a UI error when the `token` is `ASTR` while the `monitorDestChainBalance` function(watch) in useXcmBridge.ts
// Reproduce the UI error: assets page -> transfer ASTR -> XCM -> flip the chains -> To: Interlay
const interlayChains = [Chain.INTERLAY, Chain.KINTSUGI];
if (!interlayChains.includes(token.originChain as Chain)) {
return '0';
}
const api = await this.apiFactory.get(chain.endpoint);

try {
Expand All @@ -83,6 +89,7 @@ export class InterlayXcmRepository extends XcmRepository {
return '0';
}
}

public async getNativeBalance(address: string, chain: XcmChain): Promise<BN> {
try {
const api = await this.apiFactory.get(chain.endpoint);
Expand Down

0 comments on commit c5f062e

Please sign in to comment.