From 7109ad6a46bd187f29eebbc1f45499870e2895d5 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 21 Oct 2024 19:02:04 -0500 Subject: [PATCH] adding todos/structure for ODHack issues --- .../example/walletapp/ui/account/CoinViewModel.kt | 1 - .../example/walletapp/ui/account/WalletScreen.kt | 4 ++-- .../com/example/walletapp/utils/StarknetClient.kt | 14 +++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/wallet_app/app/src/main/java/com/example/walletapp/ui/account/CoinViewModel.kt b/wallet_app/app/src/main/java/com/example/walletapp/ui/account/CoinViewModel.kt index 5da80a20..d88ba66f 100644 --- a/wallet_app/app/src/main/java/com/example/walletapp/ui/account/CoinViewModel.kt +++ b/wallet_app/app/src/main/java/com/example/walletapp/ui/account/CoinViewModel.kt @@ -21,7 +21,6 @@ class CoinViewModel : ViewModel() { vsCurrencies: String) { viewModelScope.launch { try { - // Fetch prices for starknet and bitcoin in USD val response = repository.getTokenPrices(ids,vsCurrencies) if (response.isSuccessful) { response.body()?.let { priceMap -> diff --git a/wallet_app/app/src/main/java/com/example/walletapp/ui/account/WalletScreen.kt b/wallet_app/app/src/main/java/com/example/walletapp/ui/account/WalletScreen.kt index f8004a0b..34dc73d2 100644 --- a/wallet_app/app/src/main/java/com/example/walletapp/ui/account/WalletScreen.kt +++ b/wallet_app/app/src/main/java/com/example/walletapp/ui/account/WalletScreen.kt @@ -94,14 +94,14 @@ fun Wallet(modifier: Modifier, onNewTokenPress: () -> Unit, onReceivePress: () - val prices by coinViewModel.prices val errorMessage by coinViewModel.errorMessage - // TODO: + // TODO(#106): use the accounts stored tokens instead of hardcoding LaunchedEffect(Unit) { coinViewModel.getTokenPrices(ids = "starknet,ethereum", vsCurrencies = "usd") } LaunchedEffect (Unit){ + // TODO(#107): fetch all token balances try { - // Get the balance of the account val getBalance = starknetClient.getEthBalance(accountAddress) withContext(Dispatchers.Main) { balance = weiToEther(getBalance).toDoubleWithTwoDecimal() diff --git a/wallet_app/app/src/main/java/com/example/walletapp/utils/StarknetClient.kt b/wallet_app/app/src/main/java/com/example/walletapp/utils/StarknetClient.kt index 99eb1c4d..c32ac227 100644 --- a/wallet_app/app/src/main/java/com/example/walletapp/utils/StarknetClient.kt +++ b/wallet_app/app/src/main/java/com/example/walletapp/utils/StarknetClient.kt @@ -7,7 +7,9 @@ import com.swmansion.starknet.data.types.Felt import com.swmansion.starknet.data.types.Uint256 import com.swmansion.starknet.provider.rpc.JsonRpcProvider import com.swmansion.starknet.signer.StarkCurveSigner +import com.swmansion.starknet.account.Account import kotlinx.coroutines.future.await + import java.math.BigDecimal const val ETH_ERC20_ADDRESS = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" @@ -35,9 +37,12 @@ class StarknetClient(private val rpcUrl: String) { cairoVersion = Felt.ONE, ) - // TODO: deploy account + // TODO(#99): add account deployment logic + } + // TODO(#107): change name to getBalance, support getting balance for any token + // follow example: https://github.com/software-mansion/starknet-jvm/blob/main/androiddemo/src/main/java/com/example/androiddemo/MainActivity.kt suspend fun getEthBalance(accountAddress: Felt): Uint256 { val erc20ContractAddress = Felt.fromHex(ETH_ERC20_ADDRESS) @@ -66,8 +71,11 @@ class StarknetClient(private val rpcUrl: String) { ) } - suspend fun sendERC20() { - // TODO(#24) + suspend fun transferFunds(account: Account, toAddress: Felt, amount: Uint256) { + // TODO(#102): add logic to transfer funds here + // follow the example: https://github.com/software-mansion/starknet-jvm/blob/main/androiddemo/src/main/java/com/example/androiddemo/MainActivity.kt } + + }