Skip to content

Commit 83267c5

Browse files
committed
feat: source component
1 parent 5b1cb09 commit 83267c5

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

app/src/main/java/to/bitkit/data/dto/price/PriceDTO.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ import kotlinx.serialization.Serializable
44

55
@Serializable
66
data class PriceDTO(
7-
val widgets: List<PriceWidgetData>
7+
val widgets: List<PriceWidgetData>,
8+
val source: String
89
)

app/src/main/java/to/bitkit/data/widgets/PriceService.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ class PriceService @Inject constructor(
3737

3838
override val widgetType = WidgetType.PRICE
3939
override val refreshInterval = 1.minutes
40+
private val sourceLabel = "Bitfinex.com"
4041

4142
override suspend fun fetchData(): Result<PriceDTO> = runCatching {
4243
val period = widgetsStore.data.first().pricePreferences.period ?: GraphPeriod.ONE_DAY
4344

4445
val widgets = TradingPair.entries.map { pair ->
4546
fetchPairData(pair = pair, period = period)
4647
}
47-
PriceDTO(widgets)
48+
PriceDTO(widgets = widgets, source = sourceLabel)
4849
}.onFailure {
4950
Logger.warn(e = it, msg = "Failed to fetch price data", context = TAG)
5051
}
@@ -54,9 +55,10 @@ class PriceService @Inject constructor(
5455
GraphPeriod.entries.map { period ->
5556
async {
5657
PriceDTO(
57-
TradingPair.entries.map { pair ->
58+
widgets = TradingPair.entries.map { pair ->
5859
fetchPairData(pair = pair, period = period)
59-
}
60+
},
61+
source = sourceLabel
6062
)
6163
}
6264
}.awaitAll()

app/src/main/java/to/bitkit/ui/screens/widgets/price/PriceCard.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import to.bitkit.data.dto.price.PriceWidgetData
4545
import to.bitkit.data.dto.price.TradingPair
4646
import to.bitkit.models.widget.PricePreferences
4747
import to.bitkit.ui.components.BodyMSB
48+
import to.bitkit.ui.components.BodyS
4849
import to.bitkit.ui.components.BodySB
4950
import to.bitkit.ui.components.CaptionB
5051
import to.bitkit.ui.theme.AppThemeSurface
@@ -139,6 +140,28 @@ fun PriceCard(
139140
.testTag("price_card_chart")
140141
)
141142
}
143+
144+
if (pricePreferences.showSource) {
145+
Spacer(modifier = Modifier.height(8.dp))
146+
147+
Row(
148+
modifier = Modifier
149+
.fillMaxWidth()
150+
.testTag("source_row"),
151+
horizontalArrangement = Arrangement.SpaceBetween
152+
) {
153+
CaptionB(
154+
text = stringResource(R.string.widgets__widget__source),
155+
color = Colors.White64,
156+
modifier = Modifier.testTag("source_label")
157+
)
158+
CaptionB(
159+
text = priceDTO.source,
160+
color = Colors.White64,
161+
modifier = Modifier.testTag("source_text")
162+
)
163+
}
164+
}
142165
}
143166
}
144167
}
@@ -221,8 +244,11 @@ private fun FullBlockCardPreview() {
221244
PriceCard(
222245
modifier = Modifier.fillMaxWidth(),
223246
showWidgetTitle = true,
224-
pricePreferences = PricePreferences(),
247+
pricePreferences = PricePreferences(
248+
showSource = true
249+
),
225250
priceDTO = PriceDTO(
251+
source = "Bitfinex.com",
226252
widgets = listOf(
227253
PriceWidgetData(
228254
pair = TradingPair.BTC_USD,

app/src/main/java/to/bitkit/ui/screens/widgets/price/PriceEditScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ fun PriceEditScreen(
5757
onClickPreview = navigatePreview,
5858
allPeriodsUsd = allPeriodsUsd,
5959
priceModel = currentPrice ?: PriceDTO(
60-
widgets = listOf()
60+
widgets = listOf(),
61+
source = ""
6162
),
6263
onClickTradingPair = { pair ->
6364
viewModel.toggleTradingPair(pair = pair)

app/src/main/java/to/bitkit/ui/screens/widgets/price/PricePreviewScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ private fun Preview() {
232232
onClickSave = {},
233233
pricePreferences = PricePreferences(),
234234
priceDTO = PriceDTO(
235+
source = "Bitfinex.com",
235236
widgets = listOf(
236237
PriceWidgetData(
237238
pair = TradingPair.BTC_USD,
@@ -278,6 +279,7 @@ private fun Preview2() {
278279
showSource = true
279280
),
280281
priceDTO = PriceDTO(
282+
source = "Bitfinex.com",
281283
widgets = listOf(
282284
PriceWidgetData(
283285
pair = TradingPair.BTC_USD,

0 commit comments

Comments
 (0)