-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* copy address and back button fixes * Some minor changes * Remove local.properties from repository * Save Account Info * rename datastore * remove unused vars --------- Co-authored-by: Thomas <[email protected]>
- Loading branch information
Showing
6 changed files
with
95 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
wallet_app/app/src/main/java/com/example/walletapp/datastore/WalletStoreModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.walletapp.datastore | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class WalletStoreModule(private val context: Context) { | ||
companion object { | ||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore("wallet_prefs") | ||
private val HAS_ACCOUNT = booleanPreferencesKey("has_account") | ||
private val ACCOUNT_NAME = stringPreferencesKey("acc_name") | ||
private val PRIVATE_KEY = stringPreferencesKey("private_key") | ||
} | ||
|
||
val hasAccount: Flow<Boolean> = context.dataStore.data.map { preferences -> | ||
preferences[HAS_ACCOUNT] ?: false | ||
} | ||
|
||
suspend fun setHasAccount(hasAccount: Boolean) { | ||
context.dataStore.edit { preferences -> | ||
preferences[HAS_ACCOUNT] = hasAccount | ||
} | ||
} | ||
val accName: Flow<String> = context.dataStore.data.map { preferences -> | ||
preferences[ACCOUNT_NAME] ?: "" | ||
} | ||
|
||
suspend fun setAccountName(accName: String) { | ||
context.dataStore.edit { preferences -> | ||
preferences[ACCOUNT_NAME] = accName | ||
} | ||
} | ||
val privateKey: Flow<String> = context.dataStore.data.map { preferences -> | ||
preferences[PRIVATE_KEY] ?: "" | ||
} | ||
|
||
suspend fun setPrivateKey(privateKey: String) { | ||
context.dataStore.edit { preferences -> | ||
preferences[PRIVATE_KEY] = privateKey | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters