Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fts/484 account storage alert #525

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion FRW.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,14 @@
4EFF94C52AEEDD0A00365EF7 /* IPResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFF94C32AEEDD0A00365EF7 /* IPResponse.swift */; };
4EFF94C72AEEE5DD00365EF7 /* DevicesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFF94C62AEEE5DD00365EF7 /* DevicesViewModel.swift */; };
4EFF94C82AEEE5DD00365EF7 /* DevicesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFF94C62AEEE5DD00365EF7 /* DevicesViewModel.swift */; };
573429B62CDC4B2E00BDE016 /* AccountModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 573429B52CDC4B2E00BDE016 /* AccountModels.swift */; };
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 */; };
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 */; };
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 @@ -2568,6 +2576,10 @@
4EFF94C02AEEDC1C00365EF7 /* FRWAPI+IP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FRWAPI+IP.swift"; sourceTree = "<group>"; };
4EFF94C32AEEDD0A00365EF7 /* IPResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPResponse.swift; sourceTree = "<group>"; };
4EFF94C62AEEE5DD00365EF7 /* DevicesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevicesViewModel.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>"; };
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>"; };
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 @@ -4583,6 +4595,9 @@
4E9D8F1D2BF87A0400E11CC7 /* TitleWithClosedView.swift */,
4EAFBD802C1051D00031EA20 /* CircularProgressView.swift */,
4E5F2F242C1AF398008589C4 /* PresentHostingController.swift */,
576F9E592CDB28590038E9CA /* StorageUsageView.swift */,
57ACE9AD2CE17901004DCA3E /* PersistentToastView.swift */,
57E9AB762CE40B2600F04CE5 /* InsufficientStorageToastView.swift */,
);
path = Component;
sourceTree = "<group>";
Expand Down Expand Up @@ -5809,6 +5824,7 @@
6AAD4E6828BC6E9900AEAB1F /* TransactionModels.swift */,
6AC476E728F3C993008503E6 /* WebBookmark.swift */,
6A2C560A290BE46800306A6C /* Currency.swift */,
573429B52CDC4B2E00BDE016 /* AccountModels.swift */,
15DFD34B2CE197F9004B0DB8 /* AppExternalLinks.swift */,
);
path = Model;
Expand Down Expand Up @@ -6795,6 +6811,7 @@
15DC20BF27819C56000B187A /* VSquareButtonState.swift in Sources */,
6A8FA49A285B192800EE5BE3 /* SnapAnchorPreferenceKey.swift in Sources */,
15DC217527819C56000B187A /* VDialogButtonModel.swift in Sources */,
57E9AB782CE40B2600F04CE5 /* InsufficientStorageToastView.swift in Sources */,
158832EB28942F8500142B35 /* serviceDefinition.swift in Sources */,
156E84AE281CDF4F00415896 /* WalletModels.swift in Sources */,
4E5054222C33DB1F00D4BA56 /* AppConfig.swift in Sources */,
Expand Down Expand Up @@ -7180,6 +7197,7 @@
1588330D28943D1D00142B35 /* SPQRCameraController.swift in Sources */,
15DC21A727819C56000B187A /* VBaseTextField.swift in Sources */,
6A0137672897E7A0009BEF20 /* HalfSheetModal.swift in Sources */,
57ACE9AF2CE17901004DCA3E /* PersistentToastView.swift in Sources */,
1575A73528B286DA00ADC513 /* LottieButton.swift in Sources */,
15DC210727819C56000B187A /* VSliderState.swift in Sources */,
6AFE1D062A384E3000824D5C /* AccountSwitchView.swift in Sources */,
Expand Down Expand Up @@ -7239,6 +7257,7 @@
15DC212D27819C56000B187A /* VWheelPicker.swift in Sources */,
15DC20EB27819C56000B187A /* VAccordionLayoutType.swift in Sources */,
15DC218527819C56000B187A /* VToggleModel.swift in Sources */,
576F9E5A2CDB28590038E9CA /* StorageUsageView.swift in Sources */,
6A164F6C2845F1CB0026B31E /* Indexable.swift in Sources */,
6AEF839C28647B830081E285 /* FRWAPI+Crypto.swift in Sources */,
4EB2C6B72B4947DF00EB899C /* MultiBackupiCloudTarget.swift in Sources */,
Expand Down Expand Up @@ -7434,6 +7453,7 @@
4E09A1EB2CC793FE0099606E /* EventTrack.swift in Sources */,
6A29114D28CB37E8003295BD /* TransferListHandler.swift in Sources */,
4EC97653286A07060066811D /* NFTCollectionEnableView.swift in Sources */,
573429B62CDC4B2E00BDE016 /* AccountModels.swift in Sources */,
6AE4605F286ED142009C2B96 /* TokenDetailViewModel.swift in Sources */,
15DC209327819C56000B187A /* VToast.swift in Sources */,
15DC21CD27819C56000B187A /* SliderHelpers.swift in Sources */,
Expand Down Expand Up @@ -7592,6 +7612,7 @@
15C58AD22868A4EE00BD4FC6 /* VSquareButtonState.swift in Sources */,
15C58AD32868A4EE00BD4FC6 /* SnapAnchorPreferenceKey.swift in Sources */,
15C58AD42868A4EE00BD4FC6 /* VDialogButtonModel.swift in Sources */,
57E9AB772CE40B2600F04CE5 /* InsufficientStorageToastView.swift in Sources */,
158832EA28942F8500142B35 /* serviceDefinition.swift in Sources */,
15C58AD52868A4EE00BD4FC6 /* WalletModels.swift in Sources */,
4E5054212C33DB1F00D4BA56 /* AppConfig.swift in Sources */,
Expand Down Expand Up @@ -7977,6 +7998,7 @@
6A0137662897E7A0009BEF20 /* HalfSheetModal.swift in Sources */,
1575A73428B286DA00ADC513 /* LottieButton.swift in Sources */,
15C58B9C2868A4EE00BD4FC6 /* VSliderState.swift in Sources */,
57ACE9AE2CE17901004DCA3E /* PersistentToastView.swift in Sources */,
15C58B9D2868A4EE00BD4FC6 /* VMenuButtonType.swift in Sources */,
6AFE1D052A384E3000824D5C /* AccountSwitchView.swift in Sources */,
158832E128942D5800142B35 /* RequestInfo.swift in Sources */,
Expand Down Expand Up @@ -8036,6 +8058,7 @@
15C58BB32868A4EE00BD4FC6 /* VToggleModel.swift in Sources */,
15C58BB42868A4EE00BD4FC6 /* Indexable.swift in Sources */,
15C58BB52868A4EE00BD4FC6 /* FRWAPI+Crypto.swift in Sources */,
576F9E5B2CDB28590038E9CA /* StorageUsageView.swift in Sources */,
15C58BB62868A4EE00BD4FC6 /* VDialogButton.swift in Sources */,
4EB2C6B62B4947DF00EB899C /* MultiBackupiCloudTarget.swift in Sources */,
15C58BB72868A4EE00BD4FC6 /* StateOpacities_P.swift in Sources */,
Expand Down Expand Up @@ -8231,6 +8254,7 @@
4E09A1EA2CC793FE0099606E /* EventTrack.swift in Sources */,
6A29114C28CB37E8003295BD /* TransferListHandler.swift in Sources */,
4EC97652286A07060066811D /* NFTCollectionEnableView.swift in Sources */,
573429B72CDC4B2E00BDE016 /* AccountModels.swift in Sources */,
6AE4605E286ED142009C2B96 /* TokenDetailViewModel.swift in Sources */,
15C58C1F2868A4EE00BD4FC6 /* VToast.swift in Sources */,
15C58C202868A4EE00BD4FC6 /* SliderHelpers.swift in Sources */,
Expand Down Expand Up @@ -9443,7 +9467,7 @@
repositoryURL = "https://github.com/outblock/flow-swift";
requirement = {
kind = exactVersion;
version = 0.3.8;
version = 0.3.9;
};
};
15F517F928C6574C00504FDC /* XCRemoteSwiftPackageReference "atlantis" */ = {
Expand Down
9 changes: 9 additions & 0 deletions FRW/Foundation/Define/NotificationDefine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public extension Notification.Name {

static let transactionManagerDidChanged = Notification.Name("transactionManagerDidChanged")
static let transactionStatusDidChanged = Notification.Name("transactionStatusDidChanged")
static let insufficientStorageTransactionFailure = Notification.Name("insufficientStorageTransactionFailure")

static let transactionCountDidChanged = Notification.Name("transactionCountDidChanged")

Expand All @@ -44,3 +45,11 @@ public extension Notification.Name {

static let remoteConfigDidUpdate = Notification.Name("remoteConfigDidUpdate")
}

struct InsufficientStorageTransactionFailureData {
let minimumBalance: Decimal

init(minimumBalance: Decimal = 0) {
self.minimumBalance = minimumBalance
}
}
20 changes: 20 additions & 0 deletions FRW/Foundation/Model/AccountModels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AccountModels.swift
// FRW
//
// Created by Antonio Bello on 11/7/24.
//

import Foundation
import Flow

extension Flow {
struct AccountInfo: Decodable {
public let address: Flow.Address
public let balance: Decimal
public let availableBalance: Decimal
public let storageUsed: UInt64
public let storageCapacity: UInt64
public let storageFlow: Decimal
}
}
7 changes: 6 additions & 1 deletion FRW/Modules/Browser/View/BrowserAuthzView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ struct BrowserAuthzView: View {

Spacer()

actionView
VStack(spacing: 0) {
InsufficientStorageToastView<BrowserAuthzViewModel>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put the into the actionView instead of adding it in different places ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied similar refactoring to other places (NFTTransferView and WalletSendAmountView)

.environmentObject(self.vm)

actionView
}
}
.if(let: vm.template) {
$0.animation(.spring(), value: $1)
Expand Down
16 changes: 14 additions & 2 deletions FRW/Modules/Browser/View/BrowserAuthzViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ class BrowserAuthzViewModel: ObservableObject {
@Published var logo: String?
@Published var cadence: String
@Published var cadenceFormatted: AttributedString?
@Published var arguments: [Flow.Argument]? = nil
@Published var arguments: [Flow.Argument]?
@Published var argumentsFormatted: AttributedString?
@Published var isScriptShowing: Bool = false

@Published var template: FlowTransactionTemplate?

private var callback: BrowserAuthzViewModel.Callback?

private var _insufficientStorageFailure: InsufficientStorageFailure?

init(title: String, url: String, logo: String?, cadence: String, arguments: [Flow.Argument]? = nil, callback: @escaping BrowserAuthnViewModel.Callback) {
self.title = title
urlString = url
self.logo = logo
self.cadence = cadence
self.arguments = arguments
self.callback = callback
checkForInsufficientStorage()
}

func didChooseAction(_ result: Bool) {
Expand Down Expand Up @@ -93,3 +95,13 @@ class BrowserAuthzViewModel: ObservableObject {
WalletConnectManager.shared.reloadPendingRequests()
}
}

// MARK: - InsufficientStorageToastViewModel

extension BrowserAuthzViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheck()
}
}
21 changes: 19 additions & 2 deletions FRW/Modules/NFT/NFTTransferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class NFTTransferViewModel: ObservableObject {
self.targetContact = targetContact
self.fromChildAccount = fromChildAccount
checkNFTReachable()
checkForInsufficientStorage()

NotificationCenter.default.addObserver(
self,
selector: #selector(onHolderChanged(noti:)),
Expand Down Expand Up @@ -370,13 +372,24 @@ class NFTTransferViewModel: ObservableObject {
// MARK: Private

private var isRequesting: Bool = false
private var _insufficientStorageFailure: InsufficientStorageFailure?

@objc
private func onHolderChanged(noti _: Notification) {
checkTransaction()
}
}

// MARK: - InsufficientStorageToastViewModel

extension NFTTransferViewModel: InsufficientStorageToastViewModel {
var variant: InsufficientStorageFailure? { _insufficientStorageFailure }

private func checkForInsufficientStorage() {
self._insufficientStorageFailure = insufficientStorageCheck()
}
}

// MARK: - NFTTransferView

struct NFTTransferView: View {
Expand Down Expand Up @@ -470,8 +483,12 @@ struct NFTTransferView: View {
.transition(.move(edge: .top))

Spacer()

sendButton
VStack(spacing: 0) {
InsufficientStorageToastView<NFTTransferViewModel>()
.environmentObject(self.vm)

sendButton
}
}
.padding(.horizontal, 28)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ extension ChildAccountAccessible {
var count: Int {
0
}

var isEmpty: Bool { self.count == 0 }
}

// MARK: - NFTCollection + ChildAccountAccessible
Expand Down
1 change: 0 additions & 1 deletion FRW/Modules/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ extension ProfileView {
} else {
Router.route(to: RouteMap.Backup.backupList)
}

} label: {
ProfileView.SettingItemCell(
iconName: Row.backup(vm).iconName,
Expand Down
38 changes: 9 additions & 29 deletions FRW/Modules/Profile/WalletSetting/WalletSettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ struct WalletSettingView: RouteableView {
.padding(.horizontal, 16)
.roundedBg()

storageView
.padding(.horizontal, 16)
.padding(.vertical, 16)
.roundedBg()
StorageUsageView(
title: "storage".localized,
usage: $vm.storageUsageDesc,
usagePercentValue: $vm.storageUsagePercent
)
.titleFont(.inter(size: 16, weight: .medium))
.padding(.horizontal, 16)
.padding(.vertical, 16)
.roundedBg()
}
.visibility(onlyShowInfo() ? .gone : .visible)
}
Expand Down Expand Up @@ -163,31 +168,6 @@ struct WalletSettingView: RouteableView {
}
}

var storageView: some View {
VStack {
Text("storage".localized)
.font(.inter(size: 16, weight: .medium))
.foregroundColor(Color.LL.Neutrals.text)
.frame(maxWidth: .infinity, alignment: .leading)

HStack {
Text(vm.usagePercentString)
.font(.inter(size: 12, weight: .regular))
.foregroundColor(Color.LL.Neutrals.neutrals7)

Spacer()

Text(vm.storageUsageDesc)
.font(.inter(size: 12, weight: .regular))
.foregroundColor(Color.LL.Neutrals.neutrals7)
}
.padding(.top, 5)

ProgressView(value: vm.storageUsagePercent, total: 1.0)
.tint(Color.LL.Primary.salmonPrimary)
}
}

func reload() {
user = WalletManager.shared.walletAccount.readInfo(at: address)
WalletManager.shared.changeNetwork(LocalUserDefaults.shared.flowNetwork)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class WalletSettingViewModel: ObservableObject {
@Published var storageUsagePercent: Double = 0
@Published var storageUsageDesc: String = ""

var usagePercentString: String {
return String(format: "%.2f%%", storageUsagePercent * 100)
}

init() {
fetchStorageInfo()
}
Expand Down
23 changes: 15 additions & 8 deletions FRW/Modules/Wallet/MoveAsset/MoveNFTsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ struct MoveNFTsView: RouteableView, PresentActionDelegate {

NFTListView()

VPrimaryButton(
model: ButtonStyle.green,
state: viewModel.buttonState,
action: {
viewModel.moveAction()
},
title: viewModel.moveButtonTitle
)
VStack(spacing: 0) {
InsufficientStorageToastView<MoveNFTsViewModel>()
.environmentObject(self.viewModel)
.background(Color.clear)

VPrimaryButton(
model: ButtonStyle.green,
state: viewModel.buttonState,
action: {
viewModel.moveAction()
},
title: viewModel.moveButtonTitle
)
}
.background(Color.clear)
}
.padding(.horizontal, 18)
.applyRouteable(self)
Expand Down
Loading