Skip to content

Commit

Permalink
add to-promise func (#497)
Browse files Browse the repository at this point in the history
* add to-promise func

* fix lint
  • Loading branch information
qwer951123 authored Jul 27, 2023
1 parent c79cf35 commit f1dd1e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
"typescript": "^5.0.4"
},
"packageManager": "yarn@3.5.0",
"stableVersion": "4.1.9-3"
"stableVersion": "4.1.9-4"
}
7 changes: 7 additions & 0 deletions packages/sdk/src/wallet/utils/to-promise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Observable, firstValueFrom, isObservable } from 'rxjs';

export function toPromise<T>(a: Observable<T> | Promise<T>): Promise<T> {
if (isObservable(a)) return firstValueFrom(a);

return a;
}
5 changes: 2 additions & 3 deletions packages/sdk/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '@acala-network/sdk-core';
import { BehaviorSubject, combineLatest, Observable, of, firstValueFrom } from 'rxjs';
import { map, switchMap, filter, catchError } from 'rxjs/operators';
import { FrameSystemAccountInfo } from '@polkadot/types/lookup';
import { TokenRecord, WalletConsts, BalanceData, PresetTokens, WalletConfigs, PriceProviders } from './types';
import { BelowExistentialDeposit, ChainType, Homa, Liquidity, SDKNotReady } from '..';
import { getMaxAvailableBalance } from './utils/get-max-available-balance';
Expand All @@ -36,6 +35,7 @@ import { AcalaTokenProvider } from './token-provider/acala';
import { DIDWeb3Name } from './web3name/did';
import { subscribeLiquidCrowdloanTokenPrice } from './utils/get-liquid-crowdloan-token-price';
import { Vesting } from './vesting';
import { toPromise } from './utils/to-promise';

export class Wallet implements BaseSDK {
private api: AnyApi;
Expand Down Expand Up @@ -358,9 +358,8 @@ export class Wallet implements BaseSDK {
public async checkTransfer(address: string, currency: MaybeCurrency, amount: FN, direction: 'from' | 'to' = 'to') {
const { nativeToken } = this.getPresetTokens();
const token = this.getToken(currency);
const tokenName = forceToCurrencyName(currency);
const isNativeToken = nativeToken.isEqual(token);
const accountInfo = (await this.api.query.system.account(address)) as unknown as FrameSystemAccountInfo;
const accountInfo = await toPromise(this.api.query.system.account(address));
const balance = await this.getBalance(currency, address);

let needCheck = true;
Expand Down

0 comments on commit f1dd1e7

Please sign in to comment.