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

sec(wallet): adding a warning message for Solana System Program assign instruction (uplift to 1.71.x) #26206

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,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 = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ios/brave-ios/Sources/BraveWallet/WalletConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,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"
}
18 changes: 18 additions & 0 deletions ios/brave-ios/Sources/BraveWallet/WalletStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading