Skip to content

Commit

Permalink
Merge branch 'base/seamless-dapp-browser' into feature/custom-modal-p…
Browse files Browse the repository at this point in the history
…resentation
  • Loading branch information
svojsu committed Jan 3, 2025
2 parents 3f15e56 + 1b5dcb4 commit 7739d6b
Show file tree
Hide file tree
Showing 48 changed files with 438 additions and 61 deletions.
16 changes: 13 additions & 3 deletions novawallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
0C252BBF2B3D3CEB0047308F /* TypeRegistry+Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C252BBE2B3D3CEB0047308F /* TypeRegistry+Node.swift */; };
0C259EA42B46721B00CB86E4 /* ProxyMessageSheetViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C259EA32B46721B00CB86E4 /* ProxyMessageSheetViewFactory.swift */; };
0C259EA82B46C55C00CB86E4 /* ExtrinsicSigningErrorHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C259EA72B46C55C00CB86E4 /* ExtrinsicSigningErrorHandling.swift */; };
0C28DF0D2D1AC69F0016DB8E /* SNAddressType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DAC197268D3DD9002D0DF4 /* SNAddressType.swift */; };
0C28DF1C2D2008670016DB8E /* AssetFungibilityPreservationProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C28DF1B2D2008670016DB8E /* AssetFungibilityPreservationProvider.swift */; };
0C29B5382A4C68A500E35C6D /* AnimationUpdatibleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C29B5372A4C68A500E35C6D /* AnimationUpdatibleView.swift */; };
0C2A3C932CDC813B00A0E2B3 /* AssetsExchangeOperationFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C2A3C922CDC813B00A0E2B3 /* AssetsExchangeOperationFactory.swift */; };
0C2A3C952CDC8ADB00A0E2B3 /* SwapAssetSelectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C2A3C942CDC8ADB00A0E2B3 /* SwapAssetSelectionModel.swift */; };
Expand Down Expand Up @@ -881,6 +883,7 @@
0CFA161E2B0CED07007AF885 /* GovTreasurySpentLocalHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFA161D2B0CED07007AF885 /* GovTreasurySpentLocalHandler.swift */; };
0CFA16202B0CEF31007AF885 /* GovTreasuryApproveHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFA161F2B0CEF31007AF885 /* GovTreasuryApproveHandler.swift */; };
0CFFB9D32D11A67C00172E8C /* XcmTokensArrivalDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFFB9D22D11A67C00172E8C /* XcmTokensArrivalDetector.swift */; };
0CFFB9D92D17592500172E8C /* OperatingSystemApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFFB9D82D17592500172E8C /* OperatingSystemApi.swift */; };
0D5245ED354CC52A842C85A0 /* TransferConfirmViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD8B98AB03AAF06AA891695 /* TransferConfirmViewLayout.swift */; };
0D8213272889988B78188D9A /* DAppWalletAuthInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 337EC62037D657258BCBC02F /* DAppWalletAuthInteractor.swift */; };
0DACB56C0BDD4C984FE3C15C /* AssetReceiveWireframe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C1179A25C22AF0875A1ADCD /* AssetReceiveWireframe.swift */; };
Expand Down Expand Up @@ -5528,6 +5531,7 @@
0C252BBE2B3D3CEB0047308F /* TypeRegistry+Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TypeRegistry+Node.swift"; sourceTree = "<group>"; };
0C259EA32B46721B00CB86E4 /* ProxyMessageSheetViewFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyMessageSheetViewFactory.swift; sourceTree = "<group>"; };
0C259EA72B46C55C00CB86E4 /* ExtrinsicSigningErrorHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtrinsicSigningErrorHandling.swift; sourceTree = "<group>"; };
0C28DF1B2D2008670016DB8E /* AssetFungibilityPreservationProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetFungibilityPreservationProvider.swift; sourceTree = "<group>"; };
0C29B5372A4C68A500E35C6D /* AnimationUpdatibleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimationUpdatibleView.swift; sourceTree = "<group>"; };
0C2A3C922CDC813B00A0E2B3 /* AssetsExchangeOperationFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetsExchangeOperationFactory.swift; sourceTree = "<group>"; };
0C2A3C942CDC8ADB00A0E2B3 /* SwapAssetSelectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwapAssetSelectionModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6283,6 +6287,7 @@
0CFA161D2B0CED07007AF885 /* GovTreasurySpentLocalHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GovTreasurySpentLocalHandler.swift; sourceTree = "<group>"; };
0CFA161F2B0CEF31007AF885 /* GovTreasuryApproveHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GovTreasuryApproveHandler.swift; sourceTree = "<group>"; };
0CFFB9D22D11A67C00172E8C /* XcmTokensArrivalDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcmTokensArrivalDetector.swift; sourceTree = "<group>"; };
0CFFB9D82D17592500172E8C /* OperatingSystemApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperatingSystemApi.swift; sourceTree = "<group>"; };
0D32A720511D1D3B0F479AFE /* DAppBrowserTabListProtocols.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DAppBrowserTabListProtocols.swift; sourceTree = "<group>"; };
0D37CF4AFB06AF3AC2F78057 /* ImportCloudPasswordPresenter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ImportCloudPasswordPresenter.swift; sourceTree = "<group>"; };
0D3FE2CE7F9F2836755DBA63 /* GovernanceUnlockConfirmProtocols.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = GovernanceUnlockConfirmProtocols.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -17051,13 +17056,14 @@
path = PerformOperation;
sourceTree = "<group>";
};
84468A05286652EF00BCBE00 /* Operation */ = {
84468A05286652EF00BCBE00 /* AssetOperations */ = {
isa = PBXGroup;
children = (
84468A062866530100BCBE00 /* AssetStorageInfoOperationFactory.swift */,
2D32BE1F2C6CF4A20047F520 /* AssetTransferAggregationFactory.swift */,
0C28DF1B2D2008670016DB8E /* AssetFungibilityPreservationProvider.swift */,
);
path = Operation;
path = AssetOperations;
sourceTree = "<group>";
};
844ADE7C28CB34F600EE29F7 /* AutomationTime */ = {
Expand Down Expand Up @@ -19113,6 +19119,7 @@
0CDEF1652C27EC83003878F2 /* RuntimeMetadataRepositoryFactory.swift */,
0C7104782C2AC0F300487E64 /* InMemoryCaching.swift */,
0C33E8B92D011D2E0090096A /* Debouncer.swift */,
0CFFB9D82D17592500172E8C /* OperatingSystemApi.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -19468,6 +19475,7 @@
8490154E24ACD521008F705E /* Substrate */ = {
isa = PBXGroup;
children = (
84468A05286652EF00BCBE00 /* AssetOperations */,
0CEB6B3F2CA50DB400609DC2 /* AssetConverters */,
0CCE3AAD2BF5BBBF00D55F03 /* Operations */,
84A3B89C2836CF8F00DE2669 /* Coders */,
Expand Down Expand Up @@ -21739,7 +21747,6 @@
isa = PBXGroup;
children = (
84ED6BDC28688C9000B3C558 /* View */,
84468A05286652EF00BCBE00 /* Operation */,
84E25BEA27E87D3D00290BF1 /* Validation */,
8466780D27EB28FF007935D3 /* BaseTransfer */,
DA7D18D3AF772CC2385C228C /* TransferSetup */,
Expand Down Expand Up @@ -25569,6 +25576,7 @@
7778FE3E2B90CCDD0023E801 /* SubstrateStorageVersion.swift in Sources */,
7778FE3D2B90CCA20023E801 /* String+Split.swift in Sources */,
7778FE502B9108AA0023E801 /* CompoundOperationWrapper+Result.swift in Sources */,
0C28DF0D2D1AC69F0016DB8E /* SNAddressType.swift in Sources */,
0C8FDBA02CAD022700775D7F /* SubstrateDataModel.xcdatamodeld in Sources */,
77EDF9242B96DCEB003266B1 /* ProxyAccountModel.swift in Sources */,
7778FE402B90F42D0023E801 /* PriceDataMapper.swift in Sources */,
Expand Down Expand Up @@ -27923,6 +27931,7 @@
84B8AA7929F905C800347A37 /* WalletConnectStateInitiating.swift in Sources */,
8468B87224F63D3A00B76BC6 /* AddAccount+AccountCreateWireframe.swift in Sources */,
9DFB37659A6B911A4D54623E /* AccountConfirmInteractor.swift in Sources */,
0C28DF1C2D2008670016DB8E /* AssetFungibilityPreservationProvider.swift in Sources */,
84BAFCD626AF64CB00871E86 /* SelectValidatorsViewLayout.swift in Sources */,
84C5ADD52812745F006D7388 /* WalletAccountViewModel.swift in Sources */,
8863C7AC29D499D30068AD54 /* Web3NameService.swift in Sources */,
Expand Down Expand Up @@ -28617,6 +28626,7 @@
848CCB442832EE9B00A1FD00 /* GeneralStorageSubscriptionFactory.swift in Sources */,
8483B15828F98C9F0048B295 /* ReferendumVotersViewModel.swift in Sources */,
2D7BEBD62C23818B00BBCB57 /* NetworkManageNodeWireframe.swift in Sources */,
0CFFB9D92D17592500172E8C /* OperatingSystemApi.swift in Sources */,
84BB3CEE267CD6B500676FFE /* CrowdloanContributionDict.swift in Sources */,
8473F4B4282BD5A1007CC55A /* StakingRelaychainInteractor.swift in Sources */,
845B821B26EF80BC00D25C72 /* MetaAccountModel.swift in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions novawallet/Common/Helpers/AddressConversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ extension AccountAddress {
}
}

func toChainAccountIdOrSubstrateGeneric(
using conversion: ChainFormat
) throws -> AccountId {
switch conversion {
case .ethereum:
return try extractEthereumAccountId()
case let .substrate(prefix):
let addressFactory = SS58AddressFactory()
let type = try addressFactory.type(fromAddress: self).uint16Value

guard type == prefix || type == SNAddressType.genericSubstrate.rawValue else {
throw AccountAddressConversionError.invalidChainAddress
}

return try addressFactory.accountId(fromAddress: self, type: type)
}
}

func toSubstrateAccountId(using prefix: UInt16? = nil) throws -> AccountId {
let factory = SS58AddressFactory()

Expand Down
24 changes: 24 additions & 0 deletions novawallet/Common/Helpers/OperatingSystemApi.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import UIKit

protocol OperatingSystemMediating: AnyObject {
func disableScreenSleep()
func enableScreenSleep()
}

final class OperatingSystemMediator {
let application: UIApplication

init(application: UIApplication = .shared) {
self.application = application
}
}

extension OperatingSystemMediator: OperatingSystemMediating {
func disableScreenSleep() {
application.isIdleTimerDisabled = true
}

func enableScreenSleep() {
application.isIdleTimerDisabled = false
}
}
4 changes: 2 additions & 2 deletions novawallet/Common/Ledger/SupportedLedgerApps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ extension SupportedLedgerApp {
[
SupportedLedgerApp(chainId: KnowChainId.polkadot, coin: 354, cla: 0x90, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.kusama, coin: 434, cla: 0x99, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.statemint, coin: 354, cla: 0x96, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.statemine, coin: 434, cla: 0x97, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.polkadotAssetHub, coin: 354, cla: 0x96, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.kusamaAssetHub, coin: 434, cla: 0x97, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.karura, coin: 686, cla: 0x9A, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.acala, coin: 787, cla: 0x9B, type: .substrate),
SupportedLedgerApp(chainId: KnowChainId.nodle, coin: 1003, cla: 0x98, type: .substrate),
Expand Down
4 changes: 2 additions & 2 deletions novawallet/Common/Model/KnownChainIds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import Foundation

enum KnowChainId {
static let kusama = "b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe"
static let statemine = "48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a"
static let kusamaAssetHub = "48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a"
static let polkadot = "91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"
static let polkadotAssetHub = "68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f"
static let acala = "fc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c"
static let statemint = "68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f"
static let edgeware = "742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b"
static let karura = "baf5aabe40646d11f0ee8abbdc64f4a4b7674925cba08e4a05ff9ebed6e2126b"
static let nodle = "97da7ede98d7bad4e36b4d734b6055425a3be036da2a332ea5a7037656427a21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ extension AssetExchangePathFilter: GraphEdgeFiltering {
return true
}

if edge.requiresOriginKeepAliveOnIntermediatePosition() {
return false
}

let canPayFees = (chainAssetIn.isUtilityAsset || feeSupport.canPayFee(inNonNative: chainAssetIn)) &&
edge.canPayNonNativeFeesInIntermediatePosition()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ extension AssetHubExchangeEdge: AssetExchangableGraphEdge {
true
}

func requiresOriginKeepAliveOnIntermediatePosition() -> Bool {
false
}

func beginMetaOperation(
for amountIn: Balance,
amountOut: Balance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ final class AssetHubExchangeMetaOperation: AssetExchangeBaseMetaOperation {}

extension AssetHubExchangeMetaOperation: AssetExchangeMetaOperationProtocol {
var label: AssetExchangeMetaOperationLabel { .swap }
var requiresOriginAccountKeepAlive: Bool { false }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension AssetsExchangePathCostEstimator: AssetsExchangePathCostEstimating {
) -> CompoundOperationWrapper<AssetsExchangePathCost> {
let operation = ClosureOperation<AssetsExchangePathCost> {
guard let usdtTiedAsset = self.chainRegistry.getChain(
for: KnowChainId.statemint
for: KnowChainId.polkadotAssetHub
)?.chainAssetForSymbol("USDT") else {
return .zero
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AnyAssetExchangeEdge {

private let shouldIgnoreFeeRequirementClosure: (any AssetExchangableGraphEdge) -> Bool
private let canPayFeesInIntermediatePositionClosure: () -> Bool
private let requiresKeepAliveOnIntermediatePositionClosure: () -> Bool
private let typeClosure: () -> AssetExchangeEdgeType

private let beginMetaOperationClosure: (Balance, Balance) throws -> AssetExchangeMetaOperationProtocol
Expand All @@ -37,6 +38,7 @@ class AnyAssetExchangeEdge {
appendToOperationClosure = edge.appendToOperation
shouldIgnoreFeeRequirementClosure = edge.shouldIgnoreFeeRequirement
canPayFeesInIntermediatePositionClosure = edge.canPayNonNativeFeesInIntermediatePosition
requiresKeepAliveOnIntermediatePositionClosure = edge.requiresOriginKeepAliveOnIntermediatePosition
typeClosure = { edge.type }
beginMetaOperationClosure = edge.beginMetaOperation
appendToMetaOperationClosure = edge.appendToMetaOperation
Expand Down Expand Up @@ -74,6 +76,10 @@ extension AnyAssetExchangeEdge: AssetExchangableGraphEdge {
canPayFeesInIntermediatePositionClosure()
}

func requiresOriginKeepAliveOnIntermediatePosition() -> Bool {
requiresKeepAliveOnIntermediatePositionClosure()
}

func beginMetaOperation(for amountIn: Balance, amountOut: Balance) throws -> AssetExchangeMetaOperationProtocol {
try beginMetaOperationClosure(amountIn, amountOut)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ protocol AssetExchangableGraphEdge: GraphQuotableEdge {

func canPayNonNativeFeesInIntermediatePosition() -> Bool

func requiresOriginKeepAliveOnIntermediatePosition() -> Bool

var type: AssetExchangeEdgeType { get }

func beginMetaOperation(for amountIn: Balance, amountOut: Balance) throws -> AssetExchangeMetaOperationProtocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import Foundation
enum AssetExchangeMetaOperationLabel: Equatable {
case swap
case transfer

var isTransfer: Bool {
switch self {
case .transfer:
true
case .swap:
false
}
}
}

protocol AssetExchangeMetaOperationProtocol {
Expand All @@ -11,6 +20,7 @@ protocol AssetExchangeMetaOperationProtocol {
var amountIn: Balance { get }
var amountOut: Balance { get }
var label: AssetExchangeMetaOperationLabel { get }
var requiresOriginAccountKeepAlive: Bool { get }
}

class AssetExchangeBaseMetaOperation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ final class CrosschainAssetsExchangeProvider: AssetsExchangeBaseProvider {
let userStorageFacade: StorageFacadeProtocol
let substrateStorageFacade: StorageFacadeProtocol
let signingWrapperFactory: SigningWrapperFactoryProtocol
let fungibilityPreservationProvider: AssetFungibilityPreservationProviding

init(
wallet: MetaAccountModel,
syncService: XcmTransfersSyncServiceProtocol,
chainRegistry: ChainRegistryProtocol,
pathCostEstimator: AssetsExchangePathCostEstimating,
fungibilityPreservationProvider: AssetFungibilityPreservationProviding,
signingWrapperFactory: SigningWrapperFactoryProtocol,
userStorageFacade: StorageFacadeProtocol,
substrateStorageFacade: StorageFacadeProtocol,
Expand All @@ -27,6 +29,7 @@ final class CrosschainAssetsExchangeProvider: AssetsExchangeBaseProvider {
self.signingWrapperFactory = signingWrapperFactory
self.userStorageFacade = userStorageFacade
self.substrateStorageFacade = substrateStorageFacade
self.fungibilityPreservationProvider = fungibilityPreservationProvider

super.init(
chainRegistry: chainRegistry,
Expand Down Expand Up @@ -90,6 +93,7 @@ final class CrosschainAssetsExchangeProvider: AssetsExchangeBaseProvider {
),
xcmTransfers: xcmTransfers,
executionTimeEstimator: AssetExchangeTimeEstimator(chainRegistry: chainRegistry),
fungibilityPreservationProvider: fungibilityPreservationProvider,
operationQueue: operationQueue,
logger: logger
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ extension CrosschainExchangeEdge: AssetExchangableGraphEdge {
deliveryFeeNotPaidOrFromHolding()
}

func requiresOriginKeepAliveOnIntermediatePosition() -> Bool {
guard
let chainIn = host.allChains[origin.chainId],
let chainAssetIn = chainIn.chainAsset(for: origin.assetId) else {
return false
}

return host.fungibilityPreservationProvider.requiresPreservationForCrosschain(
assetIn: chainAssetIn
)
}

func beginMetaOperation(
for amountIn: Balance,
amountOut: Balance
Expand All @@ -92,11 +104,16 @@ extension CrosschainExchangeEdge: AssetExchangableGraphEdge {
throw ChainModelFetchError.noAsset(assetId: destination.assetId)
}

let keepAlive = host.fungibilityPreservationProvider.requiresPreservationForCrosschain(
assetIn: assetIn
)

return CrosschainExchangeMetaOperation(
assetIn: assetIn,
assetOut: assetOut,
amountIn: amountIn,
amountOut: amountOut
amountOut: amountOut,
requiresOriginAccountKeepAlive: keepAlive
)
}

Expand Down
Loading

0 comments on commit 7739d6b

Please sign in to comment.