Skip to content

Commit

Permalink
Add GasLimit field for Tezos, fix default fees
Browse files Browse the repository at this point in the history
  • Loading branch information
matsakiv committed Apr 19, 2023
1 parent 48d654e commit 4b80fb3
Show file tree
Hide file tree
Showing 11 changed files with 922 additions and 169 deletions.
3 changes: 3 additions & 0 deletions Atomex.Client.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
<Compile Update="Views\ConversionViews\ConversionCurrencyView.axaml.cs">
<DependentUpon>ConversionCurrencyView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\SendViews\TezosSendView.axaml.cs">
<DependentUpon>TezosSendView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\StartView.axaml.cs">
<DependentUpon>StartView.axaml</DependentUpon>
</Compile>
Expand Down
26 changes: 26 additions & 0 deletions Converters/StringToLongConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Globalization;

using Avalonia.Data.Converters;

namespace Atomex.Client.Desktop.Converters
{
public class StringToLongConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not long longValue)
return string.Empty;

return longValue.ToString(CultureInfo.CurrentCulture);
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not string stringValue || string.IsNullOrEmpty(stringValue))
return 0;

return long.Parse(stringValue, CultureInfo.CurrentCulture);
}
}
}
185 changes: 97 additions & 88 deletions Properties/Resources.Designer.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,7 @@ NOTE: Do not sign out or close the application until the swap is completed, othe
<data name="CvRedeemFromAddressNoteToolTip" xml:space="preserve">
<value>The redeem transaction will be sent from the address {0} if it has enough funds. Otherwise the transaction will be sent by an extrenal service for a fee</value>
</data>
<data name="SvCantEstimateFees" xml:space="preserve">
<value>Can't estimate fees</value>
</data>
</root>
22 changes: 9 additions & 13 deletions ViewModels/DappsViewModels/DappsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,8 @@ await _beaconWalletClient.SendResponseAsync(
PublicKey = PubKey.FromBytes(publicKey).ToString(),
StorageLimit = 0
},
Fee = Fee.FromNetwork(defaultValue: 0),
From = connectedWalletAddress.Address,
GasLimit = GasLimit.FromNetwork(defaultValue: operationGasLimit),
StorageLimit = StorageLimit.FromValue(0)
UseFeeFromNetwork = true,
UseGasLimitFromNetwork = true
});
}

Expand Down Expand Up @@ -468,11 +466,10 @@ await _beaconWalletClient.SendResponseAsync(

operations.Add(new TezosOperationParameters
{
Content = txContent,
Fee = Fee.FromNetwork(defaultValue: 0),
GasLimit = GasLimit.FromNetwork(defaultValue: operationGasLimit),
StorageLimit = StorageLimit.FromNetwork(defaultValue: StorageLimitPerOperation, useSafeValue: false),
From = connectedWalletAddress.Address
Content = txContent,
UseFeeFromNetwork = true,
UseGasLimitFromNetwork = true,
UseStorageLimitFromNetwork = true
});
}
else if (o is TezosDelegationOperation delegationOperation)
Expand All @@ -488,10 +485,9 @@ await _beaconWalletClient.SendResponseAsync(
StorageLimit = StorageLimitPerOperation,
Delegate = delegationOperation.Delegate
},
Fee = Fee.FromNetwork(defaultValue: 0),
GasLimit = GasLimit.FromNetwork(defaultValue: operationGasLimit),
StorageLimit = StorageLimit.FromNetwork(defaultValue: StorageLimitPerOperation, useSafeValue: false),
From = connectedWalletAddress.Address
UseFeeFromNetwork = true,
UseGasLimitFromNetwork = true,
UseStorageLimitFromNetwork = true
});
}
};
Expand Down
15 changes: 3 additions & 12 deletions ViewModels/DappsViewModels/OperationRequestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,9 @@ private async void AutoFillOperations()
{
var operation = new TezosOperationParameters
{
From = op.From,
Fee = UseDefaultFee ? Fee.FromNetwork() : op.Fee,
GasLimit = UseDefaultFee ? GasLimit.FromNetwork(DefaultOperationGasLimit) : op.GasLimit,
StorageLimit = UseDefaultFee
? StorageLimit.FromNetwork(DappsViewModel.StorageLimitPerOperation, useSafeValue: false)
: op.StorageLimit,
UseFeeFromNetwork = UseDefaultFee,
UseGasLimitFromNetwork = UseDefaultFee,
UseStorageLimitFromNetwork = UseDefaultFee,
Content = op.Content switch
{
TransactionContent txContent => new TransactionContent
Expand Down Expand Up @@ -499,10 +496,7 @@ private async void AutoFillOperations()
if (!UseDefaultFee)
{
foreach (var op in operations)
{
op.Fee = Fee.FromValue(avgFee);
op.Content.Fee = avgFee;
}
}

var (isSuccess, error) = await TezosOperationFiller
Expand All @@ -516,10 +510,7 @@ private async void AutoFillOperations()
if (!UseDefaultFee)
{
foreach (var op in operations)
{
op.Fee = Fee.FromValue(avgFee);
op.Content.Fee = avgFee;
}
}

if (error != null)
Expand Down
8 changes: 4 additions & 4 deletions ViewModels/DelegateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,10 @@ private async Task<Result<TezosOperationRequest>> RunAutoFillOperationAsync(
StorageLimit = (int)_tezosConfig.StorageLimit,
Source = delegateAddress
},
From = delegateAddress,
Fee = Blockchain.Tezos.Fee.FromNetwork(),
GasLimit = GasLimit.FromNetwork(defaultValue: (int)_tezosConfig.GasLimit),
StorageLimit = StorageLimit.FromNetwork(defaultValue: (int)_tezosConfig.StorageLimit, useSafeValue: true)
UseFeeFromNetwork = true,
UseGasLimitFromNetwork = true,
UseStorageLimitFromNetwork = true,
UseSafeStorageLimit = true
}
},
publicKey: publicKey,
Expand Down
Loading

0 comments on commit 4b80fb3

Please sign in to comment.