@@ -551,9 +551,10 @@ class MigrationService @Inject constructor(
551551 val widgetsJsonString = root[" widgets" ]?.jsonPrimitive?.content ? : return null
552552
553553 val widgets = json.decodeFromString<RNWidgets >(widgetsJsonString)
554-
555554 val widgetsData = json.parseToJsonElement(widgetsJsonString).jsonObject
556- val widgetOptions = convertRNWidgetPreferences(widgetsData[" widgets" ]?.jsonObject ? : widgetsData)
555+ val widgetOptions = convertRNWidgetPreferences(
556+ widgetsData[" widgets" ]?.jsonObject ? : widgetsData
557+ )
557558
558559 RNWidgetsWithOptions (widgets = widgets, widgetOptions = widgetOptions)
559560 } catch (e: Exception ) {
@@ -884,6 +885,7 @@ class MigrationService @Inject constructor(
884885 " blocks" to WidgetType .BLOCK ,
885886 " weather" to WidgetType .WEATHER ,
886887 " facts" to WidgetType .FACTS ,
888+ " calculator" to WidgetType .CALCULATOR ,
887889 )
888890
889891 val savedWidgets = sortOrder.mapNotNull { widgetName ->
@@ -1502,10 +1504,15 @@ class MigrationService @Inject constructor(
15021504 val result = mutableMapOf<String , ByteArray >()
15031505 if (widgetsDict == null ) return result
15041506
1505- fun getBool (key : String , fallbackKey : String? = null, defaultValue : Boolean = false): Boolean {
1507+ fun getBool (
1508+ source : kotlinx.serialization.json.JsonObject ,
1509+ key : String ,
1510+ fallbackKey : String? = null,
1511+ defaultValue : Boolean = false,
1512+ ): Boolean {
15061513 val keys = if (fallbackKey != null ) listOf (key, fallbackKey) else listOf (key)
15071514 for (k in keys) {
1508- widgetsDict [k]?.let { element ->
1515+ source [k]?.let { element ->
15091516 when {
15101517 element is kotlinx.serialization.json.JsonPrimitive && element.isString -> {
15111518 val str = element.content.lowercase()
@@ -1541,7 +1548,7 @@ class MigrationService @Inject constructor(
15411548 )
15421549 val period = periodMap[rnPeriod] ? : rnPeriod
15431550
1544- val showSource = getBool(" showSource" , defaultValue = false )
1551+ val showSource = getBool(prefs, " showSource" , defaultValue = false )
15451552 val pairsJson = selectedPairs.joinToString(" ," , " [" , " ]" ) { " \" $it \" " }
15461553 val priceOptionsJson =
15471554 """ {"selectedPairs":$pairsJson ,"selectedPeriod":"$period ","showSource":$showSource }"""
@@ -1550,47 +1557,47 @@ class MigrationService @Inject constructor(
15501557
15511558 val weatherPrefs = widgetsDict[" weatherPreferences" ]?.jsonObject
15521559 ? : widgetsDict[" weather" ]?.jsonObject
1553- weatherPrefs?.let {
1560+ weatherPrefs?.let { prefs ->
15541561 val weatherOptions = buildJsonObject {
1555- put(" showStatus" , getBool(" showTitle" , " showStatus" , defaultValue = true ))
1556- put(" showText" , getBool(" showDescription" , " showText" , defaultValue = false ))
1557- put(" showMedian" , getBool(" showCurrentFee" , " showMedian" , defaultValue = false ))
1558- put(" showNextBlockFee" , getBool(" showNextBlockFee" , defaultValue = false ))
1562+ put(" showStatus" , getBool(prefs, " showTitle" , " showStatus" , defaultValue = true ))
1563+ put(" showText" , getBool(prefs, " showDescription" , " showText" , defaultValue = false ))
1564+ put(" showMedian" , getBool(prefs, " showCurrentFee" , " showMedian" , defaultValue = false ))
1565+ put(" showNextBlockFee" , getBool(prefs, " showNextBlockFee" , defaultValue = false ))
15591566 }
15601567 result[" weather" ] = weatherOptions.toString().encodeToByteArray()
15611568 }
15621569
15631570 val newsPrefs = widgetsDict[" headlinePreferences" ]?.jsonObject
15641571 ? : widgetsDict[" headline" ]?.jsonObject
15651572 ? : widgetsDict[" news" ]?.jsonObject
1566- newsPrefs?.let {
1573+ newsPrefs?.let { prefs ->
15671574 val newsOptions = buildJsonObject {
1568- put(" showDate" , getBool(" showDate" , " showTime" , defaultValue = true ))
1569- put(" showTitle" , getBool(" showTitle" , defaultValue = true ))
1570- put(" showSource" , getBool(" showSource" , defaultValue = true ))
1575+ put(" showDate" , getBool(prefs, " showDate" , " showTime" , defaultValue = true ))
1576+ put(" showTitle" , getBool(prefs, " showTitle" , defaultValue = true ))
1577+ put(" showSource" , getBool(prefs, " showSource" , defaultValue = true ))
15711578 }
15721579 result[" news" ] = newsOptions.toString().encodeToByteArray()
15731580 }
15741581
15751582 val blocksPrefs = widgetsDict[" blocksPreferences" ]?.jsonObject
15761583 ? : widgetsDict[" blocks" ]?.jsonObject
1577- blocksPrefs?.let {
1584+ blocksPrefs?.let { prefs ->
15781585 val blocksOptions = buildJsonObject {
1579- put(" height" , getBool(" height" , " showBlock" , defaultValue = true ))
1580- put(" time" , getBool(" time" , " showTime" , defaultValue = true ))
1581- put(" date" , getBool(" date" , " showDate" , defaultValue = true ))
1582- put(" transactionCount" , getBool(" transactionCount" , " showTransactions" , defaultValue = false ))
1583- put(" size" , getBool(" size" , " showSize" , defaultValue = false ))
1584- put(" showSource" , getBool(" showSource" , defaultValue = false ))
1586+ put(" height" , getBool(prefs, " height" , " showBlock" , defaultValue = true ))
1587+ put(" time" , getBool(prefs, " time" , " showTime" , defaultValue = true ))
1588+ put(" date" , getBool(prefs, " date" , " showDate" , defaultValue = true ))
1589+ put(" transactionCount" , getBool(prefs, " transactionCount" , " showTransactions" , defaultValue = false ))
1590+ put(" size" , getBool(prefs, " size" , " showSize" , defaultValue = false ))
1591+ put(" showSource" , getBool(prefs, " showSource" , defaultValue = false ))
15851592 }
15861593 result[" blocks" ] = blocksOptions.toString().encodeToByteArray()
15871594 }
15881595
15891596 val factsPrefs = widgetsDict[" factsPreferences" ]?.jsonObject
15901597 ? : widgetsDict[" facts" ]?.jsonObject
1591- factsPrefs?.let {
1598+ factsPrefs?.let { prefs ->
15921599 val factsOptions = buildJsonObject {
1593- put(" showSource" , getBool(" showSource" , defaultValue = false ))
1600+ put(" showSource" , getBool(prefs, " showSource" , defaultValue = false ))
15941601 }
15951602 result[" facts" ] = factsOptions.toString().encodeToByteArray()
15961603 }
0 commit comments