Created
January 11, 2020 03:10
-
-
Save alexytiger/2f84c46a3bca857b399de09eef28c1e2 to your computer and use it in GitHub Desktop.
e-book
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