mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
update assets schema
This commit is contained in:
parent
cd1736ffa6
commit
1c88ca5f8d
5 changed files with 4663 additions and 261 deletions
|
@ -1493,8 +1493,12 @@ class StackTheme {
|
||||||
|
|
||||||
late final ThemeAssetsV2? assetsV2;
|
late final ThemeAssetsV2? assetsV2;
|
||||||
|
|
||||||
|
// cheat build runner into adding this at end of property id list in isar
|
||||||
|
@Name("zAssetsV3")
|
||||||
|
late final ThemeAssetsV3? assetsV3;
|
||||||
|
|
||||||
@ignore
|
@ignore
|
||||||
IThemeAssets get assets => assetsV2 ?? assetsV1!;
|
IThemeAssets get assets => assetsV3 ?? assetsV2 ?? assetsV1!;
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
|
@ -1517,13 +1521,20 @@ class StackTheme {
|
||||||
themeId: json["id"] as String,
|
themeId: json["id"] as String,
|
||||||
)
|
)
|
||||||
: null
|
: null
|
||||||
..assetsV2 = version >= 2
|
..assetsV2 = version == 2
|
||||||
? ThemeAssetsV2.fromJson(
|
? ThemeAssetsV2.fromJson(
|
||||||
json: Map<String, dynamic>.from(json["assets"] as Map),
|
json: Map<String, dynamic>.from(json["assets"] as Map),
|
||||||
applicationThemesDirectoryPath: applicationThemesDirectoryPath,
|
applicationThemesDirectoryPath: applicationThemesDirectoryPath,
|
||||||
themeId: json["id"] as String,
|
themeId: json["id"] as String,
|
||||||
)
|
)
|
||||||
: null
|
: null
|
||||||
|
..assetsV3 = version >= 3
|
||||||
|
? ThemeAssetsV3.fromJson(
|
||||||
|
json: Map<String, dynamic>.from(json["assets"] as Map),
|
||||||
|
applicationThemesDirectoryPath: applicationThemesDirectoryPath,
|
||||||
|
themeId: json["id"] as String,
|
||||||
|
)
|
||||||
|
: null
|
||||||
..themeId = json["id"] as String
|
..themeId = json["id"] as String
|
||||||
..name = json["name"] as String
|
..name = json["name"] as String
|
||||||
..brightnessString = json["brightness"] as String
|
..brightnessString = json["brightness"] as String
|
||||||
|
@ -2131,16 +2142,6 @@ class ThemeAssetsV2 implements IThemeAssets {
|
||||||
Map<Coin, String>? _coinSecondaryImages;
|
Map<Coin, String>? _coinSecondaryImages;
|
||||||
late final String coinSecondaryImagesString;
|
late final String coinSecondaryImagesString;
|
||||||
|
|
||||||
@ignore
|
|
||||||
Map<Coin, String>? get coinCardImages =>
|
|
||||||
_coinCardImages ??= parseCoinAssetsString(
|
|
||||||
coinCardImagesString!,
|
|
||||||
placeHolder: coinPlaceholder,
|
|
||||||
);
|
|
||||||
@ignore
|
|
||||||
Map<Coin, String>? _coinCardImages;
|
|
||||||
late final String? coinCardImagesString;
|
|
||||||
|
|
||||||
ThemeAssetsV2();
|
ThemeAssetsV2();
|
||||||
|
|
||||||
factory ThemeAssetsV2.fromJson({
|
factory ThemeAssetsV2.fromJson({
|
||||||
|
@ -2199,11 +2200,6 @@ class ThemeAssetsV2 implements IThemeAssets {
|
||||||
"$applicationThemesDirectoryPath/$themeId/assets",
|
"$applicationThemesDirectoryPath/$themeId/assets",
|
||||||
Map<String, dynamic>.from(json["coins"]["secondaries"] as Map),
|
Map<String, dynamic>.from(json["coins"]["secondaries"] as Map),
|
||||||
)
|
)
|
||||||
..coinCardImagesString = json["coins"]["cards"] is Map
|
|
||||||
? createCoinAssetsString(
|
|
||||||
"$applicationThemesDirectoryPath/$themeId/assets",
|
|
||||||
Map<String, dynamic>.from(json["coins"]["cards"] as Map),
|
|
||||||
) : null
|
|
||||||
..loadingGif = json["loading_gif"] is String
|
..loadingGif = json["loading_gif"] is String
|
||||||
? "$applicationThemesDirectoryPath/$themeId/assets/${json["loading_gif"] as String}"
|
? "$applicationThemesDirectoryPath/$themeId/assets/${json["loading_gif"] as String}"
|
||||||
: null
|
: null
|
||||||
|
@ -2239,6 +2235,228 @@ class ThemeAssetsV2 implements IThemeAssets {
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'ThemeAssetsV2('
|
return 'ThemeAssetsV2('
|
||||||
|
'bellNew: $bellNew, '
|
||||||
|
'buy: $buy, '
|
||||||
|
'exchange: $exchange, '
|
||||||
|
'personaIncognito: $personaIncognito, '
|
||||||
|
'personaEasy: $personaEasy, '
|
||||||
|
'stack: $stack, '
|
||||||
|
'stackIcon: $stackIcon, '
|
||||||
|
'receive: $receive, '
|
||||||
|
'receivePending: $receivePending, '
|
||||||
|
'receiveCancelled: $receiveCancelled, '
|
||||||
|
'send: $send, '
|
||||||
|
'sendPending: $sendPending, '
|
||||||
|
'sendCancelled: $sendCancelled, '
|
||||||
|
'themeSelector: $themeSelector, '
|
||||||
|
'themePreview: $themePreview, '
|
||||||
|
'txExchange: $txExchange, '
|
||||||
|
'txExchangePending: $txExchangePending, '
|
||||||
|
'txExchangeFailed: $txExchangeFailed, '
|
||||||
|
'loadingGif: $loadingGif, '
|
||||||
|
'background: $background, '
|
||||||
|
'coinPlaceholder: $coinPlaceholder, '
|
||||||
|
'coinIcons: $coinIcons, '
|
||||||
|
'coinImages: $coinImages, '
|
||||||
|
'coinSecondaryImages: $coinSecondaryImages, '
|
||||||
|
')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Embedded(inheritance: false)
|
||||||
|
class ThemeAssetsV3 implements IThemeAssets {
|
||||||
|
@override
|
||||||
|
late final String bellNew;
|
||||||
|
@override
|
||||||
|
late final String buy;
|
||||||
|
@override
|
||||||
|
late final String exchange;
|
||||||
|
@override
|
||||||
|
late final String personaIncognito;
|
||||||
|
@override
|
||||||
|
late final String personaEasy;
|
||||||
|
@override
|
||||||
|
late final String stack;
|
||||||
|
@override
|
||||||
|
late final String stackIcon;
|
||||||
|
@override
|
||||||
|
late final String receive;
|
||||||
|
@override
|
||||||
|
late final String receivePending;
|
||||||
|
@override
|
||||||
|
late final String receiveCancelled;
|
||||||
|
@override
|
||||||
|
late final String send;
|
||||||
|
@override
|
||||||
|
late final String sendPending;
|
||||||
|
@override
|
||||||
|
late final String sendCancelled;
|
||||||
|
@override
|
||||||
|
late final String themeSelector;
|
||||||
|
@override
|
||||||
|
late final String themePreview;
|
||||||
|
@override
|
||||||
|
late final String txExchange;
|
||||||
|
@override
|
||||||
|
late final String txExchangePending;
|
||||||
|
@override
|
||||||
|
late final String txExchangeFailed;
|
||||||
|
@override
|
||||||
|
late final String? loadingGif;
|
||||||
|
@override
|
||||||
|
late final String? background;
|
||||||
|
|
||||||
|
late final String coinPlaceholder;
|
||||||
|
|
||||||
|
// Added some future proof params in case we want to add anything else
|
||||||
|
// This should provide some buffer in stead of creating assetsV4 etc
|
||||||
|
@Name("otherStringParam1")
|
||||||
|
late final String? dummy1;
|
||||||
|
@Name("otherStringParam2")
|
||||||
|
late final String? dummy2;
|
||||||
|
@Name("otherStringParam3")
|
||||||
|
late final String? dummy3;
|
||||||
|
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String> get coinIcons => _coinIcons ??= parseCoinAssetsString(
|
||||||
|
coinIconsString,
|
||||||
|
placeHolder: coinPlaceholder,
|
||||||
|
);
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String>? _coinIcons;
|
||||||
|
late final String coinIconsString;
|
||||||
|
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String> get coinImages => _coinImages ??= parseCoinAssetsString(
|
||||||
|
coinImagesString,
|
||||||
|
placeHolder: coinPlaceholder,
|
||||||
|
);
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String>? _coinImages;
|
||||||
|
late final String coinImagesString;
|
||||||
|
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String> get coinSecondaryImages =>
|
||||||
|
_coinSecondaryImages ??= parseCoinAssetsString(
|
||||||
|
coinSecondaryImagesString,
|
||||||
|
placeHolder: coinPlaceholder,
|
||||||
|
);
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String>? _coinSecondaryImages;
|
||||||
|
late final String coinSecondaryImagesString;
|
||||||
|
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String>? get coinCardImages =>
|
||||||
|
_coinCardImages ??= parseCoinAssetsString(
|
||||||
|
coinCardImagesString!,
|
||||||
|
placeHolder: coinPlaceholder,
|
||||||
|
);
|
||||||
|
@ignore
|
||||||
|
Map<Coin, String>? _coinCardImages;
|
||||||
|
late final String? coinCardImagesString;
|
||||||
|
|
||||||
|
ThemeAssetsV3();
|
||||||
|
|
||||||
|
factory ThemeAssetsV3.fromJson({
|
||||||
|
required Map<String, dynamic> json,
|
||||||
|
required String applicationThemesDirectoryPath,
|
||||||
|
required String themeId,
|
||||||
|
}) {
|
||||||
|
return ThemeAssetsV3()
|
||||||
|
..bellNew =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["bell_new"] as String}"
|
||||||
|
..buy =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["buy"] as String}"
|
||||||
|
..exchange =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["exchange"] as String}"
|
||||||
|
..personaIncognito =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["persona_incognito"] as String}"
|
||||||
|
..personaEasy =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["persona_easy"] as String}"
|
||||||
|
..stack =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["stack"] as String}"
|
||||||
|
..stackIcon =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["stack_icon"] as String}"
|
||||||
|
..receive =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["receive"] as String}"
|
||||||
|
..receivePending =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["receive_pending"] as String}"
|
||||||
|
..receiveCancelled =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["receive_cancelled"] as String}"
|
||||||
|
..send =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["send"] as String}"
|
||||||
|
..sendPending =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["send_pending"] as String}"
|
||||||
|
..sendCancelled =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["send_cancelled"] as String}"
|
||||||
|
..themeSelector =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["theme_selector"] as String}"
|
||||||
|
..themePreview =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["theme_preview"] as String}"
|
||||||
|
..txExchange =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["tx_exchange"] as String}"
|
||||||
|
..txExchangePending =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["tx_exchange_pending"] as String}"
|
||||||
|
..txExchangeFailed =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["tx_exchange_failed"] as String}"
|
||||||
|
..coinPlaceholder =
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets/${json["coin_placeholder"] as String}"
|
||||||
|
..coinIconsString = createCoinAssetsString(
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets",
|
||||||
|
Map<String, dynamic>.from(json["coins"]["icons"] as Map),
|
||||||
|
)
|
||||||
|
..coinImagesString = createCoinAssetsString(
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets",
|
||||||
|
Map<String, dynamic>.from(json["coins"]["images"] as Map),
|
||||||
|
)
|
||||||
|
..coinSecondaryImagesString = createCoinAssetsString(
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets",
|
||||||
|
Map<String, dynamic>.from(json["coins"]["secondaries"] as Map),
|
||||||
|
)
|
||||||
|
..coinCardImagesString = json["coins"]["cards"] is Map
|
||||||
|
? createCoinAssetsString(
|
||||||
|
"$applicationThemesDirectoryPath/$themeId/assets",
|
||||||
|
Map<String, dynamic>.from(json["coins"]["cards"] as Map),
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
..loadingGif = json["loading_gif"] is String
|
||||||
|
? "$applicationThemesDirectoryPath/$themeId/assets/${json["loading_gif"] as String}"
|
||||||
|
: null
|
||||||
|
..background = json["background"] is String
|
||||||
|
? "$applicationThemesDirectoryPath/$themeId/assets/${json["background"] as String}"
|
||||||
|
: null
|
||||||
|
..dummy1 = null
|
||||||
|
..dummy2 = null
|
||||||
|
..dummy3 = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String createCoinAssetsString(String path, Map<String, dynamic> json) {
|
||||||
|
final Map<String, dynamic> map = {};
|
||||||
|
for (final entry in json.entries) {
|
||||||
|
map[entry.key] = "$path/${entry.value as String}";
|
||||||
|
}
|
||||||
|
return jsonEncode(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<Coin, String> parseCoinAssetsString(
|
||||||
|
String jsonString, {
|
||||||
|
required String placeHolder,
|
||||||
|
}) {
|
||||||
|
final json = jsonDecode(jsonString) as Map;
|
||||||
|
final map = Map<String, dynamic>.from(json);
|
||||||
|
|
||||||
|
final Map<Coin, String> result = {};
|
||||||
|
|
||||||
|
for (final coin in Coin.values) {
|
||||||
|
result[coin] = map[coin.name] as String? ?? placeHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ThemeAssetsV3('
|
||||||
'bellNew: $bellNew, '
|
'bellNew: $bellNew, '
|
||||||
'buy: $buy, '
|
'buy: $buy, '
|
||||||
'exchange: $exchange, '
|
'exchange: $exchange, '
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -16,9 +16,9 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
final coinCardProvider = Provider.family<String?, Coin>((ref, coin) {
|
final coinCardProvider = Provider.family<String?, Coin>((ref, coin) {
|
||||||
final assets = ref.watch(themeAssetsProvider);
|
final assets = ref.watch(themeAssetsProvider);
|
||||||
|
|
||||||
if (assets is ThemeAssets) {
|
if (assets is ThemeAssetsV3) {
|
||||||
return null;
|
return assets.coinCardImages?[coin.mainNetVersion];
|
||||||
} else {
|
} else {
|
||||||
return (assets as ThemeAssetsV2?)?.coinCardImages?[coin.mainNetVersion];
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -50,7 +50,9 @@ final coinIconProvider = Provider.family<String, Coin>((ref, coin) {
|
||||||
default:
|
default:
|
||||||
return assets.bitcoin;
|
return assets.bitcoin;
|
||||||
}
|
}
|
||||||
|
} else if (assets is ThemeAssetsV2) {
|
||||||
|
return (assets).coinIcons[coin.mainNetVersion]!;
|
||||||
} else {
|
} else {
|
||||||
return (assets as ThemeAssetsV2).coinIcons[coin.mainNetVersion]!;
|
return (assets as ThemeAssetsV3).coinIcons[coin.mainNetVersion]!;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -52,10 +52,12 @@ final coinImageProvider = Provider.family<String, Coin>((ref, coin) {
|
||||||
case Coin.ethereum:
|
case Coin.ethereum:
|
||||||
return assets.ethereumImage;
|
return assets.ethereumImage;
|
||||||
default:
|
default:
|
||||||
return assets.bitcoinImage;
|
return assets.stackIcon;
|
||||||
}
|
}
|
||||||
|
} else if (assets is ThemeAssetsV2) {
|
||||||
|
return (assets).coinImages[coin.mainNetVersion]!;
|
||||||
} else {
|
} else {
|
||||||
return (assets as ThemeAssetsV2).coinImages[coin.mainNetVersion]!;
|
return (assets as ThemeAssetsV3).coinImages[coin.mainNetVersion]!;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -99,9 +101,11 @@ final coinImageSecondaryProvider = Provider.family<String, Coin>((ref, coin) {
|
||||||
return assets.ethereumImageSecondary;
|
return assets.ethereumImageSecondary;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return assets.ethereumImageSecondary;
|
return assets.stackIcon;
|
||||||
}
|
}
|
||||||
|
} else if (assets is ThemeAssetsV2) {
|
||||||
|
return (assets).coinSecondaryImages[coin.mainNetVersion]!;
|
||||||
} else {
|
} else {
|
||||||
return (assets as ThemeAssetsV2).coinSecondaryImages[coin.mainNetVersion]!;
|
return (assets as ThemeAssetsV3).coinSecondaryImages[coin.mainNetVersion]!;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue