-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate GETH coin events in MetaMask
- Loading branch information
1 parent
bf6fc5b
commit 8c6d5df
Showing
19 changed files
with
395 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
import 'dart:async'; | ||
import 'dart:html'; | ||
|
||
import 'package:flutter/cupertino.dart'; | ||
import 'package:gethdomains/contracts/events.dart'; | ||
import 'package:gethdomains/contracts/exceptions.dart'; | ||
import 'package:gethdomains/contracts/js_error_info.dart'; | ||
import 'package:js/js_util.dart'; | ||
|
||
class GlobalErrorsSink { | ||
final StreamController<Web3Exception> _web3ErrorsStreamController = | ||
StreamController<Web3Exception>.broadcast(); | ||
|
||
Stream<Web3Exception> get web3ErrorsStream => | ||
_web3ErrorsStreamController.stream; | ||
// Singleton! | ||
static final GlobalErrorsSink _instance = GlobalErrorsSink._internal(); | ||
|
||
GlobalErrorsSink._internal() { | ||
setProperty(window, 'web3ErrorsSink', | ||
allowInterop((int code, String reason) { | ||
debugPrint('GlobalErrorsSink: web3ErrorsSink: $code, $reason'); | ||
addWeb3Error(Web3Exception.fromErrorInfo(JsErrorInfo(code, reason))); | ||
})); | ||
} | ||
|
||
factory GlobalErrorsSink() => _instance; | ||
|
||
Stream<Web3Notice> get web3ErrorsStream => _web3ErrorsStreamController.stream; | ||
|
||
void addWeb3Error(Web3Exception error) { | ||
debugPrint('[Web3Error] $error'); | ||
debugPrint('[Web3Exception] $error'); | ||
_web3ErrorsStreamController.add(error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'dart:async'; | ||
import 'dart:html'; | ||
|
||
import 'package:flutter/cupertino.dart'; | ||
import 'package:gethdomains/contracts/events.dart'; | ||
import 'package:js/js_util.dart'; | ||
|
||
class GlobalEventsSink { | ||
final StreamController<Web3Event> _web3ErrorsStreamController = | ||
StreamController<Web3Event>.broadcast(); | ||
|
||
// Singleton! | ||
static final GlobalEventsSink _instance = GlobalEventsSink._internal(); | ||
|
||
GlobalEventsSink._internal() { | ||
setProperty(window, 'web3EventsSink', | ||
allowInterop((String tag, String content) { | ||
addWeb3Event(Web3Event.fromJsTag(tag, content)); | ||
})); | ||
} | ||
|
||
factory GlobalEventsSink() => _instance; | ||
|
||
Stream<Web3Event> get web3ErrorsStream => _web3ErrorsStreamController.stream; | ||
|
||
Stream<T> _getWeb3Events<T extends Web3Event>() { | ||
return web3ErrorsStream.where((event) => event is T).cast<T>(); | ||
} | ||
|
||
Stream<Web3CoinTransfer> get coinTransfers => | ||
_getWeb3Events<Web3CoinTransfer>(); | ||
|
||
void addWeb3Event(Web3Event event) { | ||
debugPrint('[Web3Event] $event'); | ||
_web3ErrorsStreamController.add(event); | ||
} | ||
} |
Oops, something went wrong.