Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix account and scan bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Schuler-Gabriel committed Oct 6, 2023
1 parent 1a9517f commit df701aa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ class Email {
}
this@Email.client(context, onError) { client ->
client.accounts().addOnSuccessListener { credentials ->
if (credentials.size > 0){
if (credentials.isNullOrEmpty()) {
onComplete()
}else{
client.dayCutoff(dayCutOff)
client.messages(object : MessagesCallback {
override fun onComplete(
Expand Down Expand Up @@ -186,26 +188,29 @@ class Email {
) {
this.client(context, onError) { client ->
client.accounts().addOnSuccessListener { credentials ->
MainScope().async {
var returnedAccounts = 0
if (credentials.isNullOrEmpty()) {
onComplete?.invoke()
client.close()
} else {
if (credentials.isNullOrEmpty()) {
onComplete?.invoke()
client.close()
} else {
MainScope().async {
var returnedAccounts = 0
for (credential in credentials) {
val account = Account.fromEmailAccount(credential)
account.isVerified = client.verify(credential).await()
account.isVerified = true
onAccount(account)
returnedAccounts++
if (returnedAccounts == credentials.size) {
onComplete?.invoke()
client.close()
}
}

}
}
}.addOnFailureListener {
onError(it.message ?: it.toString())
onComplete?.invoke()
client.close()
}
}
}
Expand Down Expand Up @@ -263,6 +268,7 @@ class Email {
onComplete()
}.addOnFailureListener {
onError(it.message ?: it.toString())
onComplete()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ class Retailer {
onComplete()
}.addOnFailureListener {
onError(it.message ?: it.toString())
onComplete()
}
} else {
onError(
"Logout: Account not found ${account.accountCommon.id} - ${account.username}")
onError("Logout: Account not found ${account.accountCommon.id} - ${account.username}")
onComplete()
}
}
}
Expand All @@ -153,8 +154,9 @@ class Retailer {
client(context).resetHistory()
client(context).unlink().addOnSuccessListener {
onComplete()
}.addOnFailureListener { ex ->
Timberland.e(ex)
}.addOnFailureListener {
onError(it.message ?: it.toString())
onComplete()
}
}

Expand Down Expand Up @@ -182,7 +184,7 @@ class Retailer {
if (mbAccountList.isNullOrEmpty()) {
onComplete()
client.close()
}else {
} else {
for (retailerAccount in mbAccountList) {
val account = Account.fromRetailerAccount(retailerAccount)
this.orders(
Expand All @@ -194,6 +196,7 @@ class Retailer {
fetchedAccounts++
if (fetchedAccounts >= mbAccountList.size) {
onComplete()
client.close()
}
}
}
Expand Down Expand Up @@ -231,6 +234,7 @@ class Retailer {
onScan(results)
if(remaining == 0){
onComplete?.invoke()
client.close()
}
}
val ordersFailureCallback: (Int, AccountLinkingException) -> Unit = { _: Int, exception: AccountLinkingException ->
Expand Down Expand Up @@ -261,47 +265,35 @@ class Retailer {
onComplete: (() -> Unit)? = null
) {
val client: AccountLinkingClient = client(context)
client.accounts()
.addOnSuccessListener { mbAccountList ->
if (mbAccountList.isNullOrEmpty()){
onComplete?.invoke()
}else {
MainScope().async {
var counter = 0
mbAccountList.forEach { retailerAccount ->
client.verify(retailerAccount.retailerId,
success = { isVerified: Boolean, _: String ->
val account = Account.fromRetailerAccount(retailerAccount)
account.isVerified = isVerified
onAccount.invoke(account)
counter++
if (counter == mbAccountList.size) {
onComplete?.invoke()
client.close()
}
},
failure = {
val account = Account.fromRetailerAccount(retailerAccount)
account.isVerified = false
onAccount.invoke(account)
counter++
if (counter == mbAccountList.size) {
onComplete?.invoke()
client.close()
}
}
)
client.accounts().addOnSuccessListener { mbAccountList ->
if (mbAccountList.isNullOrEmpty()){
onComplete?.invoke()
client.close()
} else {
MainScope().async {
var counter = 0
mbAccountList.forEach { retailerAccount ->
val account = Account.fromRetailerAccount(retailerAccount)
account.isVerified = true
onAccount.invoke(account)
counter++
if (counter == mbAccountList.size) {
onComplete?.invoke()
client.close()
}
}

}
}
.addOnFailureListener {
onError(it.message ?: "Unknown Error in retrieving accounts. $it")
onComplete?.invoke()
client.close()
}
}.addOnFailureListener {
onError(it.message ?: "Unknown Error in retrieving accounts. $it")
onComplete?.invoke()
client.close()
}
}



/**
* Verifies a user account.
*
Expand Down
5 changes: 3 additions & 2 deletions example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export const login = async (username: string, password: string, source: string)
password,
type: accountTypes.from(source)!,
};
await instance.login(account).catch(e => console.log(e));
console.log('logged in')
console.log('loging method:');
await instance.login(account).catch((e) => console.log(e));
console.log('logged in');
};

export const accounts = async (): Promise<void> => {
Expand Down

0 comments on commit df701aa

Please sign in to comment.