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

8.7.2 Ledger for DApps Browser & Bugfixes #1245

Merged
merged 32 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
abb89ae
add transitive closure for proxy detection
ERussel Oct 7, 2024
9779bd0
draft ledger for DApp browser
ERussel Oct 8, 2024
a41e9c8
fix tests
ERussel Oct 8, 2024
b00abc9
fix icon
ERussel Oct 8, 2024
d037a39
support intermediate proxied nodes in proxy path finder
ERussel Oct 8, 2024
5b676e9
pass destination asset info to validator
svojsu Oct 8, 2024
e80c6f1
validate row model isActive
svojsu Oct 8, 2024
7a3405c
Merge pull request #1231 from novasamatech/fix/self-sufficient-valida…
svojsu Oct 9, 2024
1bf49a0
Merge pull request #1232 from novasamatech/fix/transfer-options-sheet…
svojsu Oct 9, 2024
ff3d0e1
Merge pull request #1228 from novasamatech/feature/recursive-proxies
ERussel Oct 9, 2024
8086950
Merge pull request #1227 from novasamatech/feature/dapp-generic-ledger
ERussel Oct 9, 2024
0ac36bb
pre-configured network management fixes
svojsu Oct 9, 2024
8554d64
fix modify network
svojsu Oct 9, 2024
b926f09
elevate support section and reorder rows
svojsu Oct 9, 2024
be18bbb
Merge pull request #1237 from novasamatech/main
ERussel Oct 10, 2024
b3b3754
Merge pull request #1235 from novasamatech/fix/settings-reorder
svojsu Oct 10, 2024
0c65c41
Merge pull request #1234 from novasamatech/fix/preconfigured-networks
svojsu Oct 10, 2024
6cbc003
Merge branch 'develop' into base/bugfixes
svojsu Oct 10, 2024
df5abe4
remove nested proxies
ERussel Oct 11, 2024
7203939
fix typo
ERussel Oct 11, 2024
c77e3f2
fix tests
ERussel Oct 11, 2024
4b97963
Merge pull request #1240 from novasamatech/fix/remove-nested-proxies
ERussel Oct 11, 2024
15f1d07
validate has chain account for swipe gov banner
svojsu Oct 11, 2024
8742287
use common account validation logic
svojsu Oct 11, 2024
d0185a1
add localisation
leohar Oct 11, 2024
b95867f
Merge pull request #1241 from novasamatech/fix/hide-swipe-gov-for-no-…
svojsu Oct 12, 2024
a71b888
fix wrong strings
leohar Oct 14, 2024
d14dac1
Merge pull request #1243 from novasamatech/feat/settings_localisation
svojsu Oct 14, 2024
ef534f0
Merge pull request #1242 from novasamatech/base/bugfixes
svojsu Oct 14, 2024
2971fb6
add backup validation
ERussel Oct 15, 2024
d7c0953
add more tests
ERussel Oct 16, 2024
5e5a3b5
Merge pull request #1246 from novasamatech/fix/detect-wallet-with-no-…
ERussel Oct 16, 2024
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 @@ -27,9 +27,18 @@ extension ProxyResolution {
}

let accounts: [AccountId: [MetaChainAccountResponse]]
let proxieds: [AccountId: MetaChainAccountResponse]

init(accounts: [AccountId: [MetaChainAccountResponse]]) {
self.accounts = accounts

proxieds = accounts.reduce(into: [AccountId: MetaChainAccountResponse]()) { accum, keyValue in
guard let account = keyValue.value.first(where: { $0.chainAccount.type == .proxied }) else {
return
}

accum[keyValue.key] = account
}
}

private func buildResult(
Expand Down Expand Up @@ -79,8 +88,10 @@ extension ProxyResolution {
}

let components = try solution.components.map { oldComponent in
let optAccount = accounts[oldComponent.proxyAccountId] ?? proxieds[oldComponent.proxyAccountId]

guard
let account = accounts[oldComponent.proxyAccountId],
let account = optAccount,
let proxyType = oldComponent.applicableTypes.first else {
throw PathFinderError.noAccount
}
Expand Down
25 changes: 17 additions & 8 deletions novawallet/Common/Services/Proxy/ChainProxySyncService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,34 @@ final class ChainProxySyncService: ObservableSyncService, ChainProxySyncServiceP
let proxyList = try proxyListWrapper.targetOperation.extractNoCancellableResultData()
let chainMetaAccounts = try metaAccountsWrapper.targetOperation.extractNoCancellableResultData()

let notProxiedAccountIdList: [AccountId] = chainMetaAccounts.compactMap { wallet in
let possibleProxiesList: [AccountId] = chainMetaAccounts.compactMap { wallet in
guard wallet.info.type != .proxied else {
return nil
}

return wallet.info.fetch(for: chainModel.accountRequest())?.accountId
}

let notProxiedAccountIds = Set(notProxiedAccountIdList)
var possibleProxiesIds = Set(possibleProxiesList)
var prevProxiesIds = possibleProxiesIds
var proxies: [ProxiedAccountId: [ProxyAccount]] = [:]

// We only need remote proxieds for proxies we have locally and we don't support delaed proxies
let proxies = proxyList.compactMapValues { accounts in
accounts.filter {
!$0.hasDelay && notProxiedAccountIds.contains($0.accountId)
}
}.filter { !$0.value.isEmpty }
repeat {
// We only need remote proxieds for current proxies and we don't support delayed proxies
proxies = proxyList.compactMapValues { accounts in
accounts.filter {
!$0.hasDelay && possibleProxiesIds.contains($0.accountId)
}
}.filter { !$0.value.isEmpty }

prevProxiesIds = possibleProxiesIds
possibleProxiesIds = possibleProxiesIds.union(Set(proxies.keys))

} while possibleProxiesIds != prevProxiesIds

return proxies
}

proxyListOperation.addDependency(proxyListWrapper.targetOperation)
proxyListOperation.addDependency(metaAccountsWrapper.targetOperation)

Expand Down
58 changes: 44 additions & 14 deletions novawallet/Common/Storage/WalletsUpdateMediator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,44 @@ final class WalletUpdateMediator {
self.operationQueue = operationQueue
}

private static func nonProxiedWalletReachable(
from proxiedWallet: ManagedMetaAccountModel,
wallets: [ManagedMetaAccountModel],
removeIds: Set<MetaAccountModel.Id>
) -> Bool {
var currentProxieds: Set<MetaAccountModel.Id> = [proxiedWallet.info.metaId]
var prevProxieds = currentProxieds
var foundWallets: [MetaAccountModel.Id: ManagedMetaAccountModel] = [proxiedWallet.info.metaId: proxiedWallet]

repeat {
let newReachableWallets: [ManagedMetaAccountModel] = currentProxieds.flatMap { proxiedId in
guard
let proxied = foundWallets[proxiedId],
let chainAccount = proxied.info.chainAccounts.first(where: { $0.proxy != nil }),
let proxy = chainAccount.proxy else {
return [ManagedMetaAccountModel]()
}

return wallets.filter { $0.info.has(accountId: proxy.accountId, chainId: chainAccount.chainId) }
}

if newReachableWallets.contains(
where: { $0.info.type != .proxied && !removeIds.contains($0.info.metaId) }
) {
return true
}

foundWallets = newReachableWallets.reduce(into: foundWallets) {
$0[$1.info.metaId] = $1
}

prevProxieds = currentProxieds
currentProxieds = Set(foundWallets.keys)
} while prevProxieds != currentProxieds

return false
}

private static func includeProxiedsToRemoveSet(
starting removeIds: Set<MetaAccountModel.Id>,
wallets: [ManagedMetaAccountModel]
Expand All @@ -46,20 +84,12 @@ final class WalletUpdateMediator {
// we can have nested proxieds so we make sure to remove them all

repeat {
let newProxiedIdsToRemove = allProxieds.filter { proxiedWallet in
guard
let chainAccount = proxiedWallet.info.chainAccounts.first(where: { $0.proxy != nil }),
let proxy = chainAccount.proxy else {
return false
}

return wallets.allSatisfy { wallet in
guard !newRemovedIds.contains(wallet.identifier) else {
return true
}

return !wallet.info.has(accountId: proxy.accountId, chainId: chainAccount.chainId)
}
let newProxiedIdsToRemove = allProxieds.filter { proxied in
!nonProxiedWalletReachable(
from: proxied,
wallets: wallets,
removeIds: newRemovedIds
)
}.map(\.identifier)

oldRemovedIds = newRemovedIds
Expand Down
2 changes: 1 addition & 1 deletion novawallet/Common/ViewModel/RemoteImageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class RemoteImageSerializer: CacheSerializer {
return uiImage
} else {
let imsvg = SVGKImage(data: data)
return imsvg?.uiImage ?? UIImage()
return imsvg?.uiImage
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ final class DAppBrowserSigningState: DAppBrowserBaseState {
super.init(stateMachine: stateMachine)
}

private func provideOperationResponse(with signature: Data, nextState: DAppBrowserStateProtocol) throws {
private func provideOperationResponse(
with signature: Data,
modifiedTransaction: Data?,
nextState: DAppBrowserStateProtocol
) throws {
guard let msgType = signingType.msgType else {
return
}

let identifier = (0 ... UInt32.max).randomElement() ?? 0
let result = PolkadotExtensionSignerResult(
identifier: UInt(identifier),
signature: signature.toHex(includePrefix: true)
signature: signature.toHex(includePrefix: true),
signedTransaction: modifiedTransaction?.toHex(includePrefix: true)
)

try provideResponse(for: msgType, result: result, nextState: nextState)
Expand Down Expand Up @@ -54,7 +59,11 @@ extension DAppBrowserSigningState: DAppBrowserStateProtocol {

if let signature = response.signature {
do {
try provideOperationResponse(with: signature, nextState: nextState)
try provideOperationResponse(
with: signature,
modifiedTransaction: response.modifiedTransaction,
nextState: nextState
)
} catch {
stateMachine?.emit(error: error, nextState: nextState)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ final class DAppEthereumConfirmInteractor: DAppOperationBaseInteractor {
switch result {
case let .success(txHash):
let txHashData = try Data(hexString: txHash)
let response = DAppOperationResponse(signature: txHashData)
let response = DAppOperationResponse(signature: txHashData, modifiedTransaction: nil)
let result: Result<DAppOperationResponse, Error> = .success(response)
self.presenter?.didReceive(responseResult: result, for: self.request)
case let .failure(error):
Expand Down Expand Up @@ -234,7 +234,7 @@ final class DAppEthereumConfirmInteractor: DAppOperationBaseInteractor {
do {
switch result {
case let .success(signedTransaction):
let response = DAppOperationResponse(signature: signedTransaction)
let response = DAppOperationResponse(signature: signedTransaction, modifiedTransaction: nil)
let result: Result<DAppOperationResponse, Error> = .success(response)
self.presenter?.didReceive(responseResult: result, for: self.request)
case let .failure(error):
Expand Down Expand Up @@ -304,7 +304,7 @@ extension DAppEthereumConfirmInteractor: DAppOperationConfirmInteractorInputProt
}

func reject() {
let response = DAppOperationResponse(signature: nil)
let response = DAppOperationResponse(signature: nil, modifiedTransaction: nil)
presenter?.didReceive(responseResult: .success(response), for: request)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extension DAppEthereumSignBytesInteractor: DAppOperationConfirmInteractorInputPr

do {
let signature = try signingOperation.extractNoCancellableResultData()
let response = DAppOperationResponse(signature: signature)
let response = DAppOperationResponse(signature: signature, modifiedTransaction: nil)

self.presenter?.didReceive(responseResult: .success(response), for: self.request)
} catch {
Expand All @@ -119,7 +119,7 @@ extension DAppEthereumSignBytesInteractor: DAppOperationConfirmInteractorInputPr
}

func reject() {
let response = DAppOperationResponse(signature: nil)
let response = DAppOperationResponse(signature: nil, modifiedTransaction: nil)
presenter?.didReceive(responseResult: .success(response), for: request)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,13 @@ extension DAppOperationConfirmInteractor {
)
}

// TODO: Find out whether to return this validation

guard
let specVersion = BigUInt.fromHexString(extrinsic.specVersion) /* ,
codingFactory.specVersion == specVersion */ else {
let specVersion = BigUInt.fromHexString(extrinsic.specVersion) else {
throw DAppOperationConfirmInteractorError.extrinsicBadField(name: "specVersion")
}

// TODO: Find out whether to return this validation

guard
let transactionVersion = BigUInt.fromHexString(extrinsic.transactionVersion) /* ,
codingFactory.txVersion == transactionVersion */ else {
let transactionVersion = BigUInt.fromHexString(extrinsic.transactionVersion) else {
throw DAppOperationConfirmInteractorError.extrinsicBadField(name: "transactionVersion")
}

Expand Down Expand Up @@ -135,6 +129,8 @@ extension DAppOperationConfirmInteractor {
specVersion: UInt32(specVersion),
tip: tip,
transactionVersion: UInt32(transactionVersion),
metadataHash: extrinsic.metadataHash,
withSignedTransaction: extrinsic.withSignedTransaction ?? false,
signedExtensions: expectedSignedExtensions,
version: extrinsic.version
)
Expand Down
Loading
Loading