Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:torusresearch/torus-website into…
Browse files Browse the repository at this point in the history
… feat/openlogin-v5
  • Loading branch information
arch1995 committed Oct 30, 2023
2 parents 7ad7e8a + 69ad77f commit 9786a36
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 3,578 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/binance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Run build
run: |
. ./scripts/setup.sh
npm version major -m 'Updating version to %s [skip ci]'
npm version patch -m 'Updating version to %s [skip ci]'
npm run build
. ./scripts/gitPush.sh
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Run build
run: |
. ./scripts/setup.sh
npm version major -m 'Updating version to %s [skip ci]'
npm version patch -m 'Updating version to %s [skip ci]'
npm run build
. ./scripts/gitPush.sh
env:
Expand Down
3,845 changes: 294 additions & 3,551 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "2.2.5",
"version": "4.0.2",
"private": true,
"scripts": {
"serve": "npm run locale && vue-cli-service serve",
Expand Down
4 changes: 2 additions & 2 deletions scripts/updateIframeIntegrity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ git config user.name "torus-bot"
cd ~/torus-embed/

if [[ "$GITHUB_REF" = 'refs/heads/master' ]]; then
npm version major -m 'Updating iframe integrity and publish %s'
npm version patch -m 'Updating iframe integrity and publish %s'
git push origin master
git push --tags
fi
if [[ "$GITHUB_REF" = 'refs/heads/binance' ]]; then
npm version major -m 'Updating iframe integrity and publish %s'
npm version patch -m 'Updating iframe integrity and publish %s'
git push origin binance
fi
2 changes: 1 addition & 1 deletion src/containers/WalletTransfer/WalletTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<v-menu transition="slide-y-transition" bottom>
<template #activator="{ on }">
<v-btn class="select-coin" label :outlined="$vuetify.theme.dark" v-on="on">
<span class="select-coin-name">{{ selectedItemDisplay && selectedItemDisplay.name }}</span>
<span class="select-coin-name">{{ selectedItemDisplay && (selectedItemDisplay.name || selectedItemDisplay.symbol) }}</span>
<div class="flex-grow-1 text-right pr-2">
<v-icon right>$vuetify.icons.select</v-icon>
</div>
Expand Down
23 changes: 19 additions & 4 deletions src/controllers/PreferencesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ import {
} from '../utils/enums'
import { notifyUser } from '../utils/notifications'
import { setSentryEnabled } from '../utils/sentry'
import { formatDate, formatPastTx, formatTime, getEthTxStatus, getIFrameOrigin, getUserLanguage, isMain, waitForMs } from '../utils/utils'
import {
formatDate,
formatPastTx,
formatTime,
getEthTxStatus,
getIFrameOrigin,
getUserLanguage,
isMain,
toChecksumAddressByChainId,
waitForMs,
} from '../utils/utils'
import { ObservableStore } from './utils/ObservableStore'
import { isErrorObject, prettyPrintData } from './utils/permissionUtils'

Expand Down Expand Up @@ -217,6 +227,11 @@ class PreferencesController extends SafeEventEmitter {
customNetworks,
} = user.data || {}

// transform addresses that were saved as lowercase in our db
const chainId = this.network.getCurrentChainId()
const publicAddress = toChecksumAddressByChainId(public_address, chainId)
const defaultPublicAddress = toChecksumAddressByChainId(default_public_address) || publicAddress

this.updateStore(
{
contacts,
Expand All @@ -226,11 +241,11 @@ class PreferencesController extends SafeEventEmitter {
locale: locale || getUserLanguage(),
permissions,
accountType: account_type || ACCOUNT_TYPE.NORMAL,
defaultPublicAddress: default_public_address || public_address,
defaultPublicAddress,
customTokens,
customNfts,
},
public_address
publicAddress
)

// update network controller with all the custom network updates.
Expand Down Expand Up @@ -784,7 +799,7 @@ class PreferencesController extends SafeEventEmitter {
normalizedAddChainParams(id, addChainParams) {
/**
* addChainParams interface
*
*
* interface AddEthereumChainParameter {
chainId: string; // A 0x-prefixed hexadecimal string
chainName: string;
Expand Down
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
3 changes: 2 additions & 1 deletion src/registerServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function register(config) {

function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl, { updateViaCache: 'all', scope: process.env.BASE_URL })
.register(swUrl, { updateViaCache: 'imports', scope: process.env.BASE_URL })
.then((registration) => {
registration.onupdatefound = () => {
const installingWorker = registration.installing
Expand Down Expand Up @@ -104,6 +104,7 @@ function registerValidSW(swUrl, config) {
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
cache: 'no-cache',
headers: { 'Service-Worker': 'script' },
})
.then((response) => {
Expand Down
4 changes: 2 additions & 2 deletions src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isHexString, privateToAddress } from '@ethereumjs/util'
import { isHexString } from '@ethereumjs/util'
import { OpenloginSessionManager } from '@toruslabs/openlogin-session-manager'
import { BrowserStorage, safeatob, safebtoa } from '@toruslabs/openlogin-utils'
import deepmerge from 'deepmerge'
Expand Down Expand Up @@ -255,7 +255,7 @@ export default {
dispatch('subscribeToControllers')
commit('setUserInfo', userInfo)

const selectedAddress = `0x${Buffer.from(privateToAddress(Buffer.from(privateKey.padStart(64, '0'), 'hex'))).toString('hex')}`
const selectedAddress = generateAddressFromPrivateKey(privateKey)
await dispatch('initTorusKeyring', {
keys: [
{
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 9786a36

Please sign in to comment.