Skip to content

Commit

Permalink
Uplift of #26088 (squashed) to release
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-builds committed Oct 18, 2024
1 parent 236113e commit 784960f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components/brave_wallet/browser/brave_wallet_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ inline constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveWalletConfirmTransactions", IDS_BRAVE_WALLET_CONFIRM_TRANSACTIONS},
{"braveWalletConfirmTransactionAccountCreationFee",
IDS_BRAVE_WALLET_CONFIRM_TRANSACTION_ACCOUNT_CREATION_FEE},
{"braveWalletSystemProgramAssignWarningTitle",
IDS_BRAVE_WALLET_SYSTEM_PROGRAM_ASSIGN_WARNING_TITLE},
{"braveWalletSystemProgramAssignWarningDescription",
IDS_BRAVE_WALLET_SYSTEM_PROGRAM_ASSIGN_WARNING_DESCRIPTION},
{"braveWalletTransactionGasLimit", IDS_BRAVE_WALLET_TRANSACTION_GAS_LIMIT},
{"braveWalletTransactionGasPremium",
IDS_BRAVE_WALLET_TRANSACTION_GAS_PREMIUM},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
AddressText,
WarningBox,
WarningTitle,
WarningText,
LearnMoreButton,
WarningBoxTitleRow,
URLText
Expand Down Expand Up @@ -409,6 +410,20 @@ export const ConfirmTransactionPanel = ({
)}
</>
)}

{transactionDetails.hasSystemProgramAssignInstruction && (
<WarningBox warningType={'danger'}>
<WarningBoxTitleRow>
<WarningIcon />
<WarningTitle warningType={'danger'}>
{getLocale('braveWalletSystemProgramAssignWarningTitle')}
</WarningTitle>
<WarningText>
{getLocale('braveWalletSystemProgramAssignWarningDescription')}
</WarningText>
</WarningBoxTitleRow>
</WarningBox>
)}
</>
)}

Expand Down
5 changes: 5 additions & 0 deletions components/brave_wallet_ui/stories/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@ provideStrings({
braveWalletNetworkFees: 'Network fees',
braveWalletTransactionMayIncludeAccountCreationFee:
'This transaction may include an account creation fee',
braveWalletSystemProgramAssignWarningTitle:
'Account ownership change requested',
braveWalletSystemProgramAssignWarningDescription:
'This transaction will reassign ownership of the account to a new ' +
'program. This action is irreversible and may result in loss of funds.',

// Wallet Main Panel
braveWalletPanelTitle: 'Brave Wallet',
Expand Down
21 changes: 19 additions & 2 deletions components/brave_wallet_ui/utils/tx-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface ParsedTransaction

// Solana Specific
isAssociatedTokenAccountCreation: boolean
hasSystemProgramAssignInstruction: boolean
}

export type ParsedTransactionWithoutFiatValues = Omit<
Expand Down Expand Up @@ -1278,7 +1279,7 @@ export const getTransactionIntent = ({
return (
toProperCase(getLocale('braveWalletApprovalTransactionIntent')) +
' ' +
token?.symbol ?? ''
(token?.symbol ?? '')
)
}

Expand Down Expand Up @@ -1741,7 +1742,8 @@ export const parseTransactionWithoutPrices = ({
valueExact: normalizedTransferredValueExact,
weiTransferredValue,
formattedSendCurrencyTotal,
isAssociatedTokenAccountCreation: isAssociatedTokenAccountCreationTx(tx)
isAssociatedTokenAccountCreation: isAssociatedTokenAccountCreationTx(tx),
hasSystemProgramAssignInstruction: hasSystemProgramAssignInstruction(tx)
}
}

Expand Down Expand Up @@ -1872,6 +1874,21 @@ export const isAssociatedTokenAccountCreationTx = (
BraveWallet.TransactionType
.SolanaSPLTokenTransferWithAssociatedTokenAccountCreation

export function hasSystemProgramAssignInstruction(
tx: Pick<TransactionInfo, 'txType' | 'txDataUnion'>
): tx is SolanaTransactionInfo {
if (!isSolanaTransaction(tx)) {
return false
}

const instructions = getTypedSolanaTxInstructions(tx.txDataUnion.solanaTxData)
return instructions.some(
(instruction) =>
instruction.type === "Assign" ||
instruction.type === "AssignWithSeed"
)
}

export function getTransactionTypeName(txType: BraveWallet.TransactionType) {
switch (txType) {
case BraveWallet.TransactionType.ERC1155SafeTransferFrom:
Expand Down
2 changes: 2 additions & 0 deletions components/resources/wallet_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@
<message name="IDS_BRAVE_WALLET_CONFIRM_TRANSACTION_FIRST" desc="Confirm transaction panel first transaction button">first</message>
<message name="IDS_BRAVE_WALLET_CONFIRM_TRANSACTIONS" desc="Confirm transaction panel transactions label">transactions</message>
<message name="IDS_BRAVE_WALLET_CONFIRM_TRANSACTION_ACCOUNT_CREATION_FEE" desc="Confirm transaction panel account creation fee warning">The associated token account does not exist yet. A small amount of SOL will be spent to create and fund it.</message>
<message name="IDS_BRAVE_WALLET_SYSTEM_PROGRAM_ASSIGN_WARNING_TITLE" desc="Confirm transaction panel warning title for System Program assign instruction">Account ownership change requested</message>
<message name="IDS_BRAVE_WALLET_SYSTEM_PROGRAM_ASSIGN_WARNING_DESCRIPTION" desc="Confirm transaction panel warning description for System Program assign instruction">This transaction will reassign ownership of the account to a new program. This action is irreversible and may result in loss of funds.</message>
<message name="IDS_BRAVE_WALLET_TRANSACTION_GAS_LIMIT" desc="Transaction gas limit">Gas Limit</message>
<message name="IDS_BRAVE_WALLET_TRANSACTION_GAS_PREMIUM" desc="Transaction gas premium">Gas Premium</message>
<message name="IDS_BRAVE_WALLET_TRANSACTION_GAS_FEE_CAP" desc="Transaction gas fee cap">Gas Fee Cap</message>
Expand Down

0 comments on commit 784960f

Please sign in to comment.