Skip to content

Commit

Permalink
Merge pull request #2359 from torusresearch/develop
Browse files Browse the repository at this point in the history
Release v3.0.1
  • Loading branch information
chaitanyapotti authored Sep 26, 2023
2 parents 411762f + 5bf64e5 commit 287ba8d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/handlers/Popup/PopupWithBcHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PopupWithBcHandler extends PopupHandler {
if (successExtraFn) await successExtraFn.call(this, data)
resolve(data)
} catch (error) {
log.error('message error', error)
reject(error)
} finally {
this.bc.close()
Expand Down
5 changes: 3 additions & 2 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@ethereumjs/util'
import { concatSig, normalize } from '@metamask/eth-sig-util'
import { keccak256 } from '@toruslabs/metadata-helpers'
import { safeatob } from '@toruslabs/openlogin-utils'
import assert from 'assert'
import BigNumber from 'bignumber.js'
import BN from 'bn.js'
Expand Down Expand Up @@ -872,10 +873,10 @@ export const handleRedirectParameters = (hash, queryParameters) => {
let error = ''
if (!queryParameters.preopenInstanceId) {
if (Object.keys(hashParameters).length > 0 && hashParameters.state) {
instanceParameters = JSON.parse(atob(decodeURIComponent(decodeURIComponent(hashParameters.state)))) || {}
instanceParameters = JSON.parse(safeatob(decodeURIComponent(decodeURIComponent(hashParameters.state)))) || {}
error = hashParameters.error_description || hashParameters.error || error
} else if (Object.keys(queryParameters).length > 0 && queryParameters.state) {
instanceParameters = JSON.parse(atob(decodeURIComponent(decodeURIComponent(queryParameters.state)))) || {}
instanceParameters = JSON.parse(safeatob(decodeURIComponent(decodeURIComponent(queryParameters.state)))) || {}
if (queryParameters.error) error = queryParameters.error
}
}
Expand Down
37 changes: 27 additions & 10 deletions src/views/End/End.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<script>
import { BroadcastChannel } from '@toruslabs/broadcast-channel'
import { safeatob } from '@toruslabs/openlogin-utils'
import { safeatob, storageAvailable } from '@toruslabs/openlogin-utils'
import log from 'loglevel'
import BoxLoader from '../../components/helpers/BoxLoader'
Expand All @@ -71,13 +71,25 @@ export default {
try {
const { hash } = this.$route
const hashUrl = new URL(`${window.location.origin}?${hash.slice(1)}`)
const error = hashUrl.searchParams.get('error')
const error = hashUrl.searchParams.get('error') || ''
if (error) {
if (storageAvailable('localStorage')) {
this.channelId = localStorage.getItem('broadcast_channel_id')
}
this.broadcastData = {
type: POPUP_RESULT,
error,
}
await this.continueToApp()
return
}
const paramSessionNamespace = hashUrl.searchParams.get('sessionNamespace') || ''
const openLoginHandler = await OpenLoginHandler.getInstance({}, {}, paramSessionNamespace)
const { appState } = openLoginHandler.state.userInfo
const parsedAppState = JSON.parse(safeatob(decodeURIComponent(decodeURIComponent(appState || ''))))
const { appState } = openLoginHandler.state.userInfo || {}
const parsedAppState = JSON.parse(safeatob(decodeURIComponent(decodeURIComponent(appState || ''))) || '{}')
this.whiteLabel = parsedAppState.whiteLabel || {}
openLoginHandler.whiteLabel = this.whiteLabel
const loginConfig = parsedAppState.loginConfig || {}
Expand Down Expand Up @@ -136,18 +148,23 @@ export default {
this.loading = true
try {
// move selected key to the first position of keys
const { keys } = this.broadcastData
const id = keys.findIndex((k) => k.ethAddress === this.selectedAccount)
if (id > -1) {
const selectedKey = keys[id]
keys.splice(id, 1)
keys.unshift(selectedKey)
const { keys = [], error } = this.broadcastData
if (!error) {
const id = keys.findIndex((k) => k.ethAddress === this.selectedAccount)
if (id > -1) {
const selectedKey = keys[id]
keys.splice(id, 1)
keys.unshift(selectedKey)
}
}
const bc = new BroadcastChannel(`redirect_openlogin_channel_${this.channelId}`, broadcastChannelOptions)
await bc.postMessage({ data: this.broadcastData })
bc.close()
log.info('posted info')
if (storageAvailable('localStorage')) {
localStorage.removeItem('broadcast_channel_id')
}
// wait for 100ms before closing window
// this is mostly in case of facebook/line logins on mobile devices.
setTimeout(() => {
Expand Down
7 changes: 5 additions & 2 deletions src/views/Start/Start.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</template>

<script>
import { safeatob } from '@toruslabs/openlogin-utils'
import { safeatob, storageAvailable } from '@toruslabs/openlogin-utils'
import log from 'loglevel'
import BoxLoader from '../../components/helpers/BoxLoader'
Expand Down Expand Up @@ -49,7 +49,10 @@ export default {
const { loginProvider, state, mfaLevel, sessionNamespace, ...rest } = this.$route.query
const stateParams = JSON.parse(safeatob(state))
log.info('logging in with', loginProvider, state, rest, mfaLevel)
const { whiteLabel = {}, loginConfig = {}, origin } = stateParams
const { whiteLabel = {}, loginConfig = {}, origin, instanceId } = stateParams
if (storageAvailable('localStorage')) {
localStorage.setItem('broadcast_channel_id', instanceId)
}
this.iframeOrigin = origin
this.isCustomVerifier = Object.keys(loginConfig).length > 0
Expand Down

0 comments on commit 287ba8d

Please sign in to comment.