-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/chains improvement #1955
base: master
Are you sure you want to change the base?
Changes from 3 commits
56cc8b8
4db8ab8
87820cb
ffaa91e
71e3df5
0e0cdfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const String _chainTelos = 'telos'; | ||
const String _chainTelosTest = 'telosTestnet'; | ||
const String _chainEos = 'eos'; | ||
const String _chainEosTest = 'eosTestnet'; | ||
|
||
enum SeedsChains { | ||
telos, | ||
telosTestnet, | ||
eos, | ||
eosTestnet, | ||
} | ||
|
||
extension SeedsChainsExtension on SeedsChains { | ||
String get value { | ||
switch (this) { | ||
case SeedsChains.telos: | ||
return _chainTelos; | ||
case SeedsChains.telosTestnet: | ||
return _chainTelosTest; | ||
case SeedsChains.eos: | ||
return _chainEos; | ||
case SeedsChains.eosTestnet: | ||
return _chainEosTest; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,12 @@ import 'package:collection/collection.dart'; | |
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:json_schema2/json_schema2.dart'; | ||
import 'package:seeds/datasource/remote/api/http_repo/seeds_chain_names.dart'; | ||
import 'package:seeds/datasource/remote/api/tokenmodels_repository.dart'; | ||
import 'package:seeds/datasource/remote/firebase/firebase_remote_config.dart'; | ||
import 'package:seeds/domain-shared/shared_use_cases/get_token_models_use_case.dart'; | ||
import 'package:seeds/screens/wallet/components/tokens_cards/components/currency_info_card.dart'; | ||
|
||
|
||
class TokenModel extends Equatable { | ||
static const seedsEcosysUsecase = 'seedsecosys'; | ||
static List<TokenModel> allTokens = [seedsToken]; | ||
|
@@ -24,19 +24,16 @@ class TokenModel extends Equatable { | |
final int precision; | ||
final List<String>? usecases; | ||
|
||
String get id => "$contract#$symbol"; | ||
String get id => "$contract#$symbol#$chainName"; | ||
|
||
ImageProvider get backgroundImage { | ||
return | ||
backgroundImageUrl.startsWith("assets") ? | ||
AssetImage(backgroundImageUrl) as ImageProvider : | ||
NetworkImage(backgroundImageUrl); | ||
return backgroundImageUrl.startsWith("assets") | ||
? AssetImage(backgroundImageUrl) as ImageProvider | ||
: NetworkImage(backgroundImageUrl); | ||
} | ||
|
||
ImageProvider get logo { | ||
return | ||
logoUrl.startsWith("assets") ? | ||
AssetImage(logoUrl) as ImageProvider : | ||
NetworkImage(logoUrl); | ||
return logoUrl.startsWith("assets") ? AssetImage(logoUrl) as ImageProvider : NetworkImage(logoUrl); | ||
} | ||
|
||
const TokenModel({ | ||
|
@@ -53,20 +50,20 @@ class TokenModel extends Equatable { | |
|
||
static Future<Result<void>> installSchema() async { | ||
final result = await TokenModelsRepository().getSchema(); | ||
if(result.isValue) { | ||
final tmastrSchemaMap = result.asValue!.value; | ||
tmastrSchema = JsonSchema.createSchema(tmastrSchemaMap); | ||
return Result.value(null); | ||
} | ||
print('Error getting Token Master schema from chain'); | ||
return result; | ||
if (result.isValue) { | ||
final tmastrSchemaMap = result.asValue!.value; | ||
tmastrSchema = JsonSchema.createSchema(tmastrSchemaMap); | ||
return Result.value(null); | ||
} | ||
print('Error getting Token Master schema from chain'); | ||
return result; | ||
} | ||
|
||
static TokenModel? fromJson(Map<String,dynamic> data) { | ||
final Map<String,dynamic> parsedJson = json.decode(data["json"]); | ||
static TokenModel? fromJson(Map<String, dynamic> data) { | ||
final Map<String, dynamic> parsedJson = json.decode(data["json"]); | ||
bool extendJson(String dataField, String jsonField) { | ||
final jsonData = parsedJson[jsonField]; | ||
if( jsonData != null && jsonData != data[dataField] ) { | ||
if (jsonData != null && jsonData != data[dataField]) { | ||
print('${data[dataField]}: mismatched $dataField in json' | ||
' $jsonData, ${data[dataField]}'); | ||
return false; | ||
|
@@ -75,31 +72,32 @@ class TokenModel extends Equatable { | |
return true; | ||
} | ||
} | ||
if (!( extendJson("chainName", "chain") && | ||
extendJson("contract", "account") && | ||
extendJson("symbolcode", "symbol") && | ||
extendJson("usecases", "usecases"))) { | ||
|
||
if (!(extendJson("chainName", "chain") && | ||
extendJson("contract", "account") && | ||
extendJson("symbolcode", "symbol") && | ||
extendJson("usecases", "usecases"))) { | ||
return null; | ||
} | ||
if(tmastrSchema == null) { | ||
if (tmastrSchema == null) { | ||
return null; | ||
} | ||
final validationErrors = tmastrSchema!.validateWithErrors(parsedJson); | ||
if(validationErrors.isNotEmpty) { | ||
if (validationErrors.isNotEmpty) { | ||
print('${data["symbolcode"]}:\t${validationErrors.map((e) => e.toString())}'); | ||
return null; | ||
} | ||
return TokenModel( | ||
chainName: parsedJson["chain"]!, | ||
contract: parsedJson["account"]!, | ||
symbol: parsedJson["symbol"]!, | ||
name: parsedJson["name"]!, | ||
logoUrl: parsedJson["logo"]!, | ||
balanceSubTitle: parsedJson["subtitle"], | ||
backgroundImageUrl: parsedJson["bg_image"] ?? CurrencyInfoCard.defaultBgImage, | ||
precision: parsedJson["precision"] ?? 4, | ||
usecases: parsedJson["usecases"], | ||
); | ||
chainName: parsedJson["chain"]!, | ||
contract: parsedJson["account"]!, | ||
symbol: parsedJson["symbol"]!, | ||
name: parsedJson["name"]!, | ||
logoUrl: parsedJson["logo"]!, | ||
balanceSubTitle: parsedJson["subtitle"], | ||
backgroundImageUrl: parsedJson["bg_image"] ?? CurrencyInfoCard.defaultBgImage, | ||
precision: parsedJson["precision"] ?? 4, | ||
usecases: parsedJson["usecases"], | ||
); | ||
} | ||
|
||
factory TokenModel.fromId(String tokenId) { | ||
|
@@ -120,22 +118,20 @@ class TokenModel extends Equatable { | |
static Future<void> updateModels(List<String> acceptList, [List<String>? infoList]) async { | ||
final selector = TokenModelSelector(acceptList: acceptList, infoList: infoList); | ||
final tokenListResult = await GetTokenModelsUseCase().run(selector); | ||
if(tokenListResult.isError) { | ||
if (tokenListResult.isError) { | ||
return; | ||
} | ||
final tokenList = tokenListResult.asValue!.value; | ||
for(final newtoken in tokenList) { | ||
allTokens.removeWhere((token) => token.contract==newtoken.contract | ||
&& token.chainName==newtoken.chainName | ||
&& token.symbol==newtoken.symbol); | ||
for (final newtoken in tokenList) { | ||
allTokens.removeWhere((token) => token.id == newtoken.id); | ||
} | ||
allTokens.addAll(tokenList); | ||
} | ||
|
||
static Future<void> installModels(List<String> acceptList, [List<String>? infoList]) async { | ||
if( remoteConfigurations.featureFlagTokenMasterListEnabled) { | ||
if (remoteConfigurations.featureFlagTokenMasterListEnabled) { | ||
final installResult = await installSchema(); | ||
if(installResult.isValue) { | ||
if (installResult.isValue) { | ||
allTokens = [seedsToken]; | ||
await updateModels(acceptList, infoList); | ||
return; | ||
|
@@ -145,18 +141,16 @@ class TokenModel extends Equatable { | |
} | ||
|
||
static void pruneRemoving(List<String> useCaseList) { | ||
allTokens.removeWhere((token) => | ||
token.usecases?.any((uc) => useCaseList.contains(uc)) ?? false); | ||
allTokens.removeWhere((token) => token.usecases?.any((uc) => useCaseList.contains(uc)) ?? false); | ||
} | ||
|
||
static void pruneKeeping(List<String> useCaseList) { | ||
allTokens.removeWhere((token) => ! | ||
(token.usecases?.any((uc) => useCaseList.contains(uc)) ?? false)); | ||
allTokens.removeWhere((token) => !(token.usecases?.any((uc) => useCaseList.contains(uc)) ?? false)); | ||
} | ||
} | ||
|
||
const seedsToken = TokenModel( | ||
chainName: "Telos", | ||
chainName: SeedsChains.telos.value, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems we can't use extensions in constant expressions. Ref explanation here: dart-lang/language#663 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you need to update your flutter version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh you're right - there's something weird going on with this PR. |
||
contract: "token.seeds", | ||
symbol: "SEEDS", | ||
name: "Seeds", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lower case "telos" makes sense but we have a conflict with legacy code in
seeds.tokensmaster.cpp
and the existingtmastr.seeds
table entries which use "Telos".Suggested fix would be to patch a conditional expression here which specifically converts "Telos" to "telos".
seeds_light_wallet/lib/datasource/remote/model/token_model.dart
Line 93 in ac72252
e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an actual bug or ... ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to choose whether "telos" or "Telos" is the string we use in TokenModel.chainName.
seeds_light_wallet/lib/datasource/remote/api/http_repo/seeds_chain_names.dart
Line 1 in 0e0cdfd
So yes, it's a bug that will appear as soon as we start using this PR code.