rxjs/operators#take TypeScript Examples
The following examples show how to use
rxjs/operators#take.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: operation-details.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
async checkOnBlockchain(): Promise<void> {
const selectedHorizonApi = await this.horizonApisQuery.getSelectedHorizonApi$.pipe(take(1))
.toPromise();
const network = selectedHorizonApi.networkPassphrase === Networks.PUBLIC
? 'public'
: 'testnet';
const operation = await this.operation$.pipe(take(1)).toPromise();
// TODO: This needs to be dynamic
this.globalsService.window.open(
`https://stellar.expert/explorer/${network}/tx/${operation.operationRecord.transaction_hash}`,
'_blank'
);
}
Example #2
Source File: lp-statistics.component.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
public refreshStatistics(): void {
this.lpService.setStatisticsLoading(true);
this.lpService
.getStatistics()
.pipe(
switchMap(() => this.lpService.getDeposits()),
take(1)
)
.subscribe(() => {
this.lpService.setStatisticsLoading(false);
this.cdr.detectChanges();
});
}
Example #3
Source File: path-payment-form.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
async searchAsset(formValue: 'from' | 'to'): Promise<void> {
const myAssets = await this.myAssets$.pipe(take(1)).toPromise();
this.nzDrawerService.create<AssetSearcherComponent>({
nzContent: AssetSearcherComponent,
nzPlacement: 'bottom',
nzTitle: this.translateService.instant('SWAP.SELECT_ASSET_TITLE'),
nzHeight: '100%',
nzCloseOnNavigation: true,
nzContentParams: {
defaultAssets: myAssets,
assetSelectedFunc: asset => {
if (formValue === 'from') {
this.swapForm.get(['fromAsset', 'asset'])?.setValue(asset);
}
if (formValue === 'to') {
this.swapForm.get(['toAsset', 'asset'])?.setValue(asset);
}
},
disableCustomAsset: formValue === 'from',
disableCuratedAssetByCreitTech: formValue === 'from',
}
});
}
Example #4
Source File: liquidity-providing.service.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
private waitForReceipt = (hash: string): Observable<TransactionReceipt> => {
return interval(3000).pipe(
switchMap(async () => {
const tx = await this.web3PublicService[this.blockchain].getTransactionReceipt(hash);
return tx;
}),
filter<TransactionReceipt>(Boolean),
tap(receipt => {
if (receipt.status === false) {
this.lpNotificationService.showErrorNotification(receipt.transactionHash);
}
}),
take(1)
);
};
Example #5
Source File: xdr-signer.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
async onAccepted(): Promise<void> {
const selectedAccount = await this.selectedAccount$.pipe(take(1)).toPromise();
if (!selectedAccount) {
// TODO: Handle this case
return;
}
switch (selectedAccount.type) {
case 'with_secret_key':
const passwordAuthTokenActive = await this.settingsQuery.passwordAuthTokenActive$
.pipe(take(1))
.toPromise();
if (passwordAuthTokenActive) {
await this.signWithDeviceAuthToken(selectedAccount);
} else {
await this.signWithPassword(selectedAccount);
}
break;
case 'with_ledger_wallet':
await this.signWithLedger(selectedAccount);
break;
case 'with_trezor_wallet':
await this.signWithTrezor(selectedAccount);
break;
}
}
Example #6
Source File: staking.service.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
/**
* Reloads staking token balance, earned rewards, amount with rewards, apr.
* @return Observable<number | BigNumber>
*/
public reloadStakingStatistics(): Observable<number | BigNumber> {
this._stakingStatisticsLoading$.next(true);
this.getApr().subscribe();
return this.needLogin$.pipe(
take(1),
switchMap(needLogin => {
if (needLogin) {
return EMPTY;
}
return this.getStakingTokenBalance().pipe(
switchMap(stakingTokenBalance => this.getAmountWithRewards(stakingTokenBalance)),
switchMap(amountWithRewards => this.getEarnedRewards(amountWithRewards))
);
}),
finalize(() => this._stakingStatisticsLoading$.next(false))
);
}
Example #7
Source File: share-popover.page.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
onClickCopy() {
this.uploadService.generatedUrl$
.pipe(
take(1),
switchMap(url => Clipboard.write({ string: url })),
switchMap(() => this.presentToastCopied()),
takeUntil(this.destroy$)
)
.subscribe();
}
Example #8
Source File: sign-xdr.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
async onAccepted(): Promise<void> {
const selectedAccount = await this.selectedAccount$.pipe(take(1)).toPromise();
if (!selectedAccount) {
// TODO: Handle this case
return;
}
switch (selectedAccount.type) {
case 'with_secret_key':
const passwordAuthTokenActive = await this.settingsQuery.passwordAuthTokenActive$
.pipe(take(1))
.toPromise();
if (passwordAuthTokenActive) {
await this.signWithDeviceAuthToken(selectedAccount);
} else {
await this.signWithPassword(selectedAccount);
}
break;
case 'with_ledger_wallet':
await this.signWithLedger(selectedAccount);
break;
case 'with_trezor_wallet':
await this.signWithTrezor(selectedAccount);
break;
}
}
Example #9
Source File: statistics.component.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
public refreshStatistics(): void {
this.stakingLpService
.getTotalBalanceAndRewards()
.pipe(take(1))
.subscribe(() => {
this.stakingLpService.toggleLoading('balanceAndRewards', false);
});
this.stakingLpService
.getTvlMultichain()
.pipe(
switchMap(() => this.stakingLpService.getTvlStaking()),
tap(() => this.stakingLpService.getTotalTvl()),
switchMap(() => this.stakingLpService.getTtv()),
take(1)
)
.subscribe(() => {
this.stakingLpService.toggleLoading('tvlAndTtv', false);
});
}
Example #10
Source File: asset-searcher.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
async onCustomAssetConfirmed(): Promise<void> {
const horizonApi = await this.horizonApisQuery.getSelectedHorizonApi$.pipe(take(1)).toPromise();
if (this.customAssetForm.invalid || !horizonApi) {
return;
}
const valueToEmit = {
_id: this.walletsAssetsService.formatBalanceLineId({
asset_code: this.customAssetForm.value.assetCode,
asset_issuer: this.customAssetForm.value.assetIssuer,
// We know this could be alphanum12 but is only to fool the type
asset_type: 'credit_alphanum4',
}),
assetCode: this.customAssetForm.value.assetCode,
assetIssuer: this.customAssetForm.value.assetIssuer,
// We don't need this passphrase, but we send it anyway in case in the future we want to add something that it requires it
networkPassphrase: horizonApi.networkPassphrase
};
this.assetSelected.emit(valueToEmit);
if (!!this.assetSelectedFunc) {
this.assetSelectedFunc(valueToEmit);
}
this.nzDrawerRef.close();
}
Example #11
Source File: statistics.component.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
private getStatisticsData(): void {
this.stakingLpService
.getTvlMultichain()
.pipe(
switchMap(() => this.stakingLpService.getTvlStaking()),
tap(() => this.stakingLpService.getTotalTvl()),
switchMap(() => this.stakingLpService.getTtv()),
take(1)
)
.subscribe(() => {
this.stakingLpService.toggleLoading('tvlAndTtv', false);
this.cdr.markForCheck();
});
}
Example #12
Source File: bare-flow.ts From RcloneNg with MIT License | 6 votes |
protected deployBefore() {
this.bareData$ = this.prerequest$.pipe(
switchMap(
(pre): Observable<CombErr<Tout>> => {
if (pre[1].length === 0) return this.request(pre).pipe(take(1));
return of((pre as any) as CombErr<Tout>); // force to convert. There are some errors at privious flow.
// Just make sure that checking Error[] at first in subscription
}
),
shareReplay()
);
this.deployed = true;
}
Example #13
Source File: send-payment.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
ngAfterViewInit(): void {
this.route.queryParams
.pipe(take(1))
.pipe(delay(10))
.subscribe(params => {
if (params.assetId) {
this.form.controls.assetCode.setValue(params.assetId);
} else {
this.form.controls.assetCode.setValue('native');
}
});
}
Example #14
Source File: add-record.component.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
private loadEmptyRecord() {
this.dataStore.userData$
.pipe(
take(1),
switchMap(userData => this.recordService.create(userData.recordPreset)),
tap(record => this.record.next(record)),
takeUntil(this.destroy$),
).subscribe();
}
Example #15
Source File: asset-details.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
ngOnInit(): void {
this.issuedAsset$
.pipe(filter((asset) => !!asset))
.pipe(take(1))
.pipe(withLatestFrom(this.horizonApiQuery.getSelectedHorizonApi$))
.subscribe(([asset, horizonApi]: [IWalletAssetModel, IHorizonApi]) => {
this.walletsAssetsService.requestAssetData$.next({
...asset,
horizonApi,
});
});
}
Example #16
Source File: cache-flow.ts From RcloneNg with MIT License | 6 votes |
protected request(pre: CombErr<Tin>): Observable<CombErr<Tout>> {
return iif(
() => this.cacheEnabled() && this.isCached(),
of(this.getCache()),
this.requestCache(pre).pipe(
take(1),
tap(x => {
if (this.cacheEnabled()) this.setCache(x);
})
)
);
}
Example #17
Source File: wallet-account.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
async saveName(): Promise<void> {
if (this.accountNameControl.invalid) {
return;
}
const account = await this.account$.pipe(take(1)).toPromise();
try {
await this.walletsAccountsService.setAccountName({
name: this.accountNameControl.value.trim(),
publicKey: account.publicKey,
});
} catch (e: any) {
this.nzMessageService.error(e.message || this.translateService.instant('ERROR_MESSAGES.UNEXPECTED_ERROR'));
return;
}
this.editingName = false;
}
Example #18
Source File: pages-edit.component.ts From FireAdmin with MIT License | 6 votes |
ngOnInit() {
this.blockTypes = Object.keys(PageBlockType).map((key: string) => {
return { label: key, value: PageBlockType[key] };
});
this.isSubmitButtonsDisabled = true;
this.subscription.add(
this.route.params.subscribe((params: { id: string }) => {
// console.log(params);
this.pages.get(params.id).pipe(take(1)).toPromise().then((page: Page) => {
// console.log(page);
if (page) {
this.id = page.id;
this.title = page.title;
this.slug = page.slug;
this.language = page.lang;
this.blocks = Object.keys(page.blocks).map((key: string) => {
const block: PageBlock = page.blocks[key];
return {
key: key,
name: block.name,
type: block.type,
content: block.content
};
});
this.routeParamsChange.next();
this.isSubmitButtonsDisabled = false;
} else {
this.navigation.redirectTo('pages', 'list');
}
});
})
);
}
Example #19
Source File: registered-wallet-details.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
async onEditName(): Promise<void> {
const wallet = await this.wallet$.pipe(take(1)).toPromise();
if (!wallet) {
// TODO: add error here later
return;
}
const drawerRef = this.nzDrawerService.create<EditWalletNameComponent>({
nzContent: EditWalletNameComponent,
nzTitle: this.translateService.instant('SETTINGS.REGISTERED_WALLET_DETAILS.EDIT_NAME'),
nzWrapClassName: 'drawer-full-w-320',
nzContentParams: {
wallet
}
});
drawerRef.open();
}
Example #20
Source File: pages-translate.component.ts From FireAdmin with MIT License | 6 votes |
ngOnInit() {
this.blockTypes = Object.keys(PageBlockType).map((key: string) => {
return { label: key, value: PageBlockType[key] };
});
this.isSubmitButtonsDisabled = true;
this.subscription.add(
this.route.params.subscribe((params: { id: string }) => {
// console.log(params);
this.pages.get(params.id).pipe(take(1)).toPromise().then((page: Page) => {
// console.log(page);
if (page) {
this.languages = this.pages.getTranslationLanguages(page);
if (this.languages.length) {
this.origin = page;
this.language = this.languages[0].key;
this.title = page.title;
this.slug = page.slug;
this.blocks = Object.keys(page.blocks).map((key: string) => {
const block: PageBlock = page.blocks[key];
return {
key: key,
name: block.name,
type: block.type,
content: block.content
};
});
this.routeParamsChange.next();
this.isSubmitButtonsDisabled = false;
} else {
this.navigation.redirectTo('pages', 'list');
}
} else {
this.navigation.redirectTo('pages', 'list');
}
});
})
);
}
Example #21
Source File: scanned-item-manager.service.ts From pantry_party with Apache License 2.0 | 6 votes |
perfomSave(item: ReadyScannedItem) {
this.updateScannedItemWithoutVersionBump(
item.barcode,
{saveInProgress: true}
);
const lastUndoKey = this.pvtUndoKey[item.barcode];
const undo$ = lastUndoKey ? this.undoCallback(lastUndoKey) : EMPTY;
concat(
undo$.pipe(
map(() => delete this.pvtUndoKey[item.barcode])
),
this.saveCallback(item).pipe(
map(r => {
this.pvtUndoKey[item.barcode] = r;
this.updateScannedItemWithoutVersionBump(
item.barcode,
{ lastSavedVersion: item.currentVersion }
);
})
)
).pipe(
takeUntil(this.ngUnsubscribe),
finalize(() => this.updateScannedItemWithoutVersionBump(
item.barcode,
{saveInProgress: false}
)),
take(1)
).subscribe();
}
Example #22
Source File: background-image.component.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
ngAfterViewInit(): void {
forkJoin([
this.settingsQuery.backgroundImg$.pipe(take(1)),
this.settingsQuery.backgroundCover$.pipe(take(1))
])
.pipe(take(1))
.subscribe(([backgroundImg, backgroundCover]) => {
const account = new BigNumber((backgroundCover || '').slice(14, -1) || 0).multipliedBy(100).toNumber();
this.colorCoverControl.patchValue(account, { emitEvent: false });
this.backgroundImageControl.patchValue(backgroundImg, { emitEvent: false });
this.cdr.detectChanges();
});
}
Example #23
Source File: ɵmanifest-registry.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 6 votes |
private installCapabilitiesLookupRequestHandler(): void {
Beans.get(MessageClient).observe$<ManifestObjectFilter>(ManifestRegistryTopics.LookupCapabilities)
.pipe(takeUntil(this._destroy$))
.subscribe((request: TopicMessage<ManifestObjectFilter>) => runSafe(() => {
const replyTo = request.headers.get(MessageHeaders.ReplyTo);
const appSymbolicName = request.headers.get(MessageHeaders.AppSymbolicName);
const lookupFilter = request.body || {};
// The queried capabilities may change on both, capability or intention change, because the computation
// of visible and qualified capabilities depends on registered capabilities and manifested intentions.
const registryChange$ = merge(this._capabilityStore.change$, this._intentionStore.change$);
const finder$ = defer(() => of(this._capabilityStore.find(lookupFilter)));
return finder$
.pipe(
expand(() => registryChange$.pipe(take(1), mergeMap(() => finder$))),
filterArray(capability => this.isApplicationQualifiedForCapability(appSymbolicName, capability)),
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
takeUntilUnsubscribe(replyTo),
)
.subscribe(capabilities => { // eslint-disable-line rxjs/no-nested-subscribe
Beans.get(MessageClient).publish<Capability[]>(replyTo, capabilities, {headers: new Map().set(MessageHeaders.Status, ResponseStatusCodes.OK)});
});
}));
}
Example #24
Source File: web3-modal.service.ts From web3modal-angular with MIT License | 6 votes |
async open() {
this.providers.next(this.web3WalletConnector.providers)
return await new Promise((resolve, reject) => {
this.web3WalletConnector.providerController.on(CONNECT_EVENT, provider => {
resolve(provider);
});
this.web3WalletConnector.providerController.on(ERROR_EVENT, error => {
reject(error);
});
this.shouldOpen.next(true)
this.shouldOpen.pipe(take(1)).subscribe({
next: (open) => {
if (!open) {
reject('Dismissed modal');
}
}
})
}).finally(() => {
this.close()
})
}
Example #25
Source File: app.component.ts From gnosis.1inch.exchange with MIT License | 6 votes |
private getTokenCost(
token: ITokenDescriptor,
tokenAmount: number
): Observable<TokenCost> {
return this.tokenPriceService.getUsdTokenPrice(
token.address,
token.decimals
).pipe(
map((priceBN: BigNumber) => {
const usdPrice = bnToNumberSafe(priceBN) / 1e8;
return this.calcTokenCost(tokenAmount, usdPrice);
}),
take(1)
);
}
Example #26
Source File: app.component.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
constructor(
private readonly dataStore: DataStoreService,
private readonly platform: Platform,
private readonly router: Router,
private readonly language: LanguageService
) {
this.setStatusBarStyle().subscribe();
this.dataInitialized()
.pipe(
switchMap(() => this.language.init()),
switchMap(() => this.dataStore.userData$.pipe(take(1))),
switchMap(userData => {
return (userData.recordPreset) ? of(userData) : this.dataStore.updateUserData({ recordPreset: RecordPreset.COMMON_COLD });
})
)
.subscribe(userData => {
if (userData.newUser) {
this.router.navigate(['/onboarding']);
}
SplashScreen.hide();
});
this.dataStore.initializeStore().subscribe();
}
Example #27
Source File: base-oidc-provider.ts From ng-conf-2020-workshop with MIT License | 6 votes |
public getUserInfo(): Promise<ExternalLogin> {
let resolve: (val: ExternalLogin) => void;
let reject: () => void;
const user = new Promise<ExternalLogin>((res, rej) => {
resolve = res;
reject = rej;
});
this.oidcConfigService.onConfigurationLoaded.pipe(take(1)).subscribe(() => {
this.config();
this.oidcSecurityService.onAuthorizationResult.subscribe(() => {
this.oidcSecurityService.getUserData().subscribe(userData => {
resolve(this.formatUserData(userData));
});
});
this.oidcSecurityService.authorizedImplicitFlowCallback();
});
this.oidcConfigService.load_using_stsServer(this.externalStsConfig.stsServer);
return user;
}
Example #28
Source File: emote.component.ts From App with MIT License | 6 votes |
/**
* Get the channels that this emote is added to
*/
readChannels(): Observable<UserStructure[]> {
if (!this.emote) return of([]);
return this.emote.getChannels().pipe(
take(1),
tap(users => this.channels.next(users))
);
}
Example #29
Source File: geolocation.service.ts From mylog14 with GNU General Public License v3.0 | 6 votes |
getPosition(useCache = true): Observable<GeolocationPosition> {
const cache = (this.isCachedPositionValid() && useCache);
const position$ = (cache) ? of(this.cachedPosition) : from(Geolocation.getCurrentPosition(this.defaultGeolocationOptions));
return position$
.pipe(
take(1),
map(position => {
console.log('Geolocation retrieved', position);
this.cachedPositionTime = Date.now();
return this.cachedPosition = position;
}),
);
}