2023-03-01 00:36:54 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
import 'package:stackwallet/models/ethereum/erc20_token.dart';
|
|
|
|
import 'package:stackwallet/models/ethereum/erc721_token.dart';
|
|
|
|
|
|
|
|
abstract class EthContractInfo extends Equatable {
|
|
|
|
const EthContractInfo({
|
2023-02-23 22:59:58 +00:00
|
|
|
required this.contractAddress,
|
|
|
|
required this.name,
|
|
|
|
required this.symbol,
|
|
|
|
required this.decimals,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String contractAddress;
|
|
|
|
final String name;
|
|
|
|
final String symbol;
|
|
|
|
final int decimals;
|
2023-02-28 19:26:17 +00:00
|
|
|
|
2023-03-01 00:36:54 +00:00
|
|
|
static EthContractInfo? fromMap(Map<String, dynamic> map) {
|
|
|
|
switch (map["runtimeType"]) {
|
|
|
|
case "Erc20ContractInfo":
|
|
|
|
return Erc20ContractInfo(
|
|
|
|
contractAddress: map["contractAddress"] as String,
|
|
|
|
name: map["name"] as String,
|
|
|
|
symbol: map["symbol"] as String,
|
|
|
|
decimals: map["decimals"] as int,
|
|
|
|
);
|
|
|
|
case "Erc721ContractInfo":
|
|
|
|
return Erc721ContractInfo(
|
|
|
|
contractAddress: map["contractAddress"] as String,
|
|
|
|
name: map["name"] as String,
|
|
|
|
symbol: map["symbol"] as String,
|
|
|
|
decimals: map["decimals"] as int,
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2023-02-28 19:26:17 +00:00
|
|
|
}
|
2023-03-01 00:36:54 +00:00
|
|
|
|
|
|
|
static EthContractInfo? fromJson(String json) => fromMap(
|
|
|
|
Map<String, dynamic>.from(
|
|
|
|
jsonDecode(json) as Map,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
|
|
"runtimeType": "$runtimeType",
|
|
|
|
"contractAddress": contractAddress,
|
|
|
|
"name": name,
|
|
|
|
"symbol": symbol,
|
|
|
|
"decimals": decimals,
|
|
|
|
};
|
|
|
|
|
|
|
|
String toJson() => jsonEncode(toMap());
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() => toMap().toString();
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object?> get props => [contractAddress];
|
2023-02-23 22:59:58 +00:00
|
|
|
}
|