-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81dd840
commit 033d74a
Showing
205 changed files
with
51,966 additions
and
31,065 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
82 changes: 82 additions & 0 deletions
82
mrt_wallet/js/js_wallet/models/models/networks/stellar.dart
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,82 @@ | ||
import 'dart:js_interop'; | ||
import 'package:mrt_wallet/app/core.dart'; | ||
import '../../models.dart'; | ||
|
||
@JS("stellar") | ||
external set stellar(Proxy? stellar); | ||
extension type StellarWalletAdapter(JSObject _) implements MRTNetworkAdapter { | ||
external set publicKey(JSObject? publicKey); | ||
|
||
external bool get isConnected; | ||
external set isConnected(bool isConnected); | ||
external set connect(JSFunction f); | ||
|
||
external set signMessage(JSFunction f); | ||
@JS("signTransaction") | ||
external set signTransaction(JSFunction f); | ||
@JS("signAndSendTransaction") | ||
external set signAndSendTransaction(JSFunction f); | ||
@JS("signAllTransactions") | ||
external set signAllTransactions(JSFunction f); | ||
@JS("signAndSendAllTransactions") | ||
external set signAndSendAllTransactions(JSFunction f); | ||
|
||
external set on(JSFunction f); | ||
external set removeListener(JSFunction f); | ||
|
||
factory StellarWalletAdapter.setup() { | ||
return StellarWalletAdapter(JSObject()); | ||
} | ||
} | ||
|
||
class StellarAccountsChanged { | ||
final List<String> accounts; | ||
final String? defaultAddress; | ||
final StellarProviderConnectInfo connectInfo; | ||
StellarAccountsChanged({ | ||
required List<String> accounts, | ||
required this.defaultAddress, | ||
required this.connectInfo, | ||
}) : accounts = accounts.imutable; | ||
factory StellarAccountsChanged.fromJson(Map<String, dynamic> json) { | ||
return StellarAccountsChanged( | ||
accounts: (json["accounts"] as List).cast(), | ||
defaultAddress: json["defaultAddress"], | ||
connectInfo: StellarProviderConnectInfo.fromJson(json["connectInfo"])); | ||
} | ||
Map<String, dynamic> toJson() { | ||
return { | ||
"accounts": accounts, | ||
"defaultAddress": defaultAddress, | ||
"connectInfo": connectInfo.toJson() | ||
}; | ||
} | ||
|
||
JSAny? get accountJS => accounts.map((e) => e.toJS).toList().toJS; | ||
|
||
@JSExport("toString") | ||
@override | ||
String toString() { | ||
return "StellarAccountsChanged${toJson()}"; | ||
} | ||
} | ||
|
||
class StellarProviderConnectInfo { | ||
@JSExport("passphrase") | ||
final String passphrase; | ||
|
||
StellarProviderConnectInfo(this.passphrase); | ||
factory StellarProviderConnectInfo.fromJson(Map<String, dynamic> json) { | ||
return StellarProviderConnectInfo(json["passphrase"]); | ||
} | ||
Map<String, dynamic> toJson() { | ||
return {"passphrase": passphrase}; | ||
} | ||
|
||
JSAny? get toJS => createJSInteropWrapper(this); | ||
@JSExport("toString") | ||
@override | ||
String toString() { | ||
return passphrase; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
part of '../scripts.dart'; | ||
|
||
class StellarPageController extends PageNetworkController { | ||
StellarPageController(); | ||
ProxyMethodHandler<StellarWalletAdapter>? _stellar; | ||
ProxyMethodHandler<StellarWalletAdapter> _createAdapter() { | ||
final adapter = StellarWalletAdapter(JSObject()); | ||
adapter.enable = _requestAccount.toJS; | ||
adapter.on = _addListener.toJS; | ||
adapter.on = _addListener.toJS; | ||
|
||
adapter.removeListener = _removeListener.toJS; | ||
adapter.cancelListener = _removeListener.toJS; | ||
adapter.sendWalletRequest = _onWalletRequest.toJS; | ||
adapter.cancelAllListener = _cancelAllListeners.toJS; | ||
return ProxyMethodHandler<StellarWalletAdapter>(adapter); | ||
} | ||
|
||
void _init() { | ||
_stellar ??= _createAdapter(); | ||
final proxy = Proxy(_stellar!.object, createJSInteropWrapper(_stellar!)); | ||
stellar = proxy; | ||
} | ||
|
||
JSPromise<JSAny?> _requestAccount() { | ||
final params = Web3JSRequestParams(method: "stellar_requestAccounts"); | ||
return _onWalletRequest(params); | ||
} | ||
|
||
void _disable(String? message) { | ||
ton = null; | ||
jsConsole.error(message); | ||
} | ||
|
||
void onEvent(WalletMessageEvent message) { | ||
JSAny? eventData = message.data; | ||
switch (message.eventType) { | ||
case JSEventType.connect: | ||
final chainChange = | ||
StellarProviderConnectInfo.fromJson(message.asMap()); | ||
eventData = chainChange.passphrase.toJS; | ||
break; | ||
case JSEventType.chainChanged: | ||
final chainChange = | ||
StellarProviderConnectInfo.fromJson(message.asMap()); | ||
eventData = chainChange.toJS; | ||
break; | ||
case JSEventType.accountsChanged: | ||
final chainChange = StellarAccountsChanged.fromJson(message.asMap()); | ||
eventData = chainChange.accountJS; | ||
_stellar?.object.selectedAddress = chainChange.defaultAddress?.toJS; | ||
break; | ||
case JSEventType.disconnect: | ||
_stellar?.object.selectedAddress = null; | ||
break; | ||
case JSEventType.disable: | ||
_disable(message.asString()); | ||
return; | ||
case JSEventType.active: | ||
_init(); | ||
return; | ||
default: | ||
return; | ||
} | ||
_eventListeners(message.eventType, jsObject: eventData); | ||
} | ||
|
||
void _eventListeners(JSEventType type, {JSAny? jsObject}) { | ||
if (!_listeners.containsKey(type)) return; | ||
final listeners = <JSFunction>[..._listeners[type]!]; | ||
for (final i in listeners) { | ||
i.callAsFunction(i, jsObject); | ||
} | ||
} | ||
|
||
void _addListener(String type, JSFunction listener) { | ||
final event = JSEventType.fromName(type); | ||
if (event == null || !_listeners.containsKey(event)) return; | ||
_listeners[event]?.add(listener); | ||
_emitEvent(PageMessageEvent.build(event: event)); | ||
} | ||
|
||
void _removeListener(String type, JSFunction listener) { | ||
final event = JSEventType.fromName(type); | ||
_listeners[event]?.remove(listener); | ||
} | ||
|
||
void _cancelAllListeners() { | ||
for (final i in _listeners.keys.toList()) { | ||
_listeners[i]!.clear(); | ||
} | ||
} | ||
|
||
@override | ||
JSClientType get _client => JSClientType.stellar; | ||
} |
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
Oops, something went wrong.