Skip to content

Commit

Permalink
Merge pull request #77 from MetaMask/session-persistance
Browse files Browse the repository at this point in the history
Session persistance
  • Loading branch information
elefantel authored Jun 27, 2023
2 parents 112d30d + 426e829 commit 0d8ffc3
Show file tree
Hide file tree
Showing 19 changed files with 532 additions and 204 deletions.
14 changes: 14 additions & 0 deletions Example/metamask-ios-sdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
D13A7535296E7EA0005EE461 /* ButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D13A7534296E7EA0005EE461 /* ButtonStyle.swift */; };
D148AC75292FCF1B001791E5 /* ConnectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D148AC74292FCF1B001791E5 /* ConnectView.swift */; };
D1494FEB2970149B002D36D6 /* SwitchChainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1494FEA2970149B002D36D6 /* SwitchChainView.swift */; };
D14FA2F429E576EB00F3A059 /* ToastOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14FA2F329E576EB00F3A059 /* ToastOverlay.swift */; };
D14FA2F629E578B200F3A059 /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14FA2F529E578B200F3A059 /* ViewExtension.swift */; };
D14FA2F829E57B6900F3A059 /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14FA2F729E57B6900F3A059 /* ToastView.swift */; };
D1896062296C3F9500216307 /* NetworkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1896061296C3F9500216307 /* NetworkView.swift */; };
D1EA931D29538C570078F088 /* TextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EA931C29538C570078F088 /* TextStyle.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -57,6 +60,9 @@
D13A7534296E7EA0005EE461 /* ButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonStyle.swift; sourceTree = "<group>"; };
D148AC74292FCF1B001791E5 /* ConnectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectView.swift; sourceTree = "<group>"; };
D1494FEA2970149B002D36D6 /* SwitchChainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchChainView.swift; sourceTree = "<group>"; };
D14FA2F329E576EB00F3A059 /* ToastOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastOverlay.swift; sourceTree = "<group>"; };
D14FA2F529E578B200F3A059 /* ViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtension.swift; sourceTree = "<group>"; };
D14FA2F729E57B6900F3A059 /* ToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
D1896061296C3F9500216307 /* NetworkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkView.swift; sourceTree = "<group>"; };
D1EA931C29538C570078F088 /* TextStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyle.swift; sourceTree = "<group>"; };
D5694CDE7AD78A1D52AC0870 /* Pods-metamask-ios-sdk_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-metamask-ios-sdk_Tests.debug.xcconfig"; path = "Target Support Files/Pods-metamask-ios-sdk_Tests/Pods-metamask-ios-sdk_Tests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -184,6 +190,9 @@
D107588E293F385700D6C66B /* TransactionView.swift */,
D1896061296C3F9500216307 /* NetworkView.swift */,
D1494FEA2970149B002D36D6 /* SwitchChainView.swift */,
D14FA2F329E576EB00F3A059 /* ToastOverlay.swift */,
D14FA2F529E578B200F3A059 /* ViewExtension.swift */,
D14FA2F729E57B6900F3A059 /* ToastView.swift */,
);
name = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -380,7 +389,10 @@
D107588F293F385700D6C66B /* TransactionView.swift in Sources */,
D1EA931D29538C570078F088 /* TextStyle.swift in Sources */,
D11D2F1B295075A3000E8003 /* Curvature.swift in Sources */,
D14FA2F629E578B200F3A059 /* ViewExtension.swift in Sources */,
D14FA2F829E57B6900F3A059 /* ToastView.swift in Sources */,
D1494FEB2970149B002D36D6 /* SwitchChainView.swift in Sources */,
D14FA2F429E576EB00F3A059 /* ToastOverlay.swift in Sources */,
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
D13A7535296E7EA0005EE461 /* ButtonStyle.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -594,6 +606,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = D5694CDE7AD78A1D52AC0870 /* Pods-metamask-ios-sdk_Tests.debug.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -620,6 +633,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 780C3F18921DAF52E227C55E /* Pods-metamask-ios-sdk_Tests.release.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
Expand Down
34 changes: 14 additions & 20 deletions Example/metamask-ios-sdk/ConnectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ConnectView: View {
@State private var showError = false

@State private var showProgressView = false
@State private var showToast = false

var body: some View {
NavigationView {
Expand Down Expand Up @@ -74,30 +75,23 @@ struct ConnectView: View {
NavigationLink("Switch chain") {
SwitchChainView()
}

Button {
ethereum.clearSession()
showToast = true
} label: {
Text("Clear Session")
.modifier(TextButton())
.frame(maxWidth: .infinity, maxHeight: 32)
}
.toast(isPresented: $showToast) {
ToastView(message: "Session cleared")
}
.modifier(ButtonStyle())
}
}
}

/* Hide this until changing network url is fully supported by MM
if ethereum.selectedAddress.isEmpty {
Section {
// Silly ZStack hack to hide disclosure indicator on NavigationLink
ZStack() {
NavigationLink {
NetworkView()
} label: {
Text(" ")
}
.opacity(0)
Text("Change network url")
.modifier(TextButton())
.frame(maxWidth: .infinity, maxHeight: 32)
.modifier(ButtonStyle())
}
}
}
*/

if ethereum.selectedAddress.isEmpty {
Section {
ZStack {
Expand Down
35 changes: 35 additions & 0 deletions Example/metamask-ios-sdk/ToastOverlay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ToastOverlay.swift
// metamask-ios-sdk_Example
//

import SwiftUI

struct ToastOverlay<ToastContent>: View where ToastContent : View {
let content: ToastContent
@Binding var isPresented: Bool


var body: some View {
GeometryReader { geometry in
VStack {
Spacer()
HStack {
Spacer()
content
.frame(width: geometry.size.width * 0.8, height: 8)
.animation(.easeIn)
Spacer()
}
Spacer()
}
}
.background(Color.clear)
.edgesIgnoringSafeArea(.bottom)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
isPresented = false
}
}
}
}
26 changes: 26 additions & 0 deletions Example/metamask-ios-sdk/ToastView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ToastView.swift
// metamask-ios-sdk_Example
//

import SwiftUI

struct ToastView: View {
let message: String

var body: some View {
VStack {
Text(message)
.padding()
.foregroundColor(.white)
.background(Color.black)
.clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
}
}
}

struct ToastView_Previews: PreviewProvider {
static var previews: some View {
ToastView(message: "Test message")
}
}
17 changes: 17 additions & 0 deletions Example/metamask-ios-sdk/ViewExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ViewExtension.swift
// metamask-ios-sdk_Example
//

import SwiftUI

extension View {
func toast<ToastContent: View>(isPresented: Binding<Bool>, @ViewBuilder content: () -> ToastContent) -> some View {
ZStack {
self
if isPresented.wrappedValue {
ToastOverlay(content: content(), isPresented: isPresented)
}
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To add MetaMask iOS SDK as an SPM package to your project, in Xcode select: `Fil
dependencies: [
.package(
url: "https://github.com/MetaMask/metamask-ios-sdk",
from: "0.1.0"
from: "0.2.0"
)
]
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class SocketChannel {

var socket: SocketIOClient!
private var socketManager: SocketManager!

var isConnected: Bool {
socket.status == .connected
}

init() {
configureSocket(url: Endpoint.SERVER_URL)
Expand Down Expand Up @@ -55,6 +59,10 @@ extension SocketChannel {
func disconnect() {
socket.disconnect()
}

func terminateHandlers() {
socket.removeAllHandlers()
}
}

// MARK: Events
Expand Down
Loading

0 comments on commit 0d8ffc3

Please sign in to comment.