Skip to content

Commit

Permalink
Fix brave/brave-ios#8297: Bump BraveCore to v1.60.x (brave/brave-ios#…
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHeaps committed Oct 20, 2023
1 parent c337770 commit 574289f
Show file tree
Hide file tree
Showing 44 changed files with 621 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ class BraveRewardsViewController: UIViewController, PopoverContentComponent {

observer.fetchedPanelPublisher = { [weak self] publisher, tabId in
guard let self = self else { return }
if tabId == self.tab.rewardsId {
self.publisher = publisher
DispatchQueue.main.async {
if tabId == self.tab.rewardsId {
self.publisher = publisher
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ extension Tab: BraveWalletKeyringServiceObserver {
func keyringCreated(_ keyringId: BraveWallet.KeyringId) {
}

func keyringRestored(_ keyringId: BraveWallet.KeyringId) {
func walletRestored() {
}

func keyringReset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ struct AccountActivityView: View {
}
}
)
.onReceive(keyringStore.$allKeyrings) { allKeyrings in
let allAccounts = allKeyrings.flatMap(\.accountInfos)
.onReceive(keyringStore.$allAccounts) { allAccounts in
if !allAccounts.contains(where: { $0.address == accountInfo.address }) {
// Account was deleted
detailsPresentation = nil
Expand Down
9 changes: 5 additions & 4 deletions Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,13 @@ struct AddAccountView: View {
}

private func defaultAccountName(for coin: BraveWallet.CoinType, chainId: String, isPrimary: Bool) -> String {
let keyringId = BraveWallet.KeyringId.keyringId(for: coin, on: chainId)
let keyringInfo = keyringStore.allKeyrings.first { $0.id == keyringId }
let accountsForCoin = keyringStore.allAccounts.filter { $0.coin == coin }
if isPrimary {
return String.localizedStringWithFormat(coin.defaultAccountName, (keyringInfo?.accountInfos.filter(\.isPrimary).count ?? 0) + 1)
let numberOfPrimaryAccountsForCoin = accountsForCoin.filter(\.isPrimary).count
return String.localizedStringWithFormat(coin.defaultAccountName, numberOfPrimaryAccountsForCoin + 1)
} else {
return String.localizedStringWithFormat(coin.defaultSecondaryAccountName, (keyringInfo?.accountInfos.filter(\.isImported).count ?? 0) + 1)
let numberOfImportedAccounts = accountsForCoin.filter(\.isImported).count
return String.localizedStringWithFormat(coin.defaultSecondaryAccountName, numberOfImportedAccounts + 1)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct AccountDetailsView_Previews: PreviewProvider {
static var previews: some View {
AccountDetailsView(
keyringStore: .previewStoreWithWalletCreated,
account: KeyringStore.previewStoreWithWalletCreated.defaultKeyring.accountInfos.first!,
account: KeyringStore.previewStoreWithWalletCreated.allAccounts.first!,
editMode: false
)
.previewColorSchemes()
Expand Down
104 changes: 102 additions & 2 deletions Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class AccountActivityStore: ObservableObject, WalletObserverStore {
self.userAssets = updatedUserAssets
self.userNFTs = updatedUserNFTs

let keyringForAccount = await keyringService.keyringInfo(account.keyringId)
typealias TokenNetworkAccounts = (token: BraveWallet.BlockchainToken, network: BraveWallet.NetworkInfo, accounts: [BraveWallet.AccountInfo])
let allTokenNetworkAccounts = allUserAssets.flatMap { networkAssets in
networkAssets.tokens.map { token in
Expand Down Expand Up @@ -253,9 +252,10 @@ class AccountActivityStore: ObservableObject, WalletObserverStore {
$0[$1.token.assetRatioId.lowercased()] = Double($1.price)
})

let allAccountsForCoin = await keyringService.allAccounts().accounts.filter { $0.coin == account.coin }
self.transactionSummaries = await fetchTransactionSummarys(
networksForAccountCoin: networksForAccountCoin,
accountInfos: keyringForAccount.accountInfos,
accountInfos: allAccountsForCoin,
userAssets: userAssets.map(\.token),
allTokens: allTokens,
assetRatios: assetRatios
Expand Down Expand Up @@ -327,3 +327,103 @@ class AccountActivityStore: ObservableObject, WalletObserverStore {
}
#endif
}

extension AccountActivityStore: BraveWalletKeyringServiceObserver {
func keyringCreated(_ keyringId: BraveWallet.KeyringId) {
}

func walletRestored() {
}

func keyringReset() {
}

func locked() {
}

func unlocked() {
}

func backedUp() {
}

func accountsChanged() {
}

func autoLockMinutesChanged() {
}

func selectedWalletAccountChanged(_ account: BraveWallet.AccountInfo) {
guard observeAccountUpdates else { return }
self.account = account
update()
}

func selectedDappAccountChanged(_ coin: BraveWallet.CoinType, account: BraveWallet.AccountInfo?) {
guard observeAccountUpdates, let account else { return }
self.account = account
update()
}

func accountsAdded(_ addedAccounts: [BraveWallet.AccountInfo]) {
}
}

extension AccountActivityStore: BraveWalletJsonRpcServiceObserver {
func chainChangedEvent(_ chainId: String, coin: BraveWallet.CoinType, origin: URLOrigin?) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
// Handle small gap between chain changing and txController having the correct chain Id
self.update()
}
}
func onAddEthereumChainRequestCompleted(_ chainId: String, error: String) {
}
func onIsEip1559Changed(_ chainId: String, isEip1559: Bool) {
}
}

extension AccountActivityStore: BraveWalletTxServiceObserver {
func onNewUnapprovedTx(_ txInfo: BraveWallet.TransactionInfo) {
update()
}
func onTransactionStatusChanged(_ txInfo: BraveWallet.TransactionInfo) {
update()
}
func onUnapprovedTxUpdated(_ txInfo: BraveWallet.TransactionInfo) {
}
func onTxServiceReset() {
}
}

extension AccountActivityStore: BraveWalletBraveWalletServiceObserver {
public func onActiveOriginChanged(_ originInfo: BraveWallet.OriginInfo) {
}

public func onDefaultWalletChanged(_ wallet: BraveWallet.DefaultWallet) {
}

public func onDefaultBaseCurrencyChanged(_ currency: String) {
currencyCode = currency
}

public func onDefaultBaseCryptocurrencyChanged(_ cryptocurrency: String) {
}

public func onNetworkListChanged() {
}

func onDefaultEthereumWalletChanged(_ wallet: BraveWallet.DefaultWallet) {
}

func onDefaultSolanaWalletChanged(_ wallet: BraveWallet.DefaultWallet) {
}

public func onDiscoverAssetsStarted() {
}

func onDiscoverAssetsCompleted(_ discoveredAssets: [BraveWallet.BlockchainToken]) {
}

func onResetWallet() {
}
}
101 changes: 92 additions & 9 deletions Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
self.isSwapSupported = await swapService.isSwapSupported(token.chainId)

// fetch accounts
let keyringId = BraveWallet.KeyringId.keyringId(for: token.coin, on: token.chainId)
let keyring = await keyringService.keyringInfo(keyringId)
var updatedAccounts = keyring.accountInfos.map {
let allAccountsForTokenCoin = await keyringService.allAccounts().accounts.filter { $0.coin == token.coin }
var updatedAccounts = allAccountsForTokenCoin.map {
AccountAssetViewModel(account: $0, decimalBalance: 0.0, balance: "", fiatBalance: "")
}

Expand All @@ -220,9 +219,13 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
}
}

self.accounts = await fetchAccountBalances(updatedAccounts, keyring: keyring, network: network)
self.accounts = await fetchAccountBalances(updatedAccounts, network: network)
let assetRatios = [token.assetRatioId.lowercased(): assetPriceValue]
self.transactionSummaries = await fetchTransactionSummarys(keyring: keyring, network: network, assetRatios: assetRatios)
self.transactionSummaries = await fetchTransactionSummarys(
accounts: allAccountsForTokenCoin,
network: network,
assetRatios: assetRatios
)
case .coinMarket(let coinMarket):
// comes from Market tab
self.price = self.currencyFormatter.string(from: NSNumber(value: coinMarket.currentPrice)) ?? ""
Expand Down Expand Up @@ -277,7 +280,6 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {

@MainActor private func fetchAccountBalances(
_ accountAssetViewModels: [AccountAssetViewModel],
keyring: BraveWallet.KeyringInfo,
network: BraveWallet.NetworkInfo
) async -> [AccountAssetViewModel] {
guard case let .blockchainToken(token) = assetDetailType
Expand Down Expand Up @@ -311,7 +313,7 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
}

@MainActor private func fetchTransactionSummarys(
keyring: BraveWallet.KeyringInfo,
accounts: [BraveWallet.AccountInfo],
network: BraveWallet.NetworkInfo,
assetRatios: [String: Double]
) async -> [TransactionSummary] {
Expand All @@ -320,7 +322,7 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
let userAssets = assetManager.getAllUserAssetsInNetworkAssets(networks: [network], includingUserDeleted: true).flatMap { $0.tokens }
let allTokens = await blockchainRegistry.allTokens(network.chainId, coin: network.coin)
let allTransactions = await withTaskGroup(of: [BraveWallet.TransactionInfo].self) { @MainActor group -> [BraveWallet.TransactionInfo] in
for account in keyring.accountInfos {
for account in accounts {
group.addTask { @MainActor in
await self.txService.allTransactionInfo(
network.coin,
Expand Down Expand Up @@ -370,7 +372,7 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
TransactionParser.transactionSummary(
from: transaction,
network: network,
accountInfos: keyring.accountInfos,
accountInfos: accounts,
userAssets: userAssets,
allTokens: allTokens,
assetRatios: assetRatios,
Expand Down Expand Up @@ -403,3 +405,84 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
}
}
}

extension AssetDetailStore: BraveWalletKeyringServiceObserver {
func keyringReset() {
}

func accountsChanged() {
update()
}

func keyringCreated(_ keyringId: BraveWallet.KeyringId) {
}

func walletRestored() {
}

func locked() {
}

func unlocked() {
}

func backedUp() {
}

func autoLockMinutesChanged() {
}

func selectedWalletAccountChanged(_ account: BraveWallet.AccountInfo) {
}

func selectedDappAccountChanged(_ coin: BraveWallet.CoinType, account: BraveWallet.AccountInfo?) {
}

func accountsAdded(_ addedAccounts: [BraveWallet.AccountInfo]) {
}
}

extension AssetDetailStore: BraveWalletTxServiceObserver {
func onNewUnapprovedTx(_ txInfo: BraveWallet.TransactionInfo) {
}
func onUnapprovedTxUpdated(_ txInfo: BraveWallet.TransactionInfo) {
}
func onTransactionStatusChanged(_ txInfo: BraveWallet.TransactionInfo) {
update()
}
func onTxServiceReset() {
}
}

extension AssetDetailStore: BraveWalletBraveWalletServiceObserver {
public func onActiveOriginChanged(_ originInfo: BraveWallet.OriginInfo) {
}

public func onDefaultWalletChanged(_ wallet: BraveWallet.DefaultWallet) {
}

public func onDefaultBaseCurrencyChanged(_ currency: String) {
currencyCode = currency
}

public func onDefaultBaseCryptocurrencyChanged(_ cryptocurrency: String) {
}

public func onNetworkListChanged() {
}

func onDefaultEthereumWalletChanged(_ wallet: BraveWallet.DefaultWallet) {
}

func onDefaultSolanaWalletChanged(_ wallet: BraveWallet.DefaultWallet) {
}

func onDiscoverAssetsStarted() {
}

func onDiscoverAssetsCompleted(_ discoveredAssets: [BraveWallet.BlockchainToken]) {
}

func onResetWallet() {
}
}
14 changes: 11 additions & 3 deletions Sources/BraveWallet/Crypto/Stores/CryptoStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum PendingRequest: Equatable {
case switchChain(BraveWallet.SwitchChainRequest)
case addSuggestedToken(BraveWallet.AddSuggestTokenRequest)
case signMessage([BraveWallet.SignMessageRequest])
case signMessageError([BraveWallet.SignMessageError])
case getEncryptionPublicKey(BraveWallet.GetEncryptionPublicKeyRequest)
case decrypt(BraveWallet.DecryptRequest)
case signTransaction([BraveWallet.SignTransactionRequest])
Expand All @@ -34,6 +35,8 @@ extension PendingRequest: Identifiable {
return "addSuggestedToken-\(tokenRequest.token.id)"
case let .signMessage(signRequests):
return "signMessage-\(signRequests.map(\.id))"
case let .signMessageError(signMessageErrorRequests):
return "signMessageError-\(signMessageErrorRequests.map(\.id))"
case let .getEncryptionPublicKey(request):
return "getEncryptionPublicKey-\(request.accountId.uniqueKey)-\(request.requestId)"
case let .decrypt(request):
Expand All @@ -51,6 +54,7 @@ enum WebpageRequestResponse: Equatable {
case addNetwork(approved: Bool, chainId: String)
case addSuggestedToken(approved: Bool, token: BraveWallet.BlockchainToken)
case signMessage(approved: Bool, id: Int32)
case signMessageError(errorId: String)
case getEncryptionPublicKey(approved: Bool, requestId: String)
case decrypt(approved: Bool, requestId: String)
case signTransaction(approved: Bool, id: Int32)
Expand Down Expand Up @@ -222,7 +226,7 @@ public class CryptoStore: ObservableObject, WalletObserverStore {
// when user creates or imports a new account with a new keyring since any new
// supported coin type / keyring will be migrated inside `CryptoStore`'s init()
},
_keyringRestored: { [weak self] _ in
_walletRestored: { [weak self] in
// This observer method will only get called when user restore a wallet
// from the lock screen
// We will need to
Expand Down Expand Up @@ -580,13 +584,13 @@ public class CryptoStore: ObservableObject, WalletObserverStore {

@MainActor
func fetchPendingTransactions() async -> [BraveWallet.TransactionInfo] {
let allKeyrings = await keyringService.keyrings(for: WalletConstants.supportedCoinTypes())
let allAccounts = await keyringService.allAccounts().accounts
var allNetworksForCoin: [BraveWallet.CoinType: [BraveWallet.NetworkInfo]] = [:]
for coin in WalletConstants.supportedCoinTypes() {
let allNetworks = await rpcService.allNetworks(coin)
allNetworksForCoin[coin] = allNetworks
}
return await txService.pendingTransactions(networksForCoin: allNetworksForCoin, for: allKeyrings)
return await txService.pendingTransactions(networksForCoin: allNetworksForCoin, for: allAccounts)
}

@MainActor
Expand All @@ -597,6 +601,8 @@ public class CryptoStore: ObservableObject, WalletObserverStore {
return .signTransaction(signTransactionRequests)
} else if case let signAllTransactionsRequests = await walletService.pendingSignAllTransactionsRequests(), !signAllTransactionsRequests.isEmpty {
return .signAllTransactions(signAllTransactionsRequests)
} else if case let signMessageErrors = await walletService.pendingSignMessageErrors(), !signMessageErrors.isEmpty {
return .signMessageError(signMessageErrors)
} else if case let signMessageRequests = await walletService.pendingSignMessageRequests(), !signMessageRequests.isEmpty {
return .signMessage(signMessageRequests)
} else if let switchRequest = await rpcService.pendingSwitchChainRequests().first {
Expand Down Expand Up @@ -665,6 +671,8 @@ public class CryptoStore: ObservableObject, WalletObserverStore {
walletService.notifyAddSuggestTokenRequestsProcessed(approved, contractAddresses: [token.contractAddress])
case let .signMessage(approved, id):
walletService.notifySignMessageRequestProcessed(approved, id: id, signature: nil, error: nil)
case let .signMessageError(errorId):
walletService.notifySignMessageErrorProcessed(errorId)
case let .getEncryptionPublicKey(approved, requestId):
walletService.notifyGetPublicKeyRequestProcessed(requestId, approved: approved)
case let .decrypt(approved, requestId):
Expand Down
Loading

0 comments on commit 574289f

Please sign in to comment.