Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client/manager/UserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export default class UserManager {
return this.UserApi.addRedeemable(payload)
}

mergeAccounts (payload) {
return this.UserApi.mergeAccounts(payload)
}

/**
* Checked to see if the refresh token is valid
* @return {Boolean} returns True / False if the refresh token is valid
Expand Down
38 changes: 38 additions & 0 deletions src/internal/net/rest/api/UserApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import urlParse from 'url-parse'
import User from '../../../../model/User'


export default class UserApi {
constructor (bv) {
this.Blockv = bv
Expand Down Expand Up @@ -431,4 +432,41 @@ export default class UserApi {
userID: profile.id
})
}

async mergeAccounts(payload) {

try {

// Begin merge
await this.client.request('POST', '/v1/user/merge_accounts', payload, true)

// Wait until the specified token has been added to the account
let timeout = Date.now() + 30000
while (true) {

// Get current tokens
let tokens = await this.getUserTokens()
if (tokens.find(t => t.properties.token.toLowerCase().trim() == payload.token.toLowerCase().trim())) {

// Found, account merging is probably finished now
break

}

// Not found, check if timeout is exceeded
if (Date.now() > timeout)
throw new Error('Could not find merged token. Please refresh the page and try again.')

// Wait a bit
await new Promise(c => setTimeout(c, 2000))

}

} catch (err) {

throw new Error(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try/catch block does nothing at all, it's safe to remove it... In fact it's better to remove it rather than wrapping an Error inside another Error


}

}
}