From 3c3c4d989e53bd975ec23ac018d1de32e72254d5 Mon Sep 17 00:00:00 2001 From: Nuo Xu Date: Thu, 24 Oct 2024 23:32:36 -0700 Subject: [PATCH] sec(wallet): adding a warning message for Solana System Program assign instruction (uplift to 1.70.x) (#26207) sec(wallet): adding a warning message for Solana System Program assign instruction (#26198) --- .../PendingTransactionView.swift | 22 +++++++++++++++++++ .../Transactions/TransactionParser.swift | 17 ++++++++++++++ .../SolanaInstruction+Extensions.swift | 10 +++++++++ .../Sources/BraveWallet/WalletConstants.swift | 6 +++++ .../Sources/BraveWallet/WalletStrings.swift | 18 +++++++++++++++ 5 files changed, 73 insertions(+) diff --git a/ios/brave-ios/Sources/BraveWallet/Crypto/Transaction Confirmations/PendingTransactionView.swift b/ios/brave-ios/Sources/BraveWallet/Crypto/Transaction Confirmations/PendingTransactionView.swift index 9c95c9095439..9db62005dfab 100644 --- a/ios/brave-ios/Sources/BraveWallet/Crypto/Transaction Confirmations/PendingTransactionView.swift +++ b/ios/brave-ios/Sources/BraveWallet/Crypto/Transaction Confirmations/PendingTransactionView.swift @@ -283,6 +283,28 @@ struct PendingTransactionView: View { ) } + if confirmationStore.activeParsedTransaction.hasSystemProgramAssignInstruction { + VStack(alignment: .leading, spacing: 8) { + Label { + Text(Strings.Wallet.confirmationViewSolAccountOwnershipChangeWarningTitle) + .foregroundColor(Color(braveSystemName: .systemfeedbackWarningText)) + } icon: { + Image(braveSystemName: "leo.warning.triangle-outline") + .foregroundColor(Color(braveSystemName: .systemfeedbackWarningIcon)) + } + .font(.subheadline.weight(.bold)) + Text(Strings.Wallet.confirmationViewSolAccountOwnershipChangeWarning) + .foregroundColor(Color(braveSystemName: .systemfeedbackWarningText)) + .font(.subheadline.weight(.medium)) + } + .padding(.horizontal, 24) + .padding(.vertical, 20) + .background( + Color(braveSystemName: .systemfeedbackWarningBackground) + .clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous)) + ) + } + // View Mode VStack(spacing: 12) { Picker("", selection: $viewMode) { diff --git a/ios/brave-ios/Sources/BraveWallet/Crypto/Transactions/TransactionParser.swift b/ios/brave-ios/Sources/BraveWallet/Crypto/Transactions/TransactionParser.swift index e77a734cbdfb..02b9bd0cc4a0 100644 --- a/ios/brave-ios/Sources/BraveWallet/Crypto/Transactions/TransactionParser.swift +++ b/ios/brave-ios/Sources/BraveWallet/Crypto/Transactions/TransactionParser.swift @@ -1027,6 +1027,23 @@ struct ParsedTransaction: Equatable { } } + var hasSystemProgramAssignInstruction: Bool { + if case .solDappTransaction(let details) = details { + for parsedInstruction in details.instructions { + let isAssign = + parsedInstruction.instruction.instructionTypeName + == WalletConstants.solanaTxInstructionTypeNameAssign + let isAssignWithSeed = + parsedInstruction.instruction.instructionTypeName + == WalletConstants.solanaTxInstructionTypeNameAssignWithSeed + if isAssign || isAssignWithSeed { + return true + } + } + } + return false + } + init() { self.transaction = .init() self.namedFromAddress = "" diff --git a/ios/brave-ios/Sources/BraveWallet/Extensions/SolanaInstruction+Extensions.swift b/ios/brave-ios/Sources/BraveWallet/Extensions/SolanaInstruction+Extensions.swift index 5b778e55c3a4..fb7c381c90ef 100644 --- a/ios/brave-ios/Sources/BraveWallet/Extensions/SolanaInstruction+Extensions.swift +++ b/ios/brave-ios/Sources/BraveWallet/Extensions/SolanaInstruction+Extensions.swift @@ -23,6 +23,16 @@ extension BraveWallet.SolanaInstruction { programId == BraveWallet.SolanaSysvarRentProgramId } + var instructionTypeName: String { + guard let decodedData = self.decodedData else { + return Strings.Wallet.solanaUnknownInstructionName + } + let instructionType = BraveWallet.SolanaSystemInstruction( + rawValue: Int(decodedData.instructionType) + ) + return instructionType?.name ?? Strings.Wallet.solanaUnknownInstructionName + } + var instructionName: String { guard let decodedData = self.decodedData else { return Strings.Wallet.solanaUnknownInstructionName diff --git a/ios/brave-ios/Sources/BraveWallet/WalletConstants.swift b/ios/brave-ios/Sources/BraveWallet/WalletConstants.swift index 1a13228b41d6..4b79da7ac469 100644 --- a/ios/brave-ios/Sources/BraveWallet/WalletConstants.swift +++ b/ios/brave-ios/Sources/BraveWallet/WalletConstants.swift @@ -202,4 +202,10 @@ public struct WalletConstants { static let signTransactionRiskLink: URL = URL( string: "https://support.brave.com/hc/en-us/articles/4409513799693" )! + + /// Solana Transacation Instruction Type Name + static let solanaTxInstructionTypeNameAssign: String = "Assign" + + /// Solana Transacation Instruction Type Name + static let solanaTxInstructionTypeNameAssignWithSeed: String = "AssignWithSeed" } diff --git a/ios/brave-ios/Sources/BraveWallet/WalletStrings.swift b/ios/brave-ios/Sources/BraveWallet/WalletStrings.swift index 54c64924c15d..2b7d6f9005ed 100644 --- a/ios/brave-ios/Sources/BraveWallet/WalletStrings.swift +++ b/ios/brave-ios/Sources/BraveWallet/WalletStrings.swift @@ -1498,6 +1498,24 @@ extension Strings { comment: "The warning shown on transaction confirmation for an Solana SPL token transaction that has not yet created an associated token account." ) + public static let confirmationViewSolAccountOwnershipChangeWarningTitle = NSLocalizedString( + "wallet.confirmationViewSolAccountOwnershipChangeWarningTitle", + tableName: "BraveWallet", + bundle: .module, + value: + "Account ownership change requested", + comment: + "The warning title shown on transaction confirmation for an Solana Dapp request that will reassign ownership of the account to a new program." + ) + public static let confirmationViewSolAccountOwnershipChangeWarning = NSLocalizedString( + "wallet.confirmationViewSolAccountOwnershipChangeWarning", + tableName: "BraveWallet", + bundle: .module, + value: + "This transaction will reassign ownership of the account to a new program. This action is irreversible and may result in loss of funds.", + comment: + "The warning shown on transaction confirmation for an Solana Dapp request that will reassign ownership of the account to a new program." + ) public static let confirmationViewCurrentAllowance = NSLocalizedString( "wallet.confirmationViewCurrentAllowance", tableName: "BraveWallet",