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

Conversation

jeden
Copy link
Collaborator

@jeden jeden commented Nov 13, 2024

No description provided.

- Extracted a reusable `StorageUsageView` from `WalletSettingView`
- Added the `StorageUsageView` to `TokenDetailView`
- Added `getAccountInfo` cadence
- Handled the `insufficientStorage` case in the remote config to display an insufficient storage alert
…n failure

- Refactored `AlertView` to allow for injected custom content
- Created `PersistentToastView`
- Added storage usage progress in TokenDetailView
@jeden jeden marked this pull request as draft November 13, 2024 23:13
@jeden
Copy link
Collaborator Author

jeden commented Nov 13, 2024

Storage view

image

  1. Move token
    image

  2. Move NFT
    image
    image

  3. Send Token
    image

  4. Send NFT
    image

  5. Sign Transaction on browser
    image

  6. Sign Transaction on WalletConnect
    image

  7. Insufficient Storage Alert
    image

  8. Storage Capacity Exceeded Alert (error condition simulated from code)
    image

- Implemented generic and reusable `InsufficientStorageToastView` as a drop-in specifically for showing the insufficient warning
- UI fixes
# Conflicts:
#	FRW.xcodeproj/project.pbxproj
#	FRW/Modules/NFT/NFTTransferView.swift
#	FRW/Modules/Wallet/MoveAsset/MoveComponentView.swift
#	FRW/Modules/Wallet/MoveAsset/MoveNFTsView.swift
#	FRW/Modules/Wallet/MoveAsset/MoveSingleNFTView.swift
#	FRW/Modules/Wallet/MoveAsset/ViewModel/MoveNFTsViewModel.swift
#	FRW/Modules/Wallet/MoveAsset/ViewModel/MoveSingleNFTViewModel.swift
#	FRW/Modules/Wallet/MoveAsset/ViewModel/MoveTokenViewModel.swift
#	FRW/Modules/Wallet/Send/WalletSendAmountViewModel.swift
#	FRW/Modules/Wallet/SideMenu/SideMenuView.swift
#	FRW/Modules/Wallet/TokenDetail/TokenDetailViewModel.swift
#	FRW/Services/Manager/Config/RemoteConfig.swift
#	FRW/Services/Manager/WalletManager.swift
#	FRW/Services/Network/FlowNetwork.swift
Copy link

gitguardian bot commented Nov 14, 2024

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9474120 Triggered Generic Password 0a9fd17 FRW/Modules/MultiRestore/ViewModel/RestoreMultiConnectViewModel.swift View secret
9474120 Triggered Generic Password 0a9fd17 FRW/Modules/MultiRestore/ViewModel/RestoreMultiConnectViewModel.swift View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@jeden jeden force-pushed the fts/484-account-storage-alert branch from ab313c9 to c71e23c Compare November 14, 2024 03:59
@jeden jeden marked this pull request as ready for review November 14, 2024 04:00
@jeden jeden requested review from zhouxl and lmcmz November 14, 2024 04:00
try? await WalletManager.shared.fetchBalance()
}

group.addTask {
Copy link
Member

Choose a reason for hiding this comment

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

No need query checkStorageInfo any more, it's included in AccountInfo now

@@ -202,6 +203,9 @@ extension RemoteConfigManager {
}
case .isIOS:
return true
case .insufficientStorage:
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this func boolValue async, otherwise, the user might missed their alert on home page.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That could potentially delay the UI, and I wouldn't feel comfortable making an enum method async, as it would imply adding logic that should reside elsewhere.
For that reason I opted for using the event bus, so that notifications are reloaded when the account info has been retrieved.

self.accountInfo = accountInfo
}
} catch let error {
log.error("[EVM] fetch account info failed.\(error.localizedDescription)")
Copy link
Member

Choose a reason for hiding this comment

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

It's not EVM action, let's put other tag. Such as [WALLET]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A clear case of copy and paste from another line :-)


static func checkAccountInfo() async throws -> Flow.AccountInfo {
let address = Flow.Address(hex: WalletManager.shared.getPrimaryWalletAddress() ?? "")
let cadence = CadenceManager.shared.current.basic?.getAccountInfo?.toFunc() ?? ""
Copy link
Member

Choose a reason for hiding this comment

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

let's throw the error if the address or cadence is empty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. It doesn't seem to exist an error for invalid cadence, so I've added invalidCadence to LLError. But let me know if there's another error that fits better.

static func checkAccountInfo() async throws -> Flow.AccountInfo {
let address = Flow.Address(hex: WalletManager.shared.getPrimaryWalletAddress() ?? "")
let cadence = CadenceManager.shared.current.basic?.getAccountInfo?.toFunc() ?? ""
let response = try await flow.accessAPI.executeScriptAtLatestBlock(cadence: cadence, arguments: [.address(address)]).decode(Flow.AccountInfo.self)
Copy link
Member

Choose a reason for hiding this comment

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

return try await flow.accessAPI.executeScriptAtLatestBlock(cadence: cadence, arguments: [.address(address)]).decode()


func isStorageInsufficient(for amount: Decimal) -> Bool {
guard let accountInfo else { return false }
return accountInfo.availableBalance - amount < Self.minDefaultBlance
Copy link
Member

Choose a reason for hiding this comment

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

Storage check doesn't need amount, it should be storageCapacity - storageUsed < 10000

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I think I forgot to update it after we discussed it... btw I'm reimplementing this part using your pseudo-code

@@ -562,6 +586,28 @@ struct SideContainerView: View {
}
.offset(x: vm.isOpen ? screenWidth - SideOffset : 0)
}
.customAlertView(
Copy link
Member

Choose a reason for hiding this comment

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

There should be a better place for placing alert.
And it alert shouldn't be configured on SideContainerView.

switch result.errorCode {
case .storageCapacityExceeded:
let data = InsufficientStorageTransactionFailureData(minimumBalance: WalletManager.shared.minimumStorageBalance)
NotificationCenter.default.post(name: .insufficientStorageTransactionFailure, object: data)
Copy link
Member

Choose a reason for hiding this comment

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

Cause we post the transactionStatusDidChanged event already, we should reuse the same notification


func isBalanceInsufficient(for amount: Decimal) -> Bool {
guard let accountInfo else { return false }
return accountInfo.availableBalance - amount - Self.minDefaultBlance < Self.minDefaultBlance
Copy link
Member

Choose a reason for hiding this comment

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

I assume the - Self.minDefaultBlance is the moveFee ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct — I've renamed all constants using the names you provided in your pseudo-code.

}

let wm = WalletManager.shared
if (isTransferBetweenEvmAndFlow) {
Copy link
Member

Choose a reason for hiding this comment

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

This logic need revisit, I will post the pseudo code in the chat.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have a double on this logical expression: should it apply both sides (Evm -> Flow and Flow -> Evm), or it is one side only?

.padding(.horizontal, 12)
.background(Color(.orange5))
}
.background(Color.LL.Neutrals.background.opacity(0.95))
Copy link
Member

Choose a reason for hiding this comment

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

I think the opacity is not the same as design

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The opacity is defined in the orange5 color. I added the background at line 30 to control transparency, as the content behind the view would make it unreadable. Compare the two:

image

image

The alternative is to make sure the content behind doesn't scroll, but that would require the sheet to be taller. Suggestions?

@EnvironmentObject private var viewModel: ViewModel

var body: some View {
PersistentToastView(message: self.viewModel.variant?.message ?? "", imageRes: .Storage.insufficient)
Copy link
Member

Choose a reason for hiding this comment

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

Can we add slideUp animation when it appears ?

@jeden jeden linked an issue Nov 15, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Account storage alert
2 participants