Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Fix crash when React Native is reloaded
Browse files Browse the repository at this point in the history
Though the crash is fixed and the node is properly stopped,
things don't work properly afterwards.
For instance estimating fee fails with the following error:
"Tx gas price does not exceed minimum"
  • Loading branch information
jeanregisser committed Sep 19, 2019
1 parent 2925855 commit 0713313
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ios/ReactNativeGeth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class ReactNativeGeth: RCTEventEmitter, GethNewHeadHandlerProtocol {
self.geth_node = NodeRunner()
super.init()
}

// Called when React Native is reloaded
@objc func invalidate() {
do {
try geth_node.getNode()?.stop()
} catch {
NSLog("Failed stopping geth node: \(error)")
}
}

@objc(supportedEvents)
override func supportedEvents() -> [String]! {
Expand All @@ -44,6 +53,12 @@ class ReactNativeGeth: RCTEventEmitter, GethNewHeadHandlerProtocol {
}

func onNewHead(_ header: GethHeader) {
guard bridge != nil else {
// Don't call sendEvent when the bridge is not set
// this happens when RN is reloaded and this module is unregistered
return
}

do {
let json = try header.encodeJSON()
let dict = try self.convertToDictionary(from: json)
Expand Down

0 comments on commit 0713313

Please sign in to comment.