-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,222 additions
and
919 deletions.
There are no files selected for viewing
333 changes: 222 additions & 111 deletions
333
UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
UnstoppableWallet/UnstoppableWallet/Extensions/Encodable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
|
||
extension Encodable { | ||
public var encoded: Data { | ||
let encoder = JSONEncoder() | ||
encoder.outputFormatting = [.sortedKeys] | ||
return try! encoder.encode(self) | ||
} | ||
public var encodedString: String { | ||
String(data: encoded, encoding: .utf8)! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...eWallet/UnstoppableWallet/Modules/WalletConnect/Main/Proposal/Eip155ProposalHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Foundation | ||
import WalletConnectSign | ||
|
||
class Eip155ProposalHandler { | ||
static let namespace = "eip155" | ||
|
||
static let supportedEvents = [ | ||
"chainChanged", | ||
"accountsChanged", | ||
] | ||
|
||
private let evmBlockchainManager: EvmBlockchainManager | ||
private let account: Account | ||
private let supportedMethods: [String] | ||
|
||
init(evmBlockchainManager: EvmBlockchainManager, account: Account, supportedMethods: [String]) { | ||
self.evmBlockchainManager = evmBlockchainManager | ||
self.account = account | ||
self.supportedMethods = supportedMethods | ||
} | ||
|
||
private func blockchainSet(namespace: ProposalNamespace) -> WalletConnectMainModule.BlockchainSet { | ||
var set = WalletConnectMainModule.BlockchainSet.empty | ||
|
||
for blockchain in namespace.chains ?? [] { | ||
guard let chainId = Int(blockchain.reference), | ||
let evmBlockchain = evmBlockchainManager.blockchain(chainId: chainId) else { | ||
// can't get blockchain by chainId, or can't parse chainId | ||
continue | ||
} | ||
|
||
let chain = evmBlockchainManager.chain(blockchainType: evmBlockchain.type) | ||
|
||
guard let address = try? WalletConnectManager.evmAddress(account: account, chain: chain) else { | ||
// can't get address for chain | ||
continue | ||
} | ||
|
||
set.items.insert( | ||
WalletConnectMainModule.BlockchainItem( | ||
namespace: blockchain.namespace, | ||
chainId: chainId, | ||
blockchain: evmBlockchain, | ||
address: address.eip55 | ||
) | ||
) | ||
} | ||
|
||
namespace.methods.forEach { | ||
if supportedMethods.contains($0) { | ||
set.methods.insert($0) | ||
} | ||
} | ||
|
||
namespace.events.forEach { | ||
if Self.supportedEvents.contains($0) { | ||
set.events.insert($0) | ||
} | ||
} | ||
|
||
return set | ||
} | ||
} | ||
|
||
extension Eip155ProposalHandler: IProposalHandler { | ||
func handle(provider: INamespaceProvider) -> WalletConnectMainModule.BlockchainSet { | ||
var set = WalletConnectMainModule.BlockchainSet.empty | ||
|
||
provider.get(namespace: Self.namespace).forEach { namespace in | ||
set.formUnion(blockchainSet(namespace: namespace)) | ||
} | ||
|
||
return set | ||
} | ||
} |
Oops, something went wrong.