Skip to content

Commit

Permalink
PWN-8341 - refreshDeviceShare no longer contains metadata to update -…
Browse files Browse the repository at this point in the history
… we do it by ourselves (#1889)
  • Loading branch information
kabramovp2p authored Jun 28, 2023
1 parent 6c04dd2 commit 6de9e65
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.p2p.wallet.auth.interactor.restore

import org.p2p.wallet.auth.analytics.RestoreWalletAnalytics
import org.p2p.wallet.auth.analytics.RestoreWalletAnalytics.UsernameRestoreMethod
import org.p2p.wallet.auth.gateway.repository.model.GatewayOnboardingMetadata
import org.p2p.wallet.auth.model.OnboardingFlow
import org.p2p.wallet.auth.model.PhoneNumber
import org.p2p.wallet.auth.model.RestoreUserResult
Expand Down Expand Up @@ -42,9 +41,8 @@ class RestoreWalletInteractor(
suspend fun tryRestoreUser(restoreFlow: OnboardingFlow.RestoreWallet): RestoreUserResult =
userRestoreInteractor.tryRestoreUser(restoreFlow)

suspend fun refreshDeviceShare(
metadata: GatewayOnboardingMetadata
): Web3AuthSignUpResponse.ShareDetailsWithMeta = userRestoreInteractor.refreshDeviceShare(metadata)
suspend fun refreshDeviceShare(): Web3AuthSignUpResponse.ShareDetailsWithMeta =
userRestoreInteractor.refreshDeviceShare()

suspend fun finishAuthFlow() {
restoreWalletAnalytics.setUserRestoreMethod(UsernameRestoreMethod.WEB3AUTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.p2p.wallet.auth.interactor.restore
import com.google.gson.JsonObject
import timber.log.Timber
import org.p2p.core.crashlytics.CrashLogger
import org.p2p.wallet.auth.gateway.repository.model.GatewayOnboardingMetadata
import org.p2p.wallet.auth.interactor.UsernameInteractor
import org.p2p.wallet.auth.model.OnboardingFlow.RestoreWallet
import org.p2p.wallet.auth.model.RestoreError
Expand Down Expand Up @@ -262,12 +261,10 @@ class UserRestoreInteractor(
usernameInteractor.tryRestoreUsername(tokenKeyProvider.publicKey.toBase58Instance())
}

suspend fun refreshDeviceShare(
metadata: GatewayOnboardingMetadata
): Web3AuthSignUpResponse.ShareDetailsWithMeta {
suspend fun refreshDeviceShare(): Web3AuthSignUpResponse.ShareDetailsWithMeta {
val socialShareUserId = restoreFlowDataLocalRepository.socialShareUserId
?: error("Device+Social restore way failed. Social share ID is null")
val deviceShare = web3AuthApi.refreshDeviceShare(metadata)
val deviceShare = web3AuthApi.refreshDeviceShare()
val data = signUpDetailsStorage.getLastSignUpUserDetails()!!.signUpDetails.copy(deviceShare = deviceShare)
signUpDetailsStorage.save(
data = data,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.p2p.wallet.auth.web3authsdk

import com.google.gson.JsonObject
import org.p2p.wallet.auth.gateway.repository.model.GatewayOnboardingMetadata
import org.p2p.wallet.auth.web3authsdk.response.Web3AuthSignInResponse
import org.p2p.wallet.auth.web3authsdk.response.Web3AuthSignUpResponse

Expand Down Expand Up @@ -29,9 +28,7 @@ interface Web3AuthApi {
encryptedMnemonic: JsonObject
): Web3AuthSignInResponse

suspend fun refreshDeviceShare(
metadata: GatewayOnboardingMetadata
): Web3AuthSignUpResponse.ShareDetailsWithMeta
suspend fun refreshDeviceShare(): Web3AuthSignUpResponse.ShareDetailsWithMeta

/**
* @param googleIdJwtToken used to auth user on Web3Auth server-side using google web client id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import org.p2p.core.network.environment.TorusEnvironment
import org.p2p.wallet.BuildConfig
import org.p2p.wallet.auth.gateway.repository.model.GatewayOnboardingMetadata
import org.p2p.wallet.auth.repository.AuthRepository
import org.p2p.wallet.auth.web3authsdk.mapper.Web3AuthClientMapper
import org.p2p.wallet.auth.web3authsdk.response.Web3AuthSignInResponse
import org.p2p.wallet.auth.web3authsdk.response.Web3AuthSignUpResponse
import org.p2p.core.network.environment.TorusEnvironment

private const val JS_COMMUNICATION_CHANNEL_NAME = "AndroidCommunicationChannel"
private const val INDEX_HTML_URI = "file:///android_asset/index.html"
Expand Down Expand Up @@ -155,19 +154,16 @@ class Web3AuthApiClient(
}
}

override suspend fun refreshDeviceShare(
metadata: GatewayOnboardingMetadata
): Web3AuthSignUpResponse.ShareDetailsWithMeta {
override suspend fun refreshDeviceShare(): Web3AuthSignUpResponse.ShareDetailsWithMeta {
return suspendCancellableCoroutine {
this.continuation = it

Timber.tag(TAG).i("refreshDeviceShare triggered")

val metadataAsJsObject = gson.toJson(metadata)
onboardingWebView.evaluateJavascript("console.log(lastFacade)", null)
onboardingWebView.evaluateJavascript(
callToLastFacade(
jsMethodCall = "refreshDeviceShare($metadataAsJsObject)"
jsMethodCall = "refreshDeviceShare()"
),
null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DevicesPresenter(

private suspend fun refreshDeviceShare(newMetadata: GatewayOnboardingMetadata) {
try {
restoreWalletInteractor.refreshDeviceShare(newMetadata)
restoreWalletInteractor.refreshDeviceShare()
metadataInteractor.updateMetadata(newMetadata)
} catch (error: Throwable) {
view?.showFailDeviceChange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SettingsEmailConfirmPresenter(

private suspend fun refreshDeviceShare(newMetadata: GatewayOnboardingMetadata) {
try {
restoreWalletInteractor.refreshDeviceShare(newMetadata)
restoreWalletInteractor.refreshDeviceShare()
metadataInteractor.updateMetadata(newMetadata)
} catch (error: Throwable) {
view?.showFailDeviceChange()
Expand Down

0 comments on commit 6de9e65

Please sign in to comment.