Skip to content

Commit

Permalink
feature: notify rn sdk whenever chainId or account changes (#190)
Browse files Browse the repository at this point in the history
* feature: notify rn sdk whenever chainId or account changes

* chore: bump ios sdk version
  • Loading branch information
elefantel authored Sep 20, 2024
1 parent d0d93d3 commit 2981241
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Alternatively, you can add the URL directly in your project's package file:
dependencies: [
.package(
url: "https://github.com/MetaMask/metamask-ios-sdk",
from: "0.8.8"
from: "0.8.9"
)
]
```
Expand Down
10 changes: 10 additions & 0 deletions Sources/metamask-ios-sdk/Classes/Extensions/Notification.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Notification.swift
//

import Foundation

public extension Notification.Name {
static let MetaMaskAccountChanged = Notification.Name("MetaMaskAccountChanged")
static let MetaMaskChainIdChanged = Notification.Name("MetaMaskChainChanged")
}
2 changes: 2 additions & 0 deletions Sources/metamask-ios-sdk/Classes/SDK/MetaMaskSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ public extension MetaMaskSDK {
extension MetaMaskSDK: EthereumEventsDelegate {
func chainIdChanged(_ chainId: String) {
self.chainId = chainId
NotificationCenter.default.post(name: .MetaMaskChainIdChanged, object: nil, userInfo: ["chainId": chainId])
}

func accountChanged(_ account: String) {
self.account = account
connected = true
NotificationCenter.default.post(name: .MetaMaskAccountChanged, object: nil, userInfo: ["account": account])
}
}

Expand Down
2 changes: 1 addition & 1 deletion metamask-ios-sdk.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'metamask-ios-sdk'
s.version = '0.8.8'
s.version = '0.8.9'
s.summary = 'Enable users to easily connect with their MetaMask Mobile wallet.'
s.swift_version = '5.5'

Expand Down

0 comments on commit 2981241

Please sign in to comment.