-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: develop
Are you sure you want to change the base?
Conversation
- 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
- 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
|
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
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- 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
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 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.
ab313c9
to
c71e23c
Compare
try? await WalletManager.shared.fetchBalance() | ||
} | ||
|
||
group.addTask { |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)") |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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() ?? "" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
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) |
There was a problem hiding this comment.
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 ?
No description provided.