diff --git a/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs b/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs index b42f07e19d233151c4682376292f2020377eed19..9be98564cfb6e7d7c882febbdaf0833ff10b3e92 100644 --- a/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs +++ b/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs @@ -11,6 +11,6 @@ namespace Frontend.Marketplaces.Interfaces public Task<double> PotatoKgPriceInEth { get; } public Task<bool> Approve(Web3 approverClient, BigInteger amount); public Task<PotatoTransaction?> Buy(string ownerAddress); - // public double Sell(PotatoTransaction transaction); + public Task<bool> Sell(PotatoTransaction transaction, string receiverAddress); } } diff --git a/Frontend/Marketplaces/PotatoMarketplaceMock.cs b/Frontend/Marketplaces/PotatoMarketplaceMock.cs index 1445f45e002cbb786f4af82db0f2580b24124108..2d2024afb9a66865b58a89aaf50fb44a9b6179bb 100644 --- a/Frontend/Marketplaces/PotatoMarketplaceMock.cs +++ b/Frontend/Marketplaces/PotatoMarketplaceMock.cs @@ -69,6 +69,21 @@ public class PotatoMarketplaceMock( }; } + public async Task<bool> Sell(PotatoTransaction transaction, string receiverAddress) + { + var amount = (double)await PotatoKgWeiPrice() * transaction.Weight; + + var transferHandler = web3.Eth.GetContractTransactionHandler<TransferFunction>(); + var transferFunction = new TransferFunction + { + To = receiverAddress, + Value = new BigInteger(amount), + }; + + var receipt = await transferHandler.SendRequestAndWaitForReceiptAsync(wethAddress, transferFunction); + return receipt.Status.Value == 1; + } + private static async Task<double> EthChfPrice() { string url = "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=CHF";