Skip to content

Commit

Permalink
more routes
Browse files Browse the repository at this point in the history
  • Loading branch information
trbutler4 committed Oct 18, 2024
1 parent b72930f commit 568d33d
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ fun WalletApp() {
}

composable<Wallet> {
WalletScreen()
WalletScreen(
onNewTokenPress = { navController.navigate( route = AddToken ) },
onReceivePress = { navController.navigate( route = Receive ) },
onSendPress = { navController.navigate( route = Send ) }
)
}
composable<AddToken> {
AddTokenScreen()
AddTokenScreen(
onConfirm = { navController.navigateUp() }
)
}

composable<Send> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,77 @@ import androidx.core.graphics.toColorInt
import com.example.walletapp.R

@Composable
fun AddTokenScreen() {
fun AddTokenScreen(onConfirm: () -> Unit) {
Surface(modifier = Modifier.fillMaxSize()) {
AddTokenScreenView(modifier = Modifier.padding(10.dp))
val contactAddress = rememberSaveable { mutableStateOf("") }
val name = rememberSaveable { mutableStateOf("") }
val symbol = rememberSaveable { mutableStateOf("") }
val decimals = rememberSaveable { mutableStateOf("") }

Column(
modifier = Modifier
.fillMaxSize()
.background(Color("#0C0C4F".toColorInt()))
.padding(horizontal = 16.dp, vertical = 24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Top
) {
Text(
text = "Add Token",
fontFamily = FontFamily(Font(R.font.publicsans_bold)),
color = Color.White,
fontSize = 28.sp
)

Spacer(modifier = Modifier.height(40.dp))

Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
SimpleTextField(
value = contactAddress.value,
onValueChange = { contactAddress.value = it },
label = "Contact Address",
placeholder = "0x123"
)
Spacer(modifier = Modifier.height(16.dp))
SimpleTextField(
value = name.value,
onValueChange = { name.value = it },
label = "Name",
placeholder = "Name"
)
Spacer(modifier = Modifier.height(16.dp))
SimpleTextField(
value = symbol.value,
onValueChange = { symbol.value = it },
label = "Symbol",
placeholder = "TOK"
)
Spacer(modifier = Modifier.height(16.dp))
SimpleTextField(
value = decimals.value,
onValueChange = { decimals.value = it },
label = "Decimals",
placeholder = "18"
)
}

Spacer(modifier = Modifier.weight(1f))

// TODO: handle saving the token data
Button(
onClick = onConfirm,
colors = ButtonDefaults.buttonColors(backgroundColor = Color("#1B1B76".toColorInt())),
modifier = Modifier
.fillMaxWidth()
.padding(start = 30.dp, end = 30.dp)
) {
Text(text = "Confirm", color = Color.White)
}
}
}
}

Expand Down Expand Up @@ -74,75 +142,3 @@ fun SimpleTextField(
}
}

@Composable
fun AddTokenScreenView(modifier: Modifier) {
val contactAddress = rememberSaveable { mutableStateOf("") }
val name = rememberSaveable { mutableStateOf("") }
val symbol = rememberSaveable { mutableStateOf("") }
val decimals = rememberSaveable { mutableStateOf("") }

Column(
modifier = Modifier
.fillMaxSize()
.background(Color("#0C0C4F".toColorInt()))
.padding(horizontal = 16.dp, vertical = 24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Top
) {
Text(
text = "Add Token",
fontFamily = FontFamily(Font(R.font.publicsans_bold)),
color = Color.White,
fontSize = 28.sp
)

Spacer(modifier = Modifier.height(40.dp))

Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
SimpleTextField(
value = contactAddress.value,
onValueChange = { contactAddress.value = it },
label = "Contact Address",
placeholder = "0x123"
)
Spacer(modifier = Modifier.height(16.dp))
SimpleTextField(
value = name.value,
onValueChange = { name.value = it },
label = "Name",
placeholder = "Name"
)
Spacer(modifier = Modifier.height(16.dp))
SimpleTextField(
value = symbol.value,
onValueChange = { symbol.value = it },
label = "Symbol",
placeholder = "TOK"
)
Spacer(modifier = Modifier.height(16.dp))
SimpleTextField(
value = decimals.value,
onValueChange = { decimals.value = it },
label = "Decimals",
placeholder = "18"
)
}

Spacer(modifier = Modifier.weight(1f))

Button(
onClick = { /* Handle confirm action */ },
colors = ButtonDefaults.buttonColors(backgroundColor = Color("#1B1B76".toColorInt())),
modifier = Modifier
.fillMaxWidth()
.padding(start = 30.dp, end = 30.dp)
) {
Text(text = "Confirm", color = Color.White)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,33 @@ import com.example.walletapp.BuildConfig
import com.example.walletapp.R
import com.example.walletapp.utils.StarknetClient
import com.example.walletapp.utils.toDoubleWithTwoDecimal
import com.example.walletapp.utils.weiToEther
import com.swmansion.starknet.data.types.Felt
import com.swmansion.starknet.provider.exceptions.RpcRequestFailedException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext


@Composable
fun WalletScreen() {
fun WalletScreen(
onNewTokenPress: () -> Unit,
onSendPress: () -> Unit,
onReceivePress: () -> Unit
) {
Surface(modifier = Modifier.fillMaxSize()) {
Wallet(
modifier = Modifier.padding(10.dp),
onNewTokenPress = onNewTokenPress,
onSendPress = onSendPress,
onReceivePress = onReceivePress
)
}
}



@Composable
fun Wallet(modifier: Modifier) {
fun Wallet(modifier: Modifier, onNewTokenPress: () -> Unit, onReceivePress: () -> Unit, onSendPress: () -> Unit) {
val networkList = listOf("Starknet Mainnet", "Test Networks")
var selectedNetworkIndex by remember { mutableStateOf(0) }
val context = (LocalContext.current as Activity)
Expand All @@ -95,7 +103,7 @@ fun Wallet(modifier: Modifier) {
// Get the balance of the account
val getBalance = starknetClient.getEthBalance(accountAddress)
withContext(Dispatchers.Main) {
balance = starknetClient.weiToEther(getBalance).toDoubleWithTwoDecimal()
balance = weiToEther(getBalance).toDoubleWithTwoDecimal()
}
} catch (e: RpcRequestFailedException) {
withContext(Dispatchers.Main) { Toast.makeText(context, "${e.code}: ${e.message}", Toast.LENGTH_LONG).show() }
Expand Down Expand Up @@ -184,7 +192,7 @@ fun Wallet(modifier: Modifier) {
fontSize = 14.sp,
modifier = Modifier
.clickable {
/* TODO */
onNewTokenPress()
}
.background(Color.Transparent)
.padding(10.dp)
Expand All @@ -198,9 +206,7 @@ fun Wallet(modifier: Modifier) {
horizontalArrangement = Arrangement.SpaceEvenly
) {
Button(
onClick = {
/* TODO: receiver screen */
},
onClick = onReceivePress,
colors = ButtonDefaults.buttonColors(backgroundColor = Color("#1B1B76".toColorInt())),
shape = RoundedCornerShape(15.dp),
) {
Expand All @@ -211,9 +217,7 @@ fun Wallet(modifier: Modifier) {
)
}
Button(
onClick = {
/* TODO: sender screen */
},
onClick = onSendPress,

colors = ButtonDefaults.buttonColors(backgroundColor = Color("#1B1B76".toColorInt())),
shape = RoundedCornerShape(15.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.graphics.toColorInt
import com.example.walletapp.R
import com.example.walletapp.ui.Onboarding
import com.example.walletapp.ui.components.StarknetLogo
import com.example.walletapp.ui.components.TransparentButton
import com.example.walletapp.ui.theme.WalletappTheme
import com.example.walletapp.ui.theme.WhiteFlare


@Composable
Expand All @@ -43,9 +42,10 @@ fun OnboardingScreen (
.padding(20.dp)
) {
Text(
text = "Starknet Wallet",
text = "Get Started",
fontFamily = FontFamily(Font(R.font.inter_regular)),
fontSize = 28.sp,
color = WhiteFlare,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(top = 70.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.compose.ui.unit.sp
import androidx.core.graphics.toColorInt
import com.example.walletapp.R


@Composable
fun ReceiveScreen(modifier: Modifier) {
val clipboard: ClipboardManager = LocalClipboardManager.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,4 @@ class StarknetClient(private val rpcUrl: String) {
// TODO(#24)
}

fun weiToEther(wei: Uint256): BigDecimal {
val weiInEther = BigDecimal("1000000000000000000") // 10^18
return BigDecimal(wei.value.toString()).divide(weiInEther)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.walletapp.utils

import com.swmansion.starknet.data.types.Uint256
import java.math.BigDecimal
import java.text.DecimalFormat

Expand All @@ -12,4 +13,9 @@ fun Double.toDoubleWithTwoDecimal(): String {
val decimalFormat = DecimalFormat("#.00")
val formattedValue = decimalFormat.format(this)
return if (this < 1) "0$formattedValue" else formattedValue
}
}

fun weiToEther(wei: Uint256): BigDecimal {
val weiInEther = BigDecimal("1000000000000000000") // 10^18
return BigDecimal(wei.value.toString()).divide(weiInEther)
}

0 comments on commit 568d33d

Please sign in to comment.