Skip to content

Commit 0d8ffc3

Browse files
authored
Merge pull request #77 from MetaMask/session-persistance
Session persistance
2 parents 112d30d + 426e829 commit 0d8ffc3

File tree

19 files changed

+532
-204
lines changed

19 files changed

+532
-204
lines changed

Example/metamask-ios-sdk.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
D13A7535296E7EA0005EE461 /* ButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D13A7534296E7EA0005EE461 /* ButtonStyle.swift */; };
2222
D148AC75292FCF1B001791E5 /* ConnectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D148AC74292FCF1B001791E5 /* ConnectView.swift */; };
2323
D1494FEB2970149B002D36D6 /* SwitchChainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1494FEA2970149B002D36D6 /* SwitchChainView.swift */; };
24+
D14FA2F429E576EB00F3A059 /* ToastOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14FA2F329E576EB00F3A059 /* ToastOverlay.swift */; };
25+
D14FA2F629E578B200F3A059 /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14FA2F529E578B200F3A059 /* ViewExtension.swift */; };
26+
D14FA2F829E57B6900F3A059 /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14FA2F729E57B6900F3A059 /* ToastView.swift */; };
2427
D1896062296C3F9500216307 /* NetworkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1896061296C3F9500216307 /* NetworkView.swift */; };
2528
D1EA931D29538C570078F088 /* TextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EA931C29538C570078F088 /* TextStyle.swift */; };
2629
/* End PBXBuildFile section */
@@ -57,6 +60,9 @@
5760
D13A7534296E7EA0005EE461 /* ButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonStyle.swift; sourceTree = "<group>"; };
5861
D148AC74292FCF1B001791E5 /* ConnectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectView.swift; sourceTree = "<group>"; };
5962
D1494FEA2970149B002D36D6 /* SwitchChainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchChainView.swift; sourceTree = "<group>"; };
63+
D14FA2F329E576EB00F3A059 /* ToastOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastOverlay.swift; sourceTree = "<group>"; };
64+
D14FA2F529E578B200F3A059 /* ViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtension.swift; sourceTree = "<group>"; };
65+
D14FA2F729E57B6900F3A059 /* ToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
6066
D1896061296C3F9500216307 /* NetworkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkView.swift; sourceTree = "<group>"; };
6167
D1EA931C29538C570078F088 /* TextStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyle.swift; sourceTree = "<group>"; };
6268
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>"; };
@@ -184,6 +190,9 @@
184190
D107588E293F385700D6C66B /* TransactionView.swift */,
185191
D1896061296C3F9500216307 /* NetworkView.swift */,
186192
D1494FEA2970149B002D36D6 /* SwitchChainView.swift */,
193+
D14FA2F329E576EB00F3A059 /* ToastOverlay.swift */,
194+
D14FA2F529E578B200F3A059 /* ViewExtension.swift */,
195+
D14FA2F729E57B6900F3A059 /* ToastView.swift */,
187196
);
188197
name = Views;
189198
sourceTree = "<group>";
@@ -380,7 +389,10 @@
380389
D107588F293F385700D6C66B /* TransactionView.swift in Sources */,
381390
D1EA931D29538C570078F088 /* TextStyle.swift in Sources */,
382391
D11D2F1B295075A3000E8003 /* Curvature.swift in Sources */,
392+
D14FA2F629E578B200F3A059 /* ViewExtension.swift in Sources */,
393+
D14FA2F829E57B6900F3A059 /* ToastView.swift in Sources */,
383394
D1494FEB2970149B002D36D6 /* SwitchChainView.swift in Sources */,
395+
D14FA2F429E576EB00F3A059 /* ToastOverlay.swift in Sources */,
384396
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
385397
D13A7535296E7EA0005EE461 /* ButtonStyle.swift in Sources */,
386398
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
@@ -594,6 +606,7 @@
594606
isa = XCBuildConfiguration;
595607
baseConfigurationReference = D5694CDE7AD78A1D52AC0870 /* Pods-metamask-ios-sdk_Tests.debug.xcconfig */;
596608
buildSettings = {
609+
CODE_SIGN_IDENTITY = "Apple Development";
597610
CODE_SIGN_STYLE = Manual;
598611
DEVELOPMENT_TEAM = "";
599612
FRAMEWORK_SEARCH_PATHS = (
@@ -620,6 +633,7 @@
620633
isa = XCBuildConfiguration;
621634
baseConfigurationReference = 780C3F18921DAF52E227C55E /* Pods-metamask-ios-sdk_Tests.release.xcconfig */;
622635
buildSettings = {
636+
CODE_SIGN_IDENTITY = "Apple Development";
623637
CODE_SIGN_STYLE = Manual;
624638
DEVELOPMENT_TEAM = "";
625639
FRAMEWORK_SEARCH_PATHS = (

Example/metamask-ios-sdk/ConnectView.swift

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct ConnectView: View {
2525
@State private var showError = false
2626

2727
@State private var showProgressView = false
28+
@State private var showToast = false
2829

2930
var body: some View {
3031
NavigationView {
@@ -74,30 +75,23 @@ struct ConnectView: View {
7475
NavigationLink("Switch chain") {
7576
SwitchChainView()
7677
}
78+
79+
Button {
80+
ethereum.clearSession()
81+
showToast = true
82+
} label: {
83+
Text("Clear Session")
84+
.modifier(TextButton())
85+
.frame(maxWidth: .infinity, maxHeight: 32)
86+
}
87+
.toast(isPresented: $showToast) {
88+
ToastView(message: "Session cleared")
89+
}
90+
.modifier(ButtonStyle())
7791
}
7892
}
7993
}
8094

81-
/* Hide this until changing network url is fully supported by MM
82-
if ethereum.selectedAddress.isEmpty {
83-
Section {
84-
// Silly ZStack hack to hide disclosure indicator on NavigationLink
85-
ZStack() {
86-
NavigationLink {
87-
NetworkView()
88-
} label: {
89-
Text(" ")
90-
}
91-
.opacity(0)
92-
Text("Change network url")
93-
.modifier(TextButton())
94-
.frame(maxWidth: .infinity, maxHeight: 32)
95-
.modifier(ButtonStyle())
96-
}
97-
}
98-
}
99-
*/
100-
10195
if ethereum.selectedAddress.isEmpty {
10296
Section {
10397
ZStack {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// ToastOverlay.swift
3+
// metamask-ios-sdk_Example
4+
//
5+
6+
import SwiftUI
7+
8+
struct ToastOverlay<ToastContent>: View where ToastContent : View {
9+
let content: ToastContent
10+
@Binding var isPresented: Bool
11+
12+
13+
var body: some View {
14+
GeometryReader { geometry in
15+
VStack {
16+
Spacer()
17+
HStack {
18+
Spacer()
19+
content
20+
.frame(width: geometry.size.width * 0.8, height: 8)
21+
.animation(.easeIn)
22+
Spacer()
23+
}
24+
Spacer()
25+
}
26+
}
27+
.background(Color.clear)
28+
.edgesIgnoringSafeArea(.bottom)
29+
.onAppear {
30+
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
31+
isPresented = false
32+
}
33+
}
34+
}
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// ToastView.swift
3+
// metamask-ios-sdk_Example
4+
//
5+
6+
import SwiftUI
7+
8+
struct ToastView: View {
9+
let message: String
10+
11+
var body: some View {
12+
VStack {
13+
Text(message)
14+
.padding()
15+
.foregroundColor(.white)
16+
.background(Color.black)
17+
.clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
18+
}
19+
}
20+
}
21+
22+
struct ToastView_Previews: PreviewProvider {
23+
static var previews: some View {
24+
ToastView(message: "Test message")
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ViewExtension.swift
3+
// metamask-ios-sdk_Example
4+
//
5+
6+
import SwiftUI
7+
8+
extension View {
9+
func toast<ToastContent: View>(isPresented: Binding<Bool>, @ViewBuilder content: () -> ToastContent) -> some View {
10+
ZStack {
11+
self
12+
if isPresented.wrappedValue {
13+
ToastOverlay(content: content(), isPresented: isPresented)
14+
}
15+
}
16+
}
17+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To add MetaMask iOS SDK as an SPM package to your project, in Xcode select: `Fil
2424
dependencies: [
2525
.package(
2626
url: "https://github.com/MetaMask/metamask-ios-sdk",
27-
from: "0.1.0"
27+
from: "0.2.0"
2828
)
2929
]
3030
```

Sources/metamask-ios-sdk/Classes/Communication/SocketChannel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class SocketChannel {
1717

1818
var socket: SocketIOClient!
1919
private var socketManager: SocketManager!
20+
21+
var isConnected: Bool {
22+
socket.status == .connected
23+
}
2024

2125
init() {
2226
configureSocket(url: Endpoint.SERVER_URL)
@@ -55,6 +59,10 @@ extension SocketChannel {
5559
func disconnect() {
5660
socket.disconnect()
5761
}
62+
63+
func terminateHandlers() {
64+
socket.removeAllHandlers()
65+
}
5866
}
5967

6068
// MARK: Events

0 commit comments

Comments
 (0)