Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt/spend key #5116

Merged
merged 17 commits into from
Nov 26, 2024
Prev Previous commit
Next Next commit
Update
SeniorZhai committed Nov 24, 2024
commit adc838a08c05d6a558d9d53afb907386c4466718
9 changes: 9 additions & 0 deletions app/src/main/java/one/mixin/android/MixinApplication.kt
Original file line number Diff line number Diff line change
@@ -287,6 +287,15 @@ open class MixinApplication :
}
}

fun reject() {
val entryPoint =
EntryPointAccessors.fromApplication(
this@MixinApplication,
AppEntryPoint::class.java,
)
entryPoint.inject(this@MixinApplication)
}

private fun clearData(sessionId: String?) {
val jobManager = getJobManager()
jobManager.cancelAllJob()
Original file line number Diff line number Diff line change
@@ -132,6 +132,7 @@ abstract class PinCodeFragment(
RestoreActivity.show(requireContext())
}
}
MixinApplication.get().reject()
activity?.finish()
}

Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import one.mixin.android.Constants.Account.PREF_LOGIN_VERIFY
import one.mixin.android.Constants.Account.PREF_TRIED_UPDATE_KEY
import one.mixin.android.Constants.DEVICE_ID
import one.mixin.android.Constants.TEAM_BOT_ID
import one.mixin.android.Constants.TEAM_BOT_NAME
import one.mixin.android.Constants.TEAM_MIXIN_USER_ID
@@ -28,6 +29,7 @@ import one.mixin.android.databinding.FragmentLoadingBinding
import one.mixin.android.extension.base64Encode
import one.mixin.android.extension.decodeBase64
import one.mixin.android.extension.defaultSharedPreferences
import one.mixin.android.extension.getStringDeviceId
import one.mixin.android.extension.putBoolean
import one.mixin.android.extension.viewDestroyed
import one.mixin.android.job.InitializeJob
@@ -36,6 +38,10 @@ import one.mixin.android.session.Session
import one.mixin.android.session.decryptPinToken
import one.mixin.android.ui.common.BaseFragment
import one.mixin.android.ui.home.MainActivity
import one.mixin.android.ui.tip.TipActivity
import one.mixin.android.ui.tip.TipBundle
import one.mixin.android.ui.tip.TipType
import one.mixin.android.ui.tip.TryConnecting
import one.mixin.android.util.ErrorHandler
import one.mixin.android.util.ErrorHandler.Companion.FORBIDDEN
import one.mixin.android.util.reportException
@@ -103,8 +109,14 @@ class LoadingFragment : BaseFragment(R.layout.fragment_loading) {

if (Session.hasSafe()) {
defaultSharedPreferences.putBoolean(PREF_LOGIN_VERIFY, true)
MainActivity.show(requireContext())
} else {
var deviceId = defaultSharedPreferences.getString(DEVICE_ID, null)
if (deviceId == null) {
deviceId = requireActivity().getStringDeviceId()
}
TipActivity.show(requireActivity(), TipBundle(TipType.Create, deviceId, TryConnecting, null))
}
MainActivity.show(requireContext())
activity?.finish()
}

Original file line number Diff line number Diff line change
@@ -289,8 +289,6 @@ class MnemonicPhraseFragment : BaseFragment(R.layout.fragment_compose) {
Session.storePinToken(pinToken.base64Encode())
Session.storeAccount(account)
defaultSharedPreferences.putString(DEVICE_ID, requireContext().getStringDeviceId())
MixinApplication.get().isOnline.set(true)

when {
account.fullName.isNullOrBlank() -> {
mobileViewModel.upsertUser(account.toUser())
@@ -302,6 +300,7 @@ class MnemonicPhraseFragment : BaseFragment(R.layout.fragment_compose) {
}
}
mobileViewModel.updateMnemonicPhraseState(MnemonicPhraseState.Success)
MixinApplication.get().reject()
activity?.finish()
} else {
if (r != null) {
Original file line number Diff line number Diff line change
@@ -91,10 +91,10 @@ class SetupNameFragment : BaseFragment(R.layout.fragment_setup_name) {
nameEt.addTextChangedListener(mWatcher)
nameCover.isClickable = true

nameEt.post {
nameEt.postDelayed({
nameEt.requestFocus()
nameEt.showKeyboard()
}
}, 200)
}
}

Original file line number Diff line number Diff line change
@@ -310,13 +310,14 @@ fun MnemonicPhraseInput(
.height(48.dp),
enabled = state == MnemonicState.Display || inputs.all { it.isNotEmpty() },
onClick = {
val words = inputs.map { it.trim() }
when (state) {
MnemonicState.Input -> onComplete.invoke(inputs)
MnemonicState.Input -> onComplete.invoke(words)
MnemonicState.Verify -> {
coroutineScope.launch {
runCatching {
loading = true
if (mnemonicList != inputs) {
if (mnemonicList != words) {
errorInfo = context.getString(R.string.invalid_mnemonic_phrase)
} else {
val selfId = Session.getAccountId()!!
@@ -340,7 +341,7 @@ fun MnemonicPhraseInput(
}
}.onSuccess {
loading = false
if (errorInfo.isBlank()) onComplete.invoke(inputs)
if (errorInfo.isBlank()) onComplete.invoke(words)
}.onFailure {
errorInfo = it.message ?: ""
loading = false
@@ -383,7 +384,8 @@ fun MnemonicPhraseInput(
MnemonicState.Input -> R.string.Confirm
MnemonicState.Verify -> R.string.Complete
}
), color = Color.White
), color = Color.White,
fontWeight = W500,
)
}
}
Original file line number Diff line number Diff line change
@@ -34,9 +34,11 @@ class AddPhoneBeforeFragment : BaseFragment(R.layout.fragment_compose) {
super.onViewCreated(view, savedInstanceState)
binding.titleView.isVisible = false
binding.compose.setContent {
AddPhoneBeforePage(Session.hasPhone()) {
AddPhoneBeforePage(Session.hasPhone(), {
requireActivity().onBackPressedDispatcher.onBackPressed()
}, {
navTo(VerifyFragment.newInstance(VerifyFragment.FROM_PHONE), VerifyFragment.TAG)
}
})
}
}
}
Original file line number Diff line number Diff line change
@@ -33,9 +33,11 @@ class AddPhoneFragment : BaseFragment(R.layout.fragment_compose) {
super.onViewCreated(view, savedInstanceState)
binding.titleView.isVisible = false
binding.compose.setContent {
AddPhonePage(Session.hasPhone()) {
AddPhonePage(Session.hasPhone(), {
requireActivity().onBackPressedDispatcher.onBackPressed()
}, {
navTo(AddPhoneBeforeFragment.newInstance(), AddPhoneBeforeFragment.TAG)
}
})
}
}
}
Original file line number Diff line number Diff line change
@@ -23,14 +23,15 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import one.mixin.android.Constants
import one.mixin.android.R
import one.mixin.android.compose.MixinBackButton
import one.mixin.android.compose.MixinTopAppBar
import one.mixin.android.compose.theme.MixinAppTheme
import one.mixin.android.extension.openUrl
import one.mixin.android.ui.landing.components.HighlightedTextWithClick
import one.mixin.android.ui.landing.components.NumberedText

@Composable
fun AddPhoneBeforePage(hasPhone: Boolean, next: () -> Unit) {
fun AddPhoneBeforePage(hasPhone: Boolean, pop: () -> Unit, next: () -> Unit) {
val context = LocalContext.current
MixinAppTheme {
Column {
@@ -48,6 +49,15 @@ fun AddPhoneBeforePage(hasPhone: Boolean, next: () -> Unit) {
)
}
},
navigationIcon = {
IconButton(onClick = { pop() }) {
Icon(
painter = painterResource(id = R.drawable.ic_back),
contentDescription = null,
tint = MixinAppTheme.colors.icon,
)
}
}
)
Column(modifier = Modifier.padding(horizontal = 20.dp)) {
Spacer(modifier = Modifier.height(50.dp))
@@ -117,7 +127,7 @@ fun AddPhoneBeforePage(hasPhone: Boolean, next: () -> Unit) {
),
) {
Text(
text = stringResource(R.string.Start),
text = stringResource(R.string.Continue),
color = Color.White
)
}
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@@ -27,7 +28,7 @@ import one.mixin.android.session.Session
import one.mixin.android.ui.landing.components.HighlightedTextWithClick

@Composable
fun AddPhonePage(hasPhone: Boolean, next: () -> Unit) {
fun AddPhonePage(hasPhone: Boolean, pop: () -> Unit, next: () -> Unit) {
val context = LocalContext.current
MixinAppTheme {
Column {
@@ -38,6 +39,15 @@ fun AddPhonePage(hasPhone: Boolean, next: () -> Unit) {
actions = {

},
navigationIcon = {
IconButton(onClick = { pop() }) {
Icon(
painter = painterResource(id = R.drawable.ic_back),
contentDescription = null,
tint = MixinAppTheme.colors.icon,
)
}
}
)
Column(modifier = Modifier.padding(horizontal = 20.dp)) {
Spacer(modifier = Modifier.height(50.dp))
4 changes: 2 additions & 2 deletions app/src/main/java/one/mixin/android/ui/tip/TipActivity.kt
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ import one.mixin.android.R
import one.mixin.android.databinding.ActivityContactBinding
import one.mixin.android.extension.defaultSharedPreferences
import one.mixin.android.extension.replaceFragment
import one.mixin.android.ui.common.BlazeBaseActivity
import one.mixin.android.ui.common.BaseActivity
import one.mixin.android.ui.tip.TipFragment.Companion.ARGS_SHOULD_WATCH
import one.mixin.android.ui.tip.TipFragment.Companion.ARGS_TIP_BUNDLE
import one.mixin.android.util.viewBinding

@AndroidEntryPoint
class TipActivity : BlazeBaseActivity() {
class TipActivity : BaseActivity() {
companion object {
const val TAG = "TipActivity"

4 changes: 4 additions & 0 deletions app/src/main/java/one/mixin/android/ui/tip/TipFragment.kt
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ import one.mixin.android.tip.getTipExceptionMsg
import one.mixin.android.ui.common.BaseFragment
import one.mixin.android.ui.common.PinInputBottomSheetDialogFragment
import one.mixin.android.ui.common.VerifyBottomSheetDialogFragment
import one.mixin.android.ui.home.MainActivity
import one.mixin.android.ui.setting.WalletPasswordFragment
import one.mixin.android.util.BiometricUtil
import one.mixin.android.util.getMixinErrorStringByCode
@@ -496,6 +497,9 @@ class TipFragment : BaseFragment(R.layout.fragment_tip) {
TipType.Upgrade -> toast(R.string.Upgrade_TIP_successfully)
}

if (activity?.isTaskRoot == true) {
MainActivity.show(requireContext())
}
activity?.finish()
}

Original file line number Diff line number Diff line change
@@ -57,7 +57,9 @@ suspend fun clearDatabase(context: Context) =
File("$it${File.separator}${Constants.DataBase.DB_NAME}-wal").delete()
File("$it${File.separator}${Constants.DataBase.DB_NAME}-journal").delete()
}
dbFile.delete()
do {
dbFile.delete()
} while (dbFile.exists())
} catch (e: Exception) {
Timber.e(e)
}
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_set_up_pin.xml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
android:fillColor="#D3D4D5" />
<path
android:pathData="M262,21C259.79,21 258,22.79 258,25C258,26.86 259.27,28.43 261,28.87V35H265V33H263V32H265V30H263V28.87C264.73,28.43 266,26.86 266,25C266,22.79 264.21,21 262,21ZM260,25C260,23.9 260.89,23 262,23C263.11,23 264,23.9 264,25C264,26.1 263.11,27 262,27C260.89,27 260,26.1 260,25Z"
android:fillColor="#4B7CDD"
android:fillColor="#D3D4D5"
android:fillType="evenOdd" />
<path
android:pathData="M250,60C250,57.79 251.79,56 254,56H270C272.21,56 274,57.79 274,60V80C274,82.21 272.21,84 270,84H254C251.79,84 250,82.21 250,80V60Z"
@@ -27,7 +27,7 @@
android:strokeColor="#D3D4D5" />
<path
android:pathData="M262,59C259.79,59 258,60.79 258,63C258,64.86 259.27,66.43 261,66.87V73H265V71H263V70H265V68H263V66.87C264.73,66.43 266,64.86 266,63C266,60.79 264.21,59 262,59ZM260,63C260,61.9 260.89,61 262,61C263.11,61 264,61.9 264,63C264,64.1 263.11,65 262,65C260.89,65 260,64.1 260,63Z"
android:fillColor="#D3D4D5"
android:fillColor="#4B7CDD"
android:fillType="evenOdd" />
<path
android:strokeWidth="1"
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
android:layout_marginEnd="36dp"
android:text="@string/Backup_Now"
android:textColor="@color/white"
android:textFontWeight="500"
android:textSize="16sp" />

<TextView
@@ -59,6 +60,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@color/selector_blue_tv"
android:textFontWeight="500"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="20dp"
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_landing.xml
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@
android:layout_marginStart="36dp"
android:layout_marginEnd="36dp"
android:textSize="14sp"
android:textFontWeight="500"
app:layout_constraintBottom_toTopOf="@id/continue_tv"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
@@ -80,6 +81,7 @@
android:layout_marginStart="36dp"
android:layout_marginEnd="36dp"
android:textSize="14sp"
android:textFontWeight="500"
app:layout_constraintBottom_toTopOf="@id/version"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -947,7 +947,7 @@
<string name="setting_data_mobile">When using mobile data</string>
<string name="setting_data_title">Media auto-download</string>
<string name="setting_data_wifi">When connected on Wi-Fi</string>
<string name="setting_log_out_account_pin_content">If you continue, your profile and account details will be delete on %1$s. read our document to **learn more**.</string>
<string name="setting_log_out_account_pin_content">Logout the account will not affect the asset security of your Mixin wallet. read our documentation ** to learn more **.</string>
<string name="setting_delete_account_pin_content">If you continue, your profile and account details will be delete on %1$s. read our document to **learn more**.</string>
<string name="setting_delete_anonymous_account_pin_content">If you continue, your profile and account details will be delete on %1$s.</string>
<string name="setting_delete_account_send">We will send a 4-digit code to %1$s</string>