Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aminsato committed Nov 19, 2024
1 parent 0e2492f commit fdb9f8c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,9 @@ internal class SwapFormViewModel @Inject constructor(

is SwapException.TimeOut ->
UiText.StringResource(R.string.swap_error_time_out)

is SwapException.NetworkConnection ->
UiText.StringResource(R.string.network_connection_lost)
}
uiState.update {
it.copy(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,5 @@
<string name="swap_screen_invalid_zero_token_amount" translatable="false">Token amount cannot be Zero</string>
<string name="swap_screen_invalid_gas_fee_calculation" translatable="false">Gas fee calculation failed</string>
<string name="swap_screen_invalid_quote_calculation" translatable="false">Quote calculation failed</string>
<string name="network_connection_lost " translatable="false">Network connection lost. Please check your internet connection</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sealed class SwapException(message: String) : Exception(message) {
class InsufficentSwapAmount(message: String) : SwapException(message)
class SwapRouteNotAvailable(message: String) : SwapException(message)
class TimeOut(message: String) : SwapException(message)
class NetworkConnection(message: String) : SwapException(message)


companion object {
Expand All @@ -22,6 +23,7 @@ sealed class SwapException(message: String) : Exception(message) {
contains("No available qoutes for the resquested") -> SwapRouteNotAvailable(error)
contains("trading is halted") -> SwapRouteNotAvailable(error)
contains("timeout") -> TimeOut(error)
contains("unable to resolve host") -> NetworkConnection(error)
else -> UnkownSwapError(error)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vultisig.wallet.data.models

import com.vultisig.wallet.data.api.errors.SwapException
import com.vultisig.wallet.data.models.TokenStandard.COSMOS
import com.vultisig.wallet.data.models.TokenStandard.EVM
import com.vultisig.wallet.data.models.TokenStandard.SOL
Expand Down Expand Up @@ -143,7 +144,7 @@ fun Chain.oneInchChainId(): Int =
Chain.BscChain -> 56
// Chain.CronosChain -> 25
Chain.ZkSync -> 324
else -> error("Chain $this is not supported by 1inch API")
else -> throw SwapException.SwapRouteNotAvailable("Chain $this is not supported by 1inch API")
}

fun Chain.swapAssetName(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.vultisig.wallet.data.utils

import com.vultisig.wallet.data.api.models.KeysignResponseSerializable
import com.vultisig.wallet.data.api.models.OneInchSwapQuoteDeserialized
import com.vultisig.wallet.data.api.models.OneInchSwapQuoteJson
import com.vultisig.wallet.data.api.models.LiFiSwapQuoteError
import com.vultisig.wallet.data.api.models.LiFiSwapQuoteJson
import com.vultisig.wallet.data.api.models.LiFiSwapQuoteDeserialized
Expand Down

0 comments on commit fdb9f8c

Please sign in to comment.