Skip to content

Commit df5a7fa

Browse files
committed
feat(tokens): add minted date to token info screen
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent ccf351f commit df5a7fa

6 files changed

Lines changed: 55 additions & 7 deletions

File tree

apps/flipcash/core/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,6 @@
431431

432432
<string name="error_title_CashReturnedToWallet">Something Went Wrong</string>
433433
<string name="error_description_CashReturnedToWallet">The cash was returned to your wallet</string>
434+
435+
<string name="label_mintDate">Minted: %1$s</string>
434436
</resources>

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/TokenInfoScreen.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import com.getcode.ui.theme.ButtonState
4747
import com.getcode.ui.theme.CodeButton
4848
import com.getcode.ui.theme.CodeCircularProgressIndicator
4949
import com.getcode.ui.theme.CodeScaffold
50+
import com.getcode.util.format
5051

5152
@Composable
5253
internal fun TokenInfoScreen(viewModel: TokenInfoViewModel) {
@@ -170,7 +171,7 @@ private fun TokenBalance(
170171
Column(
171172
modifier = modifier
172173
.padding(horizontal = CodeTheme.dimens.inset)
173-
.padding(vertical = CodeTheme.dimens.grid.x9,),
174+
.padding(vertical = CodeTheme.dimens.grid.x9),
174175
) {
175176
if (balance == null) {
176177
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
@@ -254,10 +255,32 @@ private fun CurrencyInfoSection(
254255
)
255256
}
256257

258+
state.token?.createdAt?.let { mintDate ->
259+
Text(
260+
modifier = Modifier
261+
.padding(horizontal = CodeTheme.dimens.inset)
262+
.padding(top = CodeTheme.dimens.grid.x1),
263+
text = stringResource(
264+
R.string.label_mintDate,
265+
mintDate.format("MMMM dd, yyyy")
266+
),
267+
style = CodeTheme.typography.textMedium,
268+
color = CodeTheme.colors.textSecondary,
269+
)
270+
}
271+
257272
ExpandableText(
258-
modifier = Modifier.padding(top = CodeTheme.dimens.grid.x1),
273+
modifier = Modifier
274+
.padding(
275+
top = if (state.token?.createdAt == null) {
276+
CodeTheme.dimens.grid.x1
277+
} else {
278+
CodeTheme.dimens.grid.x2
279+
}
280+
),
259281
text = state.token?.description.orEmpty(),
260282
style = CodeTheme.typography.textMedium,
283+
color = CodeTheme.colors.textSecondary,
261284
isExpanded = state.descriptionExpanded,
262285
isExpandable = false,
263286
contentPadding = PaddingValues(horizontal = CodeTheme.dimens.inset)
@@ -311,6 +334,7 @@ private fun PreviewTokenInfo() {
311334
text = LoremIpsum(words = 400).values.joinToString(" "),
312335
contentPadding = PaddingValues(horizontal = 16.dp),
313336
style = CodeTheme.typography.textMedium,
337+
color = CodeTheme.colors.textSecondary,
314338
isExpanded = false,
315339
isExpandable = false,
316340
onToggle = { }

definitions/opencode/protos/src/main/proto/currency/v1/currency_service.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ message Mint {
6565
// can be used for calculating price, market cap, etc. based on the exponential
6666
// bonding curve
6767
LaunchpadMetadata launchpad_metadata = 8;
68+
// Timestamp the currency was created
69+
google.protobuf.Timestamp created_at = 9;
6870
}
6971
message VmMetadata {
7072
// VM address

services/opencode/src/main/kotlin/com/getcode/opencode/internal/domain/mapping/MintMapper.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package com.getcode.opencode.internal.domain.mapping
22

33
import com.codeinc.opencode.gen.currency.v1.CurrencyService
44
import com.codeinc.opencode.gen.currency.v1.launchpadMetadataOrNull
5-
import com.codeinc.opencode.gen.currency.v1.vmMetadataOrNull
65
import com.getcode.opencode.internal.network.extensions.toPublicKey
76
import com.getcode.opencode.mapper.Mapper
87
import com.getcode.opencode.model.financial.MintMetadata
8+
import com.getcode.opencode.model.financial.Token
9+
import com.getcode.opencode.model.financial.usdc
10+
import com.getcode.solana.keys.Mint
911
import javax.inject.Inject
12+
import kotlin.time.Instant
1013

1114
internal class MintMapper @Inject constructor(
1215
private val vmMetadataMapper: VmMetadataMapper,
@@ -19,10 +22,23 @@ internal class MintMapper @Inject constructor(
1922
launchpadMetadataMapper.map(it)
2023
}
2124

25+
// Handle the provided `createdAt` and if it's valid use it, otherwise
26+
// do a mint check against USDC and return a well known mint date for it
27+
// otherwise return null
28+
val mintDate = from.createdAt.seconds.takeIf { it > 0 }
29+
.let { at ->
30+
if (at == null && mint == Mint.usdc) {
31+
Token.usdc.createdAt
32+
} else {
33+
at?.let { Instant.fromEpochMilliseconds(it * 1_000L) }
34+
}
35+
}
36+
2237
return MintMetadata(
2338
address = mint,
2439
decimals = from.decimals,
2540
name = from.name,
41+
createdAt = mintDate,
2642
symbol = from.symbol,
2743
description = from.description,
2844
imageUrl = from.imageUrl,

services/opencode/src/main/kotlin/com/getcode/opencode/model/financial/MintMetadata.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.getcode.opencode.solana.keys.TimelockDerivedAccounts
88
import com.getcode.solana.keys.Mint
99
import com.getcode.solana.keys.PublicKey
1010
import kotlinx.parcelize.Parcelize
11+
import kotlin.time.Instant
1112

1213
data class TokenWithBalance(
1314
val token: Token,
@@ -28,6 +29,7 @@ val MintMetadata.Companion.usdc: Token
2829
name = "USDC",
2930
symbol = "USDC",
3031
description = "",
32+
createdAt = Instant.parse("2018-05-15T05:00:00Z"),
3133
imageUrl = "",
3234
vmMetadata = VmMetadata(
3335
authority = vmAuthority,
@@ -54,15 +56,16 @@ val MintMetadata.Companion.usdc: Token
5456
* @property vmMetadata Available when a VM exists for the given mint, and can be used for deriving
5557
* VM deposit PDAs
5658
* @property launchpadMetadata Available when created by the launchpad via the currency creator program, and
57-
* can be used for calculating price, market cap, etc. based on the exponential
58-
* bonding curve
59+
* can be used for calculating price, market cap, etc. based on the exponential bonding curve
60+
* @property billCustomizations Optional visual customizations for the bill for this token when give/grabbed
5961
*/
6062
@Parcelize
6163
data class MintMetadata(
6264
val address: Mint,
6365
val decimals: Int,
6466
val name: String,
6567
val symbol: String,
68+
val createdAt: Instant?,
6669
val description: String,
6770
val imageUrl: String,
6871
val vmMetadata: VmMetadata,

ui/components/src/main/kotlin/com/getcode/ui/components/text/ExpandableText.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import com.getcode.ui.core.drawWithGradient
3636
fun ExpandableText(
3737
text: String,
3838
style: TextStyle,
39+
color: Color,
3940
isExpanded: Boolean,
4041
modifier: Modifier = Modifier,
4142
textModifier: Modifier = Modifier,
@@ -53,7 +54,7 @@ fun ExpandableText(
5354
.padding(contentPadding),
5455
text = text,
5556
style = style,
56-
color = CodeTheme.colors.textSecondary,
57+
color = color,
5758
)
5859
} else {
5960
Column(Modifier.animateContentSize()) {
@@ -63,7 +64,7 @@ fun ExpandableText(
6364
.padding(contentPadding),
6465
text = text,
6566
style = style,
66-
color = CodeTheme.colors.textSecondary,
67+
color = color,
6768
)
6869
} else {
6970
Box {

0 commit comments

Comments
 (0)