Skip to content

Commit

Permalink
Feature/wcv1 end (#329)
Browse files Browse the repository at this point in the history
* wc v1 end

* support osmosis
  • Loading branch information
soaryong-c committed Jun 29, 2023
1 parent 2473ef5 commit 463de4f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 16 deletions.
12 changes: 8 additions & 4 deletions Cosmostation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,8 @@
18F4129D2860649E0007E3F2 /* WalletDeriveViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 047FB70F281EC0E8009D8AAF /* WalletDeriveViewController.xib */; };
18F4129E286064A80007E3F2 /* MnemonicListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 047FB6FB281AA8D7009D8AAF /* MnemonicListViewController.xib */; };
18F412A0286064AD0007E3F2 /* MnemonicDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 047FB703281EBA14009D8AAF /* MnemonicDetailViewController.xib */; };
18F4EAD12A4DA0A200CFBE2B /* ApiKeyDev.plist in Resources */ = {isa = PBXBuildFile; fileRef = 187447002930942400849EE4 /* ApiKeyDev.plist */; };
18F4EAD22A4DA0A500CFBE2B /* ApiKey.plist in Resources */ = {isa = PBXBuildFile; fileRef = 187446FE2930940F00849EE4 /* ApiKey.plist */; };
18F811B9282E1FC4008AF0D2 /* WalletStationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 151788EB282E078600A7D7CC /* WalletStationCell.xib */; };
18F811BA282E1FC5008AF0D2 /* WalletStationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 151788EB282E078600A7D7CC /* WalletStationCell.xib */; };
18F811BB282E1FD7008AF0D2 /* WalletStationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 151788EA282E078600A7D7CC /* WalletStationCell.swift */; };
Expand Down Expand Up @@ -8780,6 +8782,7 @@
18FFB771281AF533004E65BB /* EditDisplayChainCell.xib in Resources */,
18FFB772281AF533004E65BB /* TxMultiTransferCell.xib in Resources */,
18FFB773281AF533004E65BB /* Osmosis.storyboard in Resources */,
18F4EAD22A4DA0A500CFBE2B /* ApiKey.plist in Resources */,
18FFB775281AF533004E65BB /* TxSwapWithdrawCell.xib in Resources */,
042C38A728F6896000FF45A2 /* MyValidatorCell.xib in Resources */,
04172B8A29F6901300D6279C /* MainVaultCell.xib in Resources */,
Expand Down Expand Up @@ -9244,6 +9247,7 @@
04D3392427E8803000E82AA7 /* WalletCrescentCell.xib in Resources */,
04C5AE9728632ECD007627EA /* ReInvest1ViewController.xib in Resources */,
28DB570C25FA3BC900B2F0E5 /* HardPoolBorrow3ViewController.xib in Resources */,
18F4EAD12A4DA0A200CFBE2B /* ApiKeyDev.plist in Resources */,
18D4C19928C729C9003F230A /* ManageConnectionViewController.xib in Resources */,
04DEAF43286476AF00F23233 /* HtlcSend2ViewController.xib in Resources */,
2812CA3F26DD4E160095C6AF /* TxIncentiveDelegatorCell.xib in Resources */,
Expand Down Expand Up @@ -12686,7 +12690,7 @@
CODE_SIGN_ENTITLEMENTS = Cosmostation/Cosmostation.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 198;
CURRENT_PROJECT_VERSION = 199;
DEVELOPMENT_TEAM = 8G562MW56M;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -12698,7 +12702,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.9.8;
MARKETING_VERSION = 1.9.9;
PRODUCT_BUNDLE_IDENTIFIER = io.wannabit.cosmostation;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -12718,7 +12722,7 @@
CODE_SIGN_ENTITLEMENTS = Cosmostation/Cosmostation.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 198;
CURRENT_PROJECT_VERSION = 199;
DEVELOPMENT_TEAM = 8G562MW56M;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -12730,7 +12734,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.9.8;
MARKETING_VERSION = 1.9.9;
PRODUCT_BUNDLE_IDENTIFIER = io.wannabit.cosmostation;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
53 changes: 44 additions & 9 deletions Cosmostation/Controller/Main/CommonWCViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ class CommonWCViewController: BaseViewController {
filteredDapps += dapps.filter({ item in
var contain = false
if let title = item["title"] as? String {
contain = contain || title.contains(text)
contain = contain || title.lowercased().contains(text.lowercased())
}
if let title = item["description"] as? String {
contain = contain || title.contains(text)
contain = contain || title.lowercased().contains(text.lowercased())
}
if let title = item["url"] as? String {
contain = contain || title.contains(text)
contain = contain || title.lowercased().contains(text.lowercased())
}
return contain
})
Expand Down Expand Up @@ -925,16 +925,31 @@ class CommonWCViewController: BaseViewController {
func approveV2CosmosAminoRequest() {
if let request = wcV2Request,
let json = try? JSON(data: request.params.encoded) {
let signDoc = json["signDoc"]
var signDoc = json["signDoc"]
let chainId = signDoc["chain_id"].rawString()
let chainType = WUtils.getChainTypeByChainId(chainId)
let chainConfig = ChainFactory.getChainConfig(chainType)
let denom = chainConfig?.stakeDenom
if (signDoc["fee"].exists() && signDoc["fee"]["amount"].exists()) {
let amounts = signDoc["fee"]["amount"].arrayValue
let gas = signDoc["fee"]["gas"].stringValue
let value = NSDecimalNumber(string: gas).dividing(by: NSDecimalNumber(value: 40))
if (amounts.count == 0) {
signDoc["fee"]["amount"] = [["amount": value.stringValue, "denom": denom]]
}
if amounts.count == 1 && amounts.contains(where: { $0["denom"].stringValue == denom && $0["amount"].stringValue == "0" }) {
signDoc["fee"]["amount"] = [["amount": value.stringValue, "denom": denom]]
}
}
let sortedJsonData = try? signDoc.rawData(options: [.sortedKeys, .withoutEscapingSlashes])
let rawOrderdDocSha = sortedJsonData!.sha256()
let chainId = signDoc["chain_id"].rawString()
getKeyAsync(chainName: WUtils.getChainDBName(WUtils.getChainTypeByChainId(chainId)) ) { tuple in
if let signature = try? ECDSA.compactsign(rawOrderdDocSha, privateKey: tuple.privateKey) {
let pubkey: JSON = ["type" : COSMOS_KEY_TYPE_PUBLIC, "value" : tuple.publicKey.base64EncodedString()]
let signature: JSON = ["signature" : signature.base64EncodedString(), "pub_key" : pubkey]
let response: JSON = ["signed" : signDoc.rawValue, "signature":signature.dictionaryValue]
self.moveToBackgroundIfNeedAndAction {
self.respondOnSign(request: request, response: AnyCodable(signature.dictionaryValue))
self.respondOnSign(request: request, response: AnyCodable(response))
self.onShowToast(NSLocalizedString("wc_request_responsed", comment: ""))
}
}
Expand Down Expand Up @@ -1277,6 +1292,10 @@ extension CommonWCViewController: WKNavigationDelegate, WKUIDelegate {
UIApplication.shared.open(URL(string: url.absoluteString.replacingOccurrences(of: "keplrwallet://wcV1", with: "cosmostation://wc"))!, options: [:])
decisionHandler(.cancel)
return
} else if (url.absoluteString.starts(with: "keplrwallet://wcV2")) {
UIApplication.shared.open(URL(string: url.absoluteString.removingPercentEncoding!.replacingOccurrences(of: "keplrwallet://wcV2", with: "cosmostation://wc"))!, options: [:])
decisionHandler(.cancel)
return
} else if (url.scheme == "cosmostation") {
UIApplication.shared.open(url, options: [:])
decisionHandler(.cancel)
Expand Down Expand Up @@ -1383,6 +1402,7 @@ extension CommonWCViewController {
try await Pair.instance.pair(uri: uri)
} catch {
print("Pairing connect error: \(error)")
self.hideLoading()
}
}
}
Expand Down Expand Up @@ -1540,7 +1560,10 @@ extension CommonWCViewController: WKScriptMessageHandler {
if (method == "cos_requestAccount" || method == "cos_account" || method == "ten_requestAccount" || method == "ten_account") {
let params = messageJSON["params"]
let chainId = params["chainName"].stringValue
let chainType = WUtils.getChainTypeByChainId(chainId)
var chainType = WUtils.getChainTypeByChainId(chainId)
if chainType == nil {
chainType = WUtils.getChainTypeByChainName(chainId)
}
let chainConfig = ChainFactory.getChainConfig(chainType)
if (self.chainConfig?.defaultPath != "m/44'/118'/0'/0/X") {
self.onShowToast(NSLocalizedString("error_not_support_wallet", comment: ""))
Expand All @@ -1559,8 +1582,20 @@ extension CommonWCViewController: WKScriptMessageHandler {
data["publicKey"].stringValue = KeyFac.getPublicFromPrivateKey(privateKey).toHexString()
let retVal = ["response": ["result": data], "message": messageJSON, "isCosmostation": true, "messageId": bodyJSON["messageId"]]
self.webView.evaluateJavaScript("window.postMessage(\(try! retVal.json()));")
} else if (method == "cos_supportedChainIds") {
let data = ["official": ["cosmoshub-4", "osmosis-1", "stride-1", "stargaze-1", "core-1"], "unofficial": []]
} else if (method == "cos_supportedChainIds" || method == "ten_supportedChainIds") {
let data = ["official": ["cosmoshub-4", "osmosis-1", "stride-1", "stargaze-1", "core-1", "crescent-1"], "unofficial": []]
let retVal = ["response": ["result": data], "message": messageJSON, "isCosmostation": true, "messageId": bodyJSON["messageId"]]
self.webView.evaluateJavaScript("window.postMessage(\(try! retVal.json()));")
} else if (method == "ten_supportedChainNames" || method == "cos_supportedChainNames") {
let data = ["official": ["cosmos", "osmosis", "stride", "stargaze", "omniflix", "crescent"], "unofficial": []]
let retVal = ["response": ["result": data], "message": messageJSON, "isCosmostation": true, "messageId": bodyJSON["messageId"]]
self.webView.evaluateJavaScript("window.postMessage(\(try! retVal.json()));")
} else if (method == "cos_activatedChainIds" || method == "ten_activatedChainIds") {
let data = ["cosmoshub-4", "osmosis-1", "stride-1", "stargaze-1", "core-1", "crescent-1"]
let retVal = ["response": ["result": data], "message": messageJSON, "isCosmostation": true, "messageId": bodyJSON["messageId"]]
self.webView.evaluateJavaScript("window.postMessage(\(try! retVal.json()));")
} else if (method == "cos_activatedChainNames" || method == "ten_activatedChainNames") {
let data = ["cosmos", "osmosis", "stride", "stargaze", "omniflix", "crescent"]
let retVal = ["response": ["result": data], "message": messageJSON, "isCosmostation": true, "messageId": bodyJSON["messageId"]]
self.webView.evaluateJavaScript("window.postMessage(\(try! retVal.json()));")
} else if (method == "cos_signAmino") {
Expand Down
6 changes: 3 additions & 3 deletions Cosmostation/Controller/Main/MainDappViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class MainDappViewController: BaseViewController {
filteredDapps += dapps.filter({ item in
var contain = false
if let title = item["title"] as? String {
contain = contain || title.contains(text)
contain = contain || title.lowercased().contains(text.lowercased())
}
if let title = item["description"] as? String {
contain = contain || title.contains(text)
contain = contain || title.lowercased().contains(text.lowercased())
}
if let title = item["url"] as? String {
contain = contain || title.contains(text)
contain = contain || title.lowercased().contains(text.lowercased())
}
return contain
})
Expand Down
10 changes: 10 additions & 0 deletions Cosmostation/Utils/WUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,16 @@ public class WUtils {
return nil
}

static func getChainTypeByChainName(_ chainName: String?) -> ChainType? {
let allConfigs = ChainFactory.SUPPRT_CONFIG()
for i in 0..<allConfigs.count {
if (chainName?.contains(allConfigs[i].chainAPIName) == true) {
return allConfigs[i].chainType
}
}
return nil
}

static func isValidChainAddress(_ chainConfig: ChainConfig?, _ address: String?) -> Bool {
guard let chainConfig = chainConfig else { return false }
if let address = address, address.starts(with: "0x") {
Expand Down

0 comments on commit 463de4f

Please sign in to comment.