Esempio n. 1
0
        public async Task HandleLyraSwap(WebWalletBeginTokenSwapAction action, IDispatcher dispatcher)
        {
            bool   IsSuccess         = false;
            string swapResultMessage = "";

            try
            {
                var pool = await client.GetPool(action.fromToken, action.toToken);

                if (pool.Successful() && pool.PoolAccountId != null)
                {
                    var result = await action.wallet.SwapToken(pool.Token0, pool.Token1,
                                                               action.fromToken, action.fromAmount, action.minReceived);

                    if (result.ResultCode == APIResultCodes.Success)
                    {
                        IsSuccess         = true;
                        swapResultMessage = "Success!";
                    }
                    else
                    {
                        swapResultMessage = $"Failed to swap token: {result.ResultCode}";
                    }
                }
                else
                {
                    swapResultMessage = $"Unable to get the liquidate pool: {pool.ResultCode}";
                }
            }
            catch (Exception ex)
            {
                swapResultMessage = "In Token Swap: " + ex.Message;
            }

            dispatcher.Dispatch(new WebWalletTokenSwapResultAction {
                Success = IsSuccess, errMessage = swapResultMessage
            });
        }
Esempio n. 2
0
 public static WebWalletState ReductLyraSwapHandler(WebWalletState state, WebWalletBeginTokenSwapAction action) => state.With(new { IsLoading = true });