Skip to content

Commit

Permalink
Support for Solana Web3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed Sep 1, 2024
1 parent 70b1ba9 commit d804077
Show file tree
Hide file tree
Showing 120 changed files with 7,412 additions and 1,512 deletions.
Binary file modified .DS_Store
Binary file not shown.
24 changes: 20 additions & 4 deletions mrt_native_support/macos/Classes/NativeView/WebKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,31 @@ class NativeViewFactory: NSObject, FlutterPlatformViewFactory,WKNavigationDelega
scriptId: '\(self.id)'
};
(function() {
window.addEventListener("error", function (e) {
window.webkit.messageHandlers.MRT.postMessage({
type: 'log',
data: "Error occurred: " + e.error.message,
id: '1',
requestId: '0',
});
return false;
})
window.addEventListener('unhandledrejection', function (e) {
// Send the message to the native side
window.webkit.messageHandlers.MRT.postMessage({
type: 'log',
data: "Error occurred: " + e.reason.message,
id: '1',
requestId: '0',
});
})
// Capture uncaught errors
window.onerror = function(message, source, lineno, colno, error) {
// Concatenate all the details into a single message string
var fullMessage = `Error: ${error ? error.toString() : 'No additional details'}`;
// Send the message to the native side
window.webkit.messageHandlers.MRT.postMessage({
type: 'log',
data: fullMessage,
data: "Error occurred: " + message,
id: '1',
requestId: '0',
});
Expand Down
1 change: 1 addition & 0 deletions mrt_wallet/assets/wasm/crypto.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ _100: Object.is,
_101: s => s.toUpperCase(),
_102: s => s.toLowerCase(),
_103: (a, i) => a.push(i),
_104: (a, i) => a.splice(i, 1)[0],
_110: (a, s) => a.join(s),
_111: (a, s, e) => a.slice(s, e),
_114: a => a.length,
Expand Down
Binary file modified mrt_wallet/assets/wasm/crypto.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions mrt_wallet/assets/webview/bn.js

Large diffs are not rendered by default.

4,710 changes: 3,542 additions & 1,168 deletions mrt_wallet/assets/webview/script.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion mrt_wallet/assets/webview/tron_web.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions mrt_wallet/extentions/bn.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mrt_wallet/extentions/chrome_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"world": "MAIN",
"matches": ["<all_urls>"],
"js": ["tron_web.js","page.js"]
"js": ["bn.js","tron_web.js","page.js"]
}
],
"background": {
Expand Down
2 changes: 1 addition & 1 deletion mrt_wallet/extentions/mozila_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"world": "MAIN",
"matches": ["<all_urls>"],
"js": ["tron_web.js","page.js"]
"js": ["bn.js","tron_web.js","page.js"]
}
],
"background": {
Expand Down
4 changes: 2 additions & 2 deletions mrt_wallet/js/js_wallet/models/models.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export 'models/ethreum/ethereum.dart';
export 'models/networks/ethereum.dart';
export 'models/mrt.dart';
export 'models/exception.dart';
export 'models/requests.dart';
export 'models/completer.dart';
export 'models/tron/tron.dart';
export 'models/networks.dart';
17 changes: 5 additions & 12 deletions mrt_wallet/js/js_wallet/models/models/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@ extension type JSError._(JSAny _) implements JSAny {

@JS("JSWalletError")
extension type JSWalletError._(JSAny _) implements JSError {
external factory JSWalletError(
{required String message,
required int code,
required String walletCode,
String? data,
JSObject? request,
String? requestId,
String? stack});

external String? get stack;
external set stack(String? info);
@JS("toString")
external set toStr(JSFunction f);

factory JSWalletError.fromMessage(
{required Web3ExceptionMessage message, String? stack}) {
final json = message.toJson();
Map<String, dynamic> json = message.toJson();
json["stack"] ??= stack;
final error = JSWalletError._(json.jsify() ?? JSObject());
String toString() {
Expand All @@ -38,8 +29,10 @@ extension type JSWalletError._(JSAny _) implements JSError {
}
factory JSWalletError.fromJson(
{required Map<String, dynamic> message, String? stack}) {
message["stack"] ??= stack;
final error = JSWalletError._(message.jsify() ?? JSObject());
Map<String, dynamic> errorJson = Map<String, dynamic>.from(message);
errorJson["stack"] ??= stack;
errorJson.removeWhere((k, v) => v == null);
final error = JSWalletError._(errorJson.jsify() ?? JSObject());
String toString() {
return message.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion mrt_wallet/js/js_wallet/models/models/mrt.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:js_interop';
import 'package:mrt_native_support/web/api/core/js.dart';

import 'ethreum/ethereum.dart';
import 'networks/ethereum.dart';

@JS("MRT")
external MRTWallet? get mrtNull;
Expand Down
3 changes: 3 additions & 0 deletions mrt_wallet/js/js_wallet/models/models/networks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'networks/ethereum.dart';
export 'networks/solana.dart';
export 'networks/tron.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extension type EthereumRequestParams._(JSObject o)

class ClientMessageEthereum extends PageMessage {
const ClientMessageEthereum({required super.method, required super.params});
factory ClientMessageEthereum.event(EthereumEvnetTypes event) {
factory ClientMessageEthereum.event(EthereumEventTypes event) {
return ClientMessageEthereum(method: event.name, params: null);
}
@override
Expand All @@ -162,7 +162,7 @@ class ClientMessageEthereum extends PageMessage {
}
}

enum EthereumEvnetTypes {
enum EthereumEventTypes {
accountsChanged([100]),
chainChanged([101]),
message([102]),
Expand All @@ -172,13 +172,13 @@ enum EthereumEvnetTypes {
disable([106]);

final List<int> tag;
const EthereumEvnetTypes(this.tag);
static EthereumEvnetTypes fromTag(List<int>? tag) {
const EthereumEventTypes(this.tag);
static EthereumEventTypes fromTag(List<int>? tag) {
return values.firstWhere((e) => BytesUtils.bytesEqual(e.tag, tag),
orElse: () => throw Web3RequestExceptionConst.internalError);
}

static EthereumEvnetTypes? fromName(String? name) {
static EthereumEventTypes? fromName(String? name) {
try {
return values.firstWhere((e) => e.name == name,
orElse: () => throw Web3RequestExceptionConst.internalError);
Expand All @@ -193,7 +193,7 @@ class JSWalletMessageResponseEthereum extends JSWalletNetworkEvent {
required this.event,
required super.data,
}) : super(client: JSClientType.ethereum);
final EthereumEvnetTypes event;
final EthereumEventTypes event;
factory JSWalletMessageResponseEthereum.deserialize(
{List<int>? bytes, CborObject? object, String? hex}) {
final CborListValue values = CborSerializable.cborTagValue(
Expand All @@ -206,7 +206,7 @@ class JSWalletMessageResponseEthereum extends JSWalletNetworkEvent {
throw Web3RequestExceptionConst.internalError;
}
return JSWalletMessageResponseEthereum(
event: EthereumEvnetTypes.fromTag(values.elementAt(1)),
event: EthereumEventTypes.fromTag(values.elementAt(1)),
data: StringUtils.toJson(values.elementAt<String>(2))["result"]);
}

Expand Down
Loading

0 comments on commit d804077

Please sign in to comment.