diff --git a/BraveWallet/Crypto/BuySendSwap/SendTokenView.swift b/BraveWallet/Crypto/BuySendSwap/SendTokenView.swift index 3b760c22496..76456b06b0e 100644 --- a/BraveWallet/Crypto/BuySendSwap/SendTokenView.swift +++ b/BraveWallet/Crypto/BuySendSwap/SendTokenView.swift @@ -37,7 +37,7 @@ struct SendTokenView: View { return sendAmount == 0 || sendAmount > balance || sendTokenStore.sendAmount.isEmpty - || sendTokenStore.addressError != nil + || (sendTokenStore.addressError != nil && sendTokenStore.addressError != .missingChecksum) } var body: some View { diff --git a/BraveWallet/Crypto/Stores/SendTokenStore.swift b/BraveWallet/Crypto/Stores/SendTokenStore.swift index 93ab89bdf10..7d0cd0528d7 100644 --- a/BraveWallet/Crypto/Stores/SendTokenStore.swift +++ b/BraveWallet/Crypto/Stores/SendTokenStore.swift @@ -42,6 +42,8 @@ public class SendTokenStore: ObservableObject { case sameAsFromAddress case contractAddress case notEthAddress + case missingChecksum + case invalidChecksum var errorDescription: String? { switch self { @@ -51,6 +53,10 @@ public class SendTokenStore: ObservableObject { return Strings.Wallet.sendWarningAddressIsContract case .notEthAddress: return Strings.Wallet.sendWarningAddressNotValid + case .missingChecksum: + return Strings.Wallet.sendWarningAddressMissingChecksumInfo + case .invalidChecksum: + return Strings.Wallet.sendWarningAddressInvalidChecksum } } } @@ -178,14 +184,29 @@ public class SendTokenStore: ObservableObject { } let normalizedSendAddress = sendAddress.lowercased() if !sendAddress.isETHAddress { + // 1. check if send address is a valid eth address addressError = .notEthAddress } else if currentAccountAddress?.lowercased() == normalizedSendAddress { + // 2. check if send address is the same as the from address addressError = .sameAsFromAddress } else if (userAssets.first(where: { $0.contractAddress.lowercased() == normalizedSendAddress }) != nil) || (allTokens.first(where: { $0.contractAddress.lowercased() == normalizedSendAddress }) != nil) { + // 3. check if send address is a contract address addressError = .contractAddress } else { - addressError = nil + keyringService.checksumEthAddress(sendAddress) { [self] checksumAddress in + if sendAddress == checksumAddress { + // 4. check if send address is the same as the checksum address from the `KeyringService` + addressError = nil + } else if sendAddress.removingHexPrefix.lowercased() == sendAddress.removingHexPrefix || sendAddress.removingHexPrefix.uppercased() == sendAddress.removingHexPrefix { + // 5. check if send address has each of the alphabetic character as uppercase, or has each of + // the alphabeic character as lowercase + addressError = .missingChecksum + } else { + // 6. send address has mixed with uppercase and lowercase and does not match with the checksum address + addressError = .invalidChecksum + } + } } } diff --git a/BraveWallet/WalletStrings.swift b/BraveWallet/WalletStrings.swift index 08b668deed9..c6efa980224 100644 --- a/BraveWallet/WalletStrings.swift +++ b/BraveWallet/WalletStrings.swift @@ -1597,6 +1597,20 @@ extension Strings { value: "Not a valid ETH address", comment: "A warning that appears below the send crypto address text field, when the input `To` address is not a valid ETH address." ) + public static let sendWarningAddressMissingChecksumInfo = NSLocalizedString( + "wallet.sendWarningAddressMissingChecksumInfo", + tableName: "BraveWallet", + bundle: .braveWallet, + value: "This address cannot be verified (missing checksum). Proceed?", + comment: "A warning that appears below the send crypto address text field, when the input `To` address is missing checksum information." + ) + public static let sendWarningAddressInvalidChecksum = NSLocalizedString( + "wallet.sendWarningAddressInvalidChecksum", + tableName: "BraveWallet", + bundle: .braveWallet, + value: "Address did not pass verification (invalid checksum). Please try again, replacing lowercase letters with uppercase.", + comment: "A warning that appears below the send crypto address text field, when the input `To` address has invalid checksum." + ) public static let betaLabel = NSLocalizedString( "wallet.betaLabel", tableName: "BraveWallet",