Skip to content

Commit 071f1e6

Browse files
don't throw if unavailable
1 parent be374c6 commit 071f1e6

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

.idea/jarRepositories.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/main/java/com/web3auth/core/Web3Auth.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
1818

1919
private var loginCompletableFuture: CompletableFuture<Web3AuthResponse> = CompletableFuture()
2020

21-
private var web3AuthResponse = Web3AuthResponse()
21+
private var web3AuthResponse: Web3AuthResponse? = null
2222
private var web3AuthOption = web3AuthOptions
2323
private var sessionManager: SessionManager = SessionManager(web3AuthOption.context)
2424

@@ -108,22 +108,22 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
108108
decodeBase64URLString(hash).toString(Charsets.UTF_8), Web3AuthResponse::class.java
109109
)
110110

111-
if (web3AuthResponse.error?.isNotBlank() == true) {
111+
if (web3AuthResponse?.error?.isNotBlank() == true) {
112112
loginCompletableFuture.completeExceptionally(
113113
UnKnownException(
114-
web3AuthResponse.error ?: Web3AuthError.getError(ErrorCode.SOMETHING_WENT_WRONG)
114+
web3AuthResponse?.error ?: Web3AuthError.getError(ErrorCode.SOMETHING_WENT_WRONG)
115115
)
116116
)
117-
} else if (web3AuthResponse.privKey.isNullOrBlank()) {
117+
} else if (web3AuthResponse?.privKey.isNullOrBlank()) {
118118
loginCompletableFuture.completeExceptionally(Exception(Web3AuthError.getError(ErrorCode.SOMETHING_WENT_WRONG)))
119119
} else {
120-
web3AuthResponse.sessionId?.let { sessionManager.saveSessionId(it) }
120+
web3AuthResponse?.sessionId?.let { sessionManager.saveSessionId(it) }
121121

122-
if (web3AuthResponse.userInfo?.dappShare?.isNotEmpty() == true) {
122+
if (web3AuthResponse?.userInfo?.dappShare?.isNotEmpty() == true) {
123123
KeyStoreManagerUtils.encryptData(
124-
web3AuthResponse.userInfo?.verifier.plus(" | ")
125-
.plus(web3AuthResponse.userInfo?.verifierId),
126-
web3AuthResponse.userInfo?.dappShare!!,
124+
web3AuthResponse?.userInfo?.verifier.plus(" | ")
125+
.plus(web3AuthResponse?.userInfo?.verifierId),
126+
web3AuthResponse?.userInfo?.dappShare!!,
127127
)
128128
}
129129
loginCompletableFuture.complete(web3AuthResponse)
@@ -177,15 +177,15 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
177177
val tempJson = JSONObject(response)
178178
web3AuthResponse =
179179
gson.fromJson(tempJson.toString(), Web3AuthResponse::class.java)
180-
if (web3AuthResponse.error?.isNotBlank() == true) {
180+
if (web3AuthResponse?.error?.isNotBlank() == true) {
181181
sessionCompletableFuture.completeExceptionally(
182182
UnKnownException(
183-
web3AuthResponse.error ?: Web3AuthError.getError(
183+
web3AuthResponse?.error ?: Web3AuthError.getError(
184184
ErrorCode.SOMETHING_WENT_WRONG
185185
)
186186
)
187187
)
188-
} else if (web3AuthResponse.privKey.isNullOrBlank()) {
188+
} else if (web3AuthResponse?.privKey.isNullOrBlank()) {
189189
sessionCompletableFuture.completeExceptionally(
190190
Exception(
191191
Web3AuthError.getError(ErrorCode.SOMETHING_WENT_WRONG)
@@ -207,37 +207,37 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
207207
return sessionCompletableFuture
208208
}
209209

210-
fun getPrivkey(): String? {
210+
fun getPrivkey(): String {
211211
val privKey: String? = if (web3AuthResponse == null) {
212-
throw Error(Web3AuthError.getError(ErrorCode.NOUSERFOUND))
212+
""
213213
} else {
214214
if (web3AuthOption.useCoreKitKey == true) {
215-
web3AuthResponse.coreKitKey
215+
web3AuthResponse?.coreKitKey
216216
} else {
217-
web3AuthResponse.privKey
217+
web3AuthResponse?.privKey
218218
}
219219
}
220-
return privKey
220+
return privKey ?: ""
221221
}
222222

223-
fun getEd25519PrivKey(): String? {
223+
fun getEd25519PrivKey(): String {
224224
val ed25519Key: String? = if (web3AuthResponse == null) {
225-
throw Error(Web3AuthError.getError(ErrorCode.NOUSERFOUND))
225+
""
226226
} else {
227227
if (web3AuthOption.useCoreKitKey == true) {
228-
web3AuthResponse.coreKitEd25519PrivKey
228+
web3AuthResponse?.coreKitEd25519PrivKey
229229
} else {
230-
web3AuthResponse.ed25519PrivKey
230+
web3AuthResponse?.ed25519PrivKey
231231
}
232232
}
233-
return ed25519Key
233+
return ed25519Key ?: ""
234234
}
235235

236236
fun getUserInfo(): UserInfo? {
237237
return if (web3AuthResponse == null) {
238238
throw Error(Web3AuthError.getError(ErrorCode.NOUSERFOUND))
239239
} else {
240-
web3AuthResponse.userInfo
240+
web3AuthResponse?.userInfo
241241
}
242242
}
243243
}

0 commit comments

Comments
 (0)