private IEnumerator GetMarketCoroutine(Action <Auction[]> successCallback = null, Action errorCallback = null) { CanvasManager.Instance.ShowOperationPopup("Refreshing blockchain asset market...", false); int itemsPerPage = 20; CarAuctions.Clear(); SellCarAuctions.Clear(); BuyCarAuctions.Clear(); yield return(PhantasmaDemo.Instance.PhantasmaApi.GetAuctions(PhantasmaDemo.PHANTASMA_CHAIN, PhantasmaDemo.TOKEN_SYMBOL, 1, (uint)itemsPerPage, (auctions, currentPage, totalPages) => { StartCoroutine(ProcessAuctions(auctions, currentPage, itemsPerPage, totalPages, successCallback, errorCallback)); }, (errorType, errorMessage) => { CanvasManager.Instance.HideOperationPopup(); CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, errorType + " - " + errorMessage); if (errorCallback != null) { errorCallback(); } })); }
/// <summary> /// Check if the auction purchase was successful /// </summary> private IEnumerator CheckAssetPurchase(Car car, string result) { CanvasManager.Instance.ShowOperationPopup("Checking auction purchase...", true); yield return(PhantasmaDemo.Instance.CheckOperation(PhantasmaDemo.EBLOCKCHAIN_OPERATION.BUY_ASSET, result, (tx) => { foreach (var evt in tx.events) { EventKind eKind; if (Enum.TryParse(evt.kind, out eKind)) { if (eKind == EventKind.OrderFilled) { var carMutableData = car.MutableData; carMutableData.location = CarLocation.None; car.OwnerAddress = PhantasmaDemo.Instance.Key.Address; car.MutableData = carMutableData; CarAuctions.Remove(car.TokenID); BuyCarAuctions.Remove(car.TokenID); PhantasmaDemo.Instance.MyCars.Add(car.TokenID, car); CanvasManager.Instance.marketMenu.UpdateMarket(MarketMenu.EMARKETPLACE_TYPE.BUY); CanvasManager.Instance.HideBuyPopup(); CanvasManager.Instance.HideOperationPopup(); CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.SUCCESS, "Asset purchased from the market with success."); GetMarket((auctions) => { CanvasManager.Instance.marketMenu.SetContent(auctions); if (CarAuctions.Keys.Count > 0) { CanvasManager.Instance.marketMenu.SelectMarketBuyTab(); } }); return; } } } CanvasManager.Instance.HideOperationPopup(); CanvasManager.Instance.HideBuyPopup(); CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Something failed while purchasing the asset from the market. Please try again."); }, ((errorType, errorMessage) => { CanvasManager.Instance.HideOperationPopup(); CanvasManager.Instance.HideBuyPopup(); CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, errorType + " - " + errorMessage); }))); }
private IEnumerator ProcessAuctions(Auction[] auctions, int currentPage, int itemsPerPage, int totalPages, Action <Auction[]> successCallback = null, Action errorCallback = null) { if (currentPage < totalPages) { yield return(PhantasmaDemo.Instance.PhantasmaApi.GetAuctions(PhantasmaDemo.PHANTASMA_CHAIN, PhantasmaDemo.TOKEN_SYMBOL, (uint)currentPage + 1, (uint)itemsPerPage, (a, cPage, tPages) => { foreach (var auction in auctions) { var carAuction = new CarAuction { tokenID = auction.tokenId, auction = auction }; CarAuctions.Add(auction.tokenId, carAuction); if (auction.creatorAddress.Equals(PhantasmaDemo.Instance.Key.Address.ToString())) { // Auction has my address -> Selling Auction SellCarAuctions.Add(auction.tokenId, carAuction); } else { // No my auction -> Buying Auction BuyCarAuctions.Add(auction.tokenId, carAuction); } } StartCoroutine(ProcessAuctions(a, cPage, itemsPerPage, tPages, successCallback, errorCallback)); }, (errorType, errorMessage) => { CanvasManager.Instance.HideOperationPopup(); CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, errorType + " - " + errorMessage); })); } else { CanvasManager.Instance.HideOperationPopup(); if (totalPages == 0) { CanvasManager.Instance.marketMenu.ShowRefreshButton("No auctions at this moment in the market."); } else { foreach (var auction in auctions) { var carAuction = new CarAuction { tokenID = auction.tokenId, auction = auction }; CarAuctions.Add(auction.tokenId, carAuction); if (auction.creatorAddress.Equals(PhantasmaDemo.Instance.Key.Address.ToString())) { // Auction has my address -> Selling Auction SellCarAuctions.Add(auction.tokenId, carAuction); } else { // No my auction -> Buying Auction BuyCarAuctions.Add(auction.tokenId, carAuction); } } if (successCallback != null) { successCallback(auctions); } } } }