Last active
September 10, 2019 03:39
-
-
Save alexytiger/593e67e4c4b7da7d8b249a311df7b181 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private widgetObservable = (id: number): Observable<PurchaseWidgetModel> => | |
| from(this.contractToken.getContractKeyAtIndex(id)).pipe( | |
| switchMap(key => from(this.contractToken.getContractByKey(key)).pipe( | |
| map(address => { | |
| const widget: PurchaseWidgetModel = { | |
| productKey: utils.parseBytes32String(key as ethers.utils.Arrayish), | |
| contractAddress: address as string | |
| }; | |
| return widget; | |
| }) | |
| )) | |
| ) | |
| public getPurchaseContractList(): Observable<PurchaseWidgetModel[]> { | |
| return from(this.contractToken.getContractCount()).pipe( | |
| map((bigNumber: ethers.utils.BigNumber) => bigNumber.toNumber()), | |
| tap((contractCount: number) => console.log('contractCount: ', contractCount)), | |
| switchMap((contractCount: number) => { | |
| if (contractCount === 0) { | |
| return of([]); | |
| } | |
| else { | |
| // we get array [0,1,....contractCount-1] | |
| const countArr: number[] = Array.from(Array(contractCount)).map((e, i) => i); | |
| const source = of(countArr); | |
| return source.pipe( | |
| mergeMap(ids => forkJoin(ids.map(this.widgetObservable))) | |
| ) | |
| } | |
| }) | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment