Skip to content

Commit

Permalink
484 account storage alert fixes (#633)
Browse files Browse the repository at this point in the history
PRFB: 484 Account storage alert
#484

- Rewritten the logic to determine when to display the insufficient storage warning (before & after)
- Updated the average transaction fee, dependent from the free gas flag
  • Loading branch information
jeden authored Dec 5, 2024
1 parent 86bdf99 commit b747bc1
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 89 deletions.
12 changes: 9 additions & 3 deletions FRW.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1387,12 +1387,14 @@
573429B72CDC4B2E00BDE016 /* AccountModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 573429B52CDC4B2E00BDE016 /* AccountModels.swift */; };
576F9E5A2CDB28590038E9CA /* StorageUsageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576F9E592CDB28590038E9CA /* StorageUsageView.swift */; };
576F9E5B2CDB28590038E9CA /* StorageUsageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576F9E592CDB28590038E9CA /* StorageUsageView.swift */; };
57999B7C2CF4267400C342D7 /* Helper+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57999B7B2CF4267400C342D7 /* Helper+Extensions.swift */; };
57999B7D2CF4267400C342D7 /* Helper+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57999B7B2CF4267400C342D7 /* Helper+Extensions.swift */; };
57ACE9AE2CE17901004DCA3E /* PersistentToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57ACE9AD2CE17901004DCA3E /* PersistentToastView.swift */; };
57ACE9AF2CE17901004DCA3E /* PersistentToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57ACE9AD2CE17901004DCA3E /* PersistentToastView.swift */; };
57E9AB772CE40B2600F04CE5 /* InsufficientStorageToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E9AB762CE40B2600F04CE5 /* InsufficientStorageToastView.swift */; };
57E9AB782CE40B2600F04CE5 /* InsufficientStorageToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E9AB762CE40B2600F04CE5 /* InsufficientStorageToastView.swift */; };
57999B7C2CF4267400C342D7 /* Helper+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57999B7B2CF4267400C342D7 /* Helper+Extensions.swift */; };
57999B7D2CF4267400C342D7 /* Helper+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57999B7B2CF4267400C342D7 /* Helper+Extensions.swift */; };
57EB45712CFFC36400393FF2 /* TokenType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57EB45702CFFC36400393FF2 /* TokenType.swift */; };
57EB45722CFFC36400393FF2 /* TokenType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57EB45702CFFC36400393FF2 /* TokenType.swift */; };
6A0137662897E7A0009BEF20 /* HalfSheetModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A0137652897E7A0009BEF20 /* HalfSheetModal.swift */; };
6A0137672897E7A0009BEF20 /* HalfSheetModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A0137652897E7A0009BEF20 /* HalfSheetModal.swift */; };
6A0454CD28768E9E00A9131C /* SwiftUIPager in Frameworks */ = {isa = PBXBuildFile; productRef = 6A0454CC28768E9E00A9131C /* SwiftUIPager */; };
Expand Down Expand Up @@ -2591,9 +2593,10 @@
571A806C2CF54C12009112EE /* InsufficientStorageAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsufficientStorageAlert.swift; sourceTree = "<group>"; };
573429B52CDC4B2E00BDE016 /* AccountModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountModels.swift; sourceTree = "<group>"; };
576F9E592CDB28590038E9CA /* StorageUsageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageUsageView.swift; sourceTree = "<group>"; };
57999B7B2CF4267400C342D7 /* Helper+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Helper+Extensions.swift"; sourceTree = "<group>"; };
57ACE9AD2CE17901004DCA3E /* PersistentToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistentToastView.swift; sourceTree = "<group>"; };
57E9AB762CE40B2600F04CE5 /* InsufficientStorageToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsufficientStorageToastView.swift; sourceTree = "<group>"; };
57999B7B2CF4267400C342D7 /* Helper+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Helper+Extensions.swift"; sourceTree = "<group>"; };
57EB45702CFFC36400393FF2 /* TokenType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenType.swift; sourceTree = "<group>"; };
6A0137652897E7A0009BEF20 /* HalfSheetModal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HalfSheetModal.swift; sourceTree = "<group>"; };
6A06CB0528AA25F400C81BE1 /* NFTUIKitListDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTUIKitListDataSource.swift; sourceTree = "<group>"; };
6A06CB0928AA485200C81BE1 /* NFTUIKitListStyleHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTUIKitListStyleHandler.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5850,6 +5853,7 @@
6A2C560A290BE46800306A6C /* Currency.swift */,
573429B52CDC4B2E00BDE016 /* AccountModels.swift */,
15DFD34B2CE197F9004B0DB8 /* AppExternalLinks.swift */,
57EB45702CFFC36400393FF2 /* TokenType.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -7120,6 +7124,7 @@
6A5006D328A7892D007FE3F5 /* NFTUIKitCollectionRegularItemCell.swift in Sources */,
15B1F6332786B1BB00847BB5 /* CheckboxStyle.swift in Sources */,
6A164F762845F1CB0026B31E /* IndexedScrollView.swift in Sources */,
57EB45712CFFC36400393FF2 /* TokenType.swift in Sources */,
154B8909276A1EEB00780E93 /* Color.swift in Sources */,
6A41005D28E2F4DC002946CE /* SwapConfirmView.swift in Sources */,
6A99343128C89FFF00E4EF59 /* BrowserSignMessageViewModel.swift in Sources */,
Expand Down Expand Up @@ -7923,6 +7928,7 @@
15C58B5A2868A4EE00BD4FC6 /* IndexedScrollView.swift in Sources */,
15C58B5B2868A4EE00BD4FC6 /* Color.swift in Sources */,
6A99343028C89FFF00E4EF59 /* BrowserSignMessageViewModel.swift in Sources */,
57EB45722CFFC36400393FF2 /* TokenType.swift in Sources */,
6A41005C28E2F4DC002946CE /* SwapConfirmView.swift in Sources */,
15C58B5C2868A4EE00BD4FC6 /* VPageIndicatorFinite.swift in Sources */,
1575A73028B26F3400ADC513 /* CardBackground.swift in Sources */,
Expand Down
14 changes: 14 additions & 0 deletions FRW/Foundation/Model/TokenType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TokenType.swift
// FRW
//
// Created by Antonio Bello on 12/3/24.
//

import Foundation

enum TokenType {
case ft(TokenModel)
case nft(NFTModel?)
case none
}
4 changes: 2 additions & 2 deletions FRW/Modules/Browser/View/BrowserAuthzViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension BrowserAuthzViewModel {

// MARK: - BrowserAuthzViewModel

class BrowserAuthzViewModel: ObservableObject {
final class BrowserAuthzViewModel: ObservableObject {
@Published var title: String
@Published var urlString: String
@Published var logo: String?
Expand Down Expand Up @@ -114,6 +114,6 @@ extension BrowserAuthzViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheckForTransfer()
self._insufficientStorageFailure = insufficientStorageCheckForTransfer(token: .none)
}
}
2 changes: 1 addition & 1 deletion FRW/Modules/NFT/NFTTransferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ extension NFTTransferViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheckForTransfer()
self._insufficientStorageFailure = insufficientStorageCheckForTransfer(token: .nft(self.nft))
}
}

Expand Down
27 changes: 11 additions & 16 deletions FRW/Modules/Wallet/MoveAsset/ViewModel/MoveNFTsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI

// MARK: - MoveNFTsViewModel

class MoveNFTsViewModel: ObservableObject {
final class MoveNFTsViewModel: ObservableObject {
// MARK: Lifecycle

init() {
Expand All @@ -23,27 +23,22 @@ class MoveNFTsViewModel: ObservableObject {

// MARK: Internal

@Published
var selectedCollection: CollectionMask?
@Published private(set) var selectedCollection: CollectionMask?
// NFTModel
@Published
var nfts: [MoveNFTsViewModel.NFT] = [
MoveNFTsViewModel.NFT.mock(),
@Published private(set) var nfts: [MoveNFTsViewModel.NFT] = [
MoveNFTsViewModel.NFT.mock(),
MoveNFTsViewModel.NFT.mock(),
MoveNFTsViewModel.NFT.mock()
]
@Published
var isMock = true
@Published
var showHint = false
@Published
var showFee = false
@Published private(set) var isMock = true
@Published private(set) var showHint = false
@Published private(set) var showFee = false

@Published
var buttonState: VPrimaryButtonState = .disabled
private(set) var buttonState: VPrimaryButtonState = .disabled

@Published
var fromContact = Contact(
private(set) var fromContact = Contact(
address: "",
avatar: "",
contactName: "",
Expand All @@ -53,7 +48,7 @@ class MoveNFTsViewModel: ObservableObject {
username: nil
)
@Published
var toContact = Contact(
private(set) var toContact = Contact(
address: "",
avatar: "",
contactName: "",
Expand Down Expand Up @@ -476,7 +471,7 @@ extension MoveNFTsViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheckForMove(from: self.fromContact.walletType, to: self.toContact.walletType)
self._insufficientStorageFailure = insufficientStorageCheckForMove(token: .nft(nil), from: self.fromContact.walletType, to: self.toContact.walletType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI

// MARK: - MoveSingleNFTViewModel

class MoveSingleNFTViewModel: ObservableObject {
final class MoveSingleNFTViewModel: ObservableObject {
// MARK: Lifecycle

init(nft: NFTModel, fromChildAccount: ChildAccount? = nil, callback: @escaping () -> Void) {
Expand All @@ -27,12 +27,12 @@ class MoveSingleNFTViewModel: ObservableObject {

// MARK: Internal

var nft: NFTModel
var fromChildAccount: ChildAccount?
var callback: () -> Void
private(set) var nft: NFTModel
private(set) var fromChildAccount: ChildAccount?
private(set) var callback: () -> Void

@Published
var fromContact = Contact(
private(set) var fromContact = Contact(
address: "",
avatar: "",
contactName: "",
Expand All @@ -42,7 +42,7 @@ class MoveSingleNFTViewModel: ObservableObject {
username: nil
)
@Published
var toContact = Contact(
private(set) var toContact = Contact(
address: "",
avatar: "",
contactName: "",
Expand All @@ -52,9 +52,9 @@ class MoveSingleNFTViewModel: ObservableObject {
username: nil
)
@Published
var buttonState: VPrimaryButtonState = .enabled
private(set) var buttonState: VPrimaryButtonState = .enabled

var accountCount: Int = 0
private(set) var accountCount: Int = 0

func closeAction() {
Router.dismiss()
Expand Down Expand Up @@ -289,7 +289,7 @@ extension MoveSingleNFTViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheckForMove(from: self.fromContact.walletType, to: self.toContact.walletType)
self._insufficientStorageFailure = insufficientStorageCheckForMove(token: .nft(self.nft), from: self.fromContact.walletType, to: self.toContact.walletType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI

// MARK: - MoveTokenViewModel

class MoveTokenViewModel: ObservableObject {
final class MoveTokenViewModel: ObservableObject {
// MARK: Lifecycle

init(token: TokenModel, isPresent: Binding<Bool>) {
Expand Down Expand Up @@ -68,9 +68,8 @@ class MoveTokenViewModel: ObservableObject {
username: nil
)

var token: TokenModel
@Binding
var isPresent: Bool
private(set) var token: TokenModel
@Binding var isPresent: Bool

var isReadyForSend: Bool {
errorType == .none && showBalance.isNumber && !showBalance.isEmpty
Expand Down Expand Up @@ -307,7 +306,7 @@ extension MoveTokenViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheckForMove(amount: self.inputTokenNum, from: self.fromContact.walletType, to: self.toContact.walletType)
self._insufficientStorageFailure = insufficientStorageCheckForMove(amount: self.inputTokenNum, token: .ft(self.token), from: self.fromContact.walletType, to: self.toContact.walletType)
}
}

Expand Down
52 changes: 20 additions & 32 deletions FRW/Modules/Wallet/Send/WalletSendAmountViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension WalletSendAmountView {

// MARK: - WalletSendAmountViewModel

class WalletSendAmountViewModel: ObservableObject {
final class WalletSendAmountViewModel: ObservableObject {
// MARK: Lifecycle

init(target: Contact, token: TokenModel) {
Expand Down Expand Up @@ -79,36 +79,24 @@ class WalletSendAmountViewModel: ObservableObject {

// MARK: Internal

@Published
var targetContact: Contact
@Published
var token: TokenModel
@Published
var amountBalance: Double = 0
@Published
var coinRate: Double = 0

@Published
var inputText: String = ""
@Published
var inputTokenNum: Double = 0
@Published
var inputDollarNum: Double = 0
var actualBalance: String = ""

@Published
var exchangeType: WalletSendAmountView.ExchangeType = .token
@Published
var errorType: WalletSendAmountView.ErrorType = .none

@Published
var showConfirmView: Bool = false

@Published
var isValidToken: Bool = true

@Published
var isEmptyTransation = true
@Published private(set) var targetContact: Contact
@Published private(set) var token: TokenModel
@Published private(set) var amountBalance: Double = 0
@Published private(set) var coinRate: Double = 0

@Published var inputText: String = ""
@Published private(set) var inputTokenNum: Double = 0
@Published private(set) var inputDollarNum: Double = 0
private(set) var actualBalance: String = ""

@Published private(set) var exchangeType: WalletSendAmountView.ExchangeType = .token
@Published private(set) var errorType: WalletSendAmountView.ErrorType = .none

@Published var showConfirmView: Bool = false

@Published private(set) var isValidToken: Bool = true

@Published var isEmptyTransation = true

var amountBalanceAsDollar: Double {
coinRate * amountBalance
Expand Down Expand Up @@ -251,7 +239,7 @@ extension WalletSendAmountViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheckForTransfer(amount: self.inputTokenNum.decimalValue)
self._insufficientStorageFailure = insufficientStorageCheckForTransfer(amount: self.inputTokenNum.decimalValue, token: .ft(self.token))
}
}

Expand Down
7 changes: 2 additions & 5 deletions FRW/Services/Manager/WalletManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension WalletManager {

static let minDefaultBlance: Decimal = 0.001
static let fixedMoveFee: Decimal = 0.001
static let averageTransactionFee: Decimal = 0.001
static var averageTransactionFee: Decimal { RemoteConfigManager.shared.freeGasEnabled ? 0 : 0.0005 }
static let mininumStorageThreshold = 10000

private static let defaultBundleID = "com.flowfoundation.wallet"
Expand Down Expand Up @@ -829,13 +829,10 @@ extension WalletManager {

var isStorageInsufficient: Bool {
guard let accountInfo else { return false }
guard accountInfo.storageCapacity >= accountInfo.storageUsed else { return true }
return accountInfo.storageCapacity - accountInfo.storageUsed < Self.mininumStorageThreshold
}

var isBalanceInsufficient: Bool {
return isBalanceInsufficient(for: 0)
}

func isBalanceInsufficient(for amount: Decimal) -> Bool {
guard let accountInfo else { return false }
return accountInfo.availableBalance - amount < Self.averageTransactionFee
Expand Down
Loading

0 comments on commit b747bc1

Please sign in to comment.