Skip to content

Commit

Permalink
sec(wallet): adding a warning message for Solana System Program assig…
Browse files Browse the repository at this point in the history
…n instruction (uplift to 1.70.x) (#26207)

sec(wallet): adding a warning message for Solana System Program assign instruction (#26198)
  • Loading branch information
nuo-xu authored Oct 25, 2024
1 parent 12c872a commit 3c3c4d9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
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 @@ -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 = ""
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 @@ -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"
}
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

0 comments on commit 3c3c4d9

Please sign in to comment.