Last active
September 16, 2019 15:56
-
-
Save alexytiger/6935ec029696962885bf29773bb63c3d 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
| public loadPurchaseContract(contractAddress: string): Observable<PurchaseContractModel> { | |
| const contract: Contract = new ethers.Contract(contractAddress, this.abi, this.provider.getSigner()); | |
| return zip( | |
| from(contract.key()), | |
| from(contract.seller()), | |
| from(contract.buyer()), | |
| from(contract.price()), | |
| from(contract.balanceOf()), | |
| from(contract.title()), | |
| from(contract.ipfsHash()), | |
| from(contract.state()), | |
| ) | |
| .pipe( | |
| map(([key, sellerAddress, buyerAddress, weiPrice, weiBalance, title, ipfsHash, state]) => { | |
| // console.log(`key: ${key}, weiPrice: ${weiPrice}, state: ${state}`); | |
| // key: 0x706967794d6f64656c3030303500000000000000000000000000000000000000, weiPrice: 500000000000000, state: 0 | |
| const product: PurchaseContractModel = { | |
| productKey: utils.parseBytes32String(key as ethers.utils.Arrayish), | |
| contractAddress, | |
| sellerAddress: sellerAddress as string, | |
| buyerAddress: (buyerAddress === ethers.constants.AddressZero) ? null : buyerAddress as string, | |
| price: utils.formatEther(weiPrice as ethers.utils.BigNumberish), // $ETH | |
| balanceOf: utils.formatEther(weiBalance as ethers.utils.BigNumberish), // $ETH | |
| title: title as string, | |
| ipfsHash: ipfsHash as string, | |
| state: state as ContractState | |
| }; | |
| return product; | |
| }), | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment