diff --git a/NFTY.xcodeproj/project.pbxproj b/NFTY.xcodeproj/project.pbxproj index 0c9e09ec..bba7b66b 100644 --- a/NFTY.xcodeproj/project.pbxproj +++ b/NFTY.xcodeproj/project.pbxproj @@ -1499,7 +1499,7 @@ CODE_SIGN_ENTITLEMENTS = NFTY/NFTY.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 15; + CURRENT_PROJECT_VERSION = 16; DEVELOPMENT_ASSET_PATHS = "NFTY/Preview\\ Content"; DEVELOPMENT_TEAM = C28QWE5379; ENABLE_PREVIEWS = YES; @@ -1527,7 +1527,7 @@ CODE_SIGN_ENTITLEMENTS = NFTY/NFTY.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 15; + CURRENT_PROJECT_VERSION = 16; DEVELOPMENT_ASSET_PATHS = "NFTY/Preview\\ Content"; DEVELOPMENT_TEAM = C28QWE5379; ENABLE_PREVIEWS = YES; diff --git a/NFTY.xcodeproj/xcuserdata/vkohli.xcuserdatad/xcschemes/xcschememanagement.plist b/NFTY.xcodeproj/xcuserdata/vkohli.xcuserdatad/xcschemes/xcschememanagement.plist index 85667854..757b77a9 100644 --- a/NFTY.xcodeproj/xcuserdata/vkohli.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/NFTY.xcodeproj/xcuserdata/vkohli.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ CreateAttributeScores.xcscheme_^#shared#^_ orderHint - 3 + 2 CreateRankingFiles.xcscheme_^#shared#^_ orderHint - 2 + 1 Demo (Playground) 1.xcscheme @@ -38,7 +38,7 @@ DownloadCollection.xcscheme_^#shared#^_ orderHint - 1 + 3 DownloadCryptoPunks.xcscheme_^#shared#^_ diff --git a/NFTY/Assets.xcassets/RainbowWallet.imageset/Contents.json b/NFTY/Assets.xcassets/RainbowWallet.imageset/Contents.json new file mode 100644 index 00000000..202afc37 --- /dev/null +++ b/NFTY/Assets.xcassets/RainbowWallet.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "RainbowWallet.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/NFTY/Assets.xcassets/RainbowWallet.imageset/RainbowWallet.png b/NFTY/Assets.xcassets/RainbowWallet.imageset/RainbowWallet.png new file mode 100644 index 00000000..efa12b99 Binary files /dev/null and b/NFTY/Assets.xcassets/RainbowWallet.imageset/RainbowWallet.png differ diff --git a/NFTY/ViewModel/UserWalletModel.swift b/NFTY/ViewModel/UserWalletModel.swift index 975354f5..faecc312 100644 --- a/NFTY/ViewModel/UserWalletModel.swift +++ b/NFTY/ViewModel/UserWalletModel.swift @@ -89,17 +89,43 @@ class UserWallet: ObservableObject { } } + private func getConnectionUrl(scheme: String,wcUrl:WCURL) throws -> String { + + switch(scheme) { + case "metamask:": + // https://github.com/WalletConnect/WalletConnectSwift/issues/79#issuecomment-1007324661 + + let _encodeURL = wcUrl.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "" + let _end2 = _encodeURL.replacingOccurrences(of: "=", with: "%3D").replacingOccurrences(of: "&", with: "%26") + + let metamaskLink = "https://metamask.app.link/wc?uri=" + return "\(metamaskLink)\(_end2)" + case "rainbow:": + // https://github.com/WalletConnect/WalletConnectSwift/issues/79#issuecomment-1007324661 + + let _encodeURL = wcUrl.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "" + let _end2 = _encodeURL.replacingOccurrences(of: "=", with: "%3D").replacingOccurrences(of: "&", with: "%26") + + let metamaskLink = "https://rnbwapp.com/wc?uri=" + return "\(metamaskLink)\(_end2)" + default: + let uri = wcUrl.fullyPercentEncodedStr + var delimiter: String + if scheme.contains("http") { + delimiter = "/" + } else { + delimiter = "//" + } + let redirect = "www.nftygo.com".addingPercentEncoding(withAllowedCharacters: .alphanumerics)! + return "\(scheme)\(delimiter)wc?uri=\(uri)&redirectUrl=\(redirect)" + } + + + } + func connectToWallet(scheme: String) throws -> Void { let wcUrl = connect() - let uri = wcUrl.fullyPercentEncodedStr - var delimiter: String - if scheme.contains("http") { - delimiter = "/" - } else { - delimiter = "//" - } - let redirect = "www.nftygo.com".addingPercentEncoding(withAllowedCharacters: .alphanumerics)! - let urlStr = "\(scheme)\(delimiter)wc?uri=\(uri)&redirectUrl=\(redirect)" + let urlStr = try! getConnectionUrl(scheme: scheme, wcUrl: wcUrl) let url = URL(string: urlStr)! // we need a delay so that WalletConnectClient can send handshake request DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1000)) { diff --git a/NFTY/Views/ConnectWalletSheet.swift b/NFTY/Views/ConnectWalletSheet.swift index 304c76f3..5fbf4178 100644 --- a/NFTY/Views/ConnectWalletSheet.swift +++ b/NFTY/Views/ConnectWalletSheet.swift @@ -27,82 +27,62 @@ struct UserWalletConnectorView : View { .foregroundColor(.secondary) } case (.none,false),(.some,_): - HStack(spacing:30) { + HStack { Spacer() - HStack { + VStack { + Text("Sign-in using") + .foregroundColor(.secondary) + .font(.subheadline) + .bold() - /* - Button(action:{ - UIImpactFeedbackGenerator(style: .light) - .impactOccurred() - - self.userWallet.removeWalletConnectSession() - self.isConnecting = true - let url = try! userWallet.connectToWallet(link:"metamask:") - // we need a delay so that WalletConnectClient can send handshake request - DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1000)) { - print("Launching=\(url)") - UIApplication.shared.open(url, options: [:], completionHandler: nil) - } - }) { - VStack { - Image("Metamask") - .resizable() - .frame(width: 60,height:60) - - Text("Sign-In with MetaMask") - .font(.caption) - .fontWeight(.bold) - .multilineTextAlignment(.center) - .foregroundColor(Color.orange) - } - .frame(minWidth: 0, maxWidth: .infinity) - .padding() - .border(Color.orange) - .clipShape(RoundedRectangle(cornerRadius:20, style: .continuous)) - .overlay( - RoundedRectangle(cornerRadius:20, style: .continuous) - .stroke(Color.orange, lineWidth: 1)) - } - - */ - - Button(action:{ - UIImpactFeedbackGenerator(style: .light) - .impactOccurred() - self.userWallet.removeWalletConnectSession() - self.isConnecting = true - try! userWallet.connectToWallet(scheme:"trust:") - }) { - VStack { - Image("TrustWallet") - .resizable() - .frame(width: 60,height:60) + HStack(spacing:20) { + + let config = [ + (title:"MetaMask",image:"Metamask",color:Color.orange,scheme:"metamask:"), + (title:"Trust Wallet",image:"TrustWallet",color:Color.blue,scheme:"trust:"), + (title:"Rainbow",image:"RainbowWallet",color:Color(red:200/255,green:230/255,blue:80/255),scheme:"rainbow:"), + ]; + + ForEach(config.indices) { index in + let (title,image,color,scheme) = config[index]; + Button(action:{ + UIImpactFeedbackGenerator(style: .light) + .impactOccurred() + self.userWallet.removeWalletConnectSession() + self.isConnecting = true + try! userWallet.connectToWallet(scheme:scheme) + }) { + VStack { + Image(image) + .resizable() + .frame(width: 50,height:50) + + Text(title) + .font(.caption) + .fontWeight(.bold) + .multilineTextAlignment(.center) + .foregroundColor(color) + } + .padding() + .border(color) + .clipShape(RoundedRectangle(cornerRadius:20, style: .continuous)) + .overlay( + RoundedRectangle(cornerRadius:20, style: .continuous) + .stroke(color, lineWidth: 3)) + } - Text("Sign-In with Trust Wallet") - .font(.caption) - .fontWeight(.bold) - .multilineTextAlignment(.center) - .foregroundColor(Color.blue) } - .frame(minWidth: 0, maxWidth: .infinity) - .padding() - .border(Color.blue) - .clipShape(RoundedRectangle(cornerRadius:20, style: .continuous)) - .overlay( - RoundedRectangle(cornerRadius:20, style: .continuous) - .stroke(Color.blue, lineWidth: 1)) } } Spacer() } - switch(userWallet.signedIn) { - case false: + switch(userWallet.signedIn,userWallet.walletConnectSession?.walletInfo?.peerMeta.name) { + case (false,_),(_,.none): EmptyView() - case true: - Text("Currently signed-in using Trust Wallet") + case (true,.some(let wallet)): + Text("Currently signed-in using \(wallet)") .foregroundColor(.secondary) .font(.caption) .italic()