Skip to content

Commit

Permalink
add to-promise func
Browse files Browse the repository at this point in the history
  • Loading branch information
qwer951123 committed Jul 27, 2023
1 parent c79cf35 commit 073dc86
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";

Check failure on line 1 in packages/sdk/src/wallet/utils/to-promise.ts

View workflow job for this annotation

GitHub Actions / Linting (16.x)

Replace `"rxjs"` with `'rxjs'`

export function toPromise <T extends any>(a: Observable<T> | Promise<T>): Promise<T> {

Check failure on line 3 in packages/sdk/src/wallet/utils/to-promise.ts

View workflow job for this annotation

GitHub Actions / Linting (16.x)

Delete `·`

Check failure on line 3 in packages/sdk/src/wallet/utils/to-promise.ts

View workflow job for this annotation

GitHub Actions / Linting (16.x)

Constraining the generic type `T` to `any` does nothing and is unnecessary
if (isObservable(a)) return firstValueFrom(a);

return a;
}

Check failure on line 7 in packages/sdk/src/wallet/utils/to-promise.ts

View workflow job for this annotation

GitHub Actions / Linting (16.x)

Insert `⏎`
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 073dc86

Please sign in to comment.