Skip to content

Commit

Permalink
Merge pull request #1002 from liquality/feat/sovryn-fixes
Browse files Browse the repository at this point in the history
Feat/sovryn fixes
  • Loading branch information
bradleySuira authored Apr 21, 2023
2 parents f31ce7a + 1ab93f7 commit ef43c17
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 190 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
VUE_APP_LEDGER_BRIDGE_URL=https://liquality.github.io/hw-web-bridge-app/dist/0.1.0
VUE_APP_SOVRYN_RPC_URL_TESTNET=https://testnet.sovryn.app/rpc
VUE_APP_SOVRYN_RPC_URL_MAINNET=https://mainnet.sovryn.app/rpc
VUE_APP_TRANSAK_WIDGET_URL=
Expand All @@ -24,4 +23,7 @@ VUE_APP_MAX_ERROR_LOG_SIZE=100
VUE_APP_REPORT_TARGETS=Sentry,Console
VUE_APP_NPM_PACKAGE_VERSION=0_81_0
VUE_APP_SENTRY_DSN=https://[email protected]/5444900
VUE_APP_INFURA_NFT_API_URL=https://nft.api.infura.io/
VUE_APP_INFURA_API_KEY=
VUE_APP_INFURA_API_KEY_SECRET=

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
},
"dependencies": {
"@chainify/hw-ledger": "2.4.0",
"@liquality/cryptoassets": "2.8.0",
"@liquality/error-parser": "2.2.6",
"@liquality/cryptoassets": "2.9.0",
"@liquality/error-parser": "2.2.8",
"@liquality/ethereum-utils": "^1.13.12",
"@liquality/terra-networks": "^1.13.12",
"@liquality/types": "^1.13.12",
"@liquality/wallet-core": "4.21.1",
"@liquality/wallet-core": "4.23.0",
"@terra-money/terra.js": "^3.1.6",
"@testing-library/vue": "^5.8.2",
"amplitude-js": "8.18.2",
Expand Down
4 changes: 1 addition & 3 deletions src/broker/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class Background {
} else if (isInternal) {
this.onInternalConnection(connection)
} else {
if (connection.name !== 'HW-BRIDGE') {
this.onExternalConnection(connection)
}
this.onExternalConnection(connection)
}
})
}
Expand Down
13 changes: 6 additions & 7 deletions src/components/ConnectionDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,12 @@ export default {
})
}
},
created() {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0) {
const { origin } = new URL(tabs[0].url)
this.currentOrigin = origin
}
})
async created() {
const [tab] = await browser.tabs.query({ active: true, currentWindow: true })
if (tab) {
const { origin } = new URL(tab.url)
this.currentOrigin = origin
}
}
}
</script>
Expand Down
2 changes: 0 additions & 2 deletions src/components/Head.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default {
},
methods: {
...mapActions(['changeActiveNetwork']),
...mapActions('app', ['settingsModalOpen']),
toggleShowNetworks() {
this.showNetworks = !this.showNetworks
if (this.showNetworks) {
Expand All @@ -95,7 +94,6 @@ export default {
if (this.showConnectionDrawer) {
this.showNetworks = false
}
this.settingsModalOpen(false)
},
hideConnectionDrawer() {
this.showConnectionDrawer = false
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default {
}
})
this.showMenuList = false
chrome.tabs.create({
browser.tabs.create({
url: browser.runtime.getURL('/index.html#/accounts/hardware-wallet?mode=tab')
})
},
Expand Down
5 changes: 0 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import devtools from '@vue/devtools'
import Vue from 'vue'
import App from './App.vue'
import store from './store'
Expand All @@ -19,7 +18,3 @@ new Vue({
store,
render: (h) => h(App)
}).$mount('#app')

if (process.env.NODE_ENV === 'development' && process.env.VUE_APP_USE_VUE_DEV_TOOLS) {
devtools.connect()
}
11 changes: 9 additions & 2 deletions src/store/modules/app/requestPermission.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ALLOWED = [
]

export const requestPermission = async (
{ state, dispatch, commit, rootState },
{ state, dispatch, commit, rootState, rootGetters },
{ origin, data }
) => {
const { requestPermissionActive } = state
Expand Down Expand Up @@ -103,7 +103,14 @@ export const requestPermission = async (
permissionRoute = '/permission/signPsbt'
}

createPopup(`${permissionRoute}?${query}`, () => reject(new UserDeclinedError()))
const url = `${permissionRoute}?${query}`
const account = rootGetters.accountItem(accountId)

if (account?.type.includes('ledger')) {
browser.tabs.create({ url: browser.runtime.getURL(`/index.html#${url}`) })
} else {
createPopup(url, () => reject(new UserDeclinedError()))
}
})
} else {
commit('SET_REQUEST_PERMISSION_ACTIVE', { active: false })
Expand Down
30 changes: 14 additions & 16 deletions src/utils/hardware-wallet.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { LedgerDeviceConnectionError } from '@liquality/error-parser'
// import { LedgerDeviceConnectionError } from '@liquality/error-parser'

export const LEDGER_USB_VENDOR_ID = '0x2c97'

export async function tryConnectLedgerDevice() {
const connectedDevices = await window.navigator.hid.requestDevice({
filters: [{ vendorId: LEDGER_USB_VENDOR_ID }]
})
const userApprovedWebHidConnection = connectedDevices.some(
(device) => device.vendorId === Number(LEDGER_USB_VENDOR_ID)
)
return !!userApprovedWebHidConnection
}

export const ledgerConnectMixin = {
data() {
return {
Expand All @@ -21,12 +11,20 @@ export const ledgerConnectMixin = {
methods: {
async connectLedger() {
if (!this.ledgerConnected) {
const connected = await tryConnectLedgerDevice()

if (!connected) {
throw new LedgerDeviceConnectionError()
if ('hid' in navigator) {
let alreadyAssignedDevices = await navigator.hid.getDevices()
const alreadyAssignedDevice = alreadyAssignedDevices.filter(
(d) => d.vendorId === Number(LEDGER_USB_VENDOR_ID)
)
if (alreadyAssignedDevice.length > 0) {
this.ledgerConnected = true
} else {
const [device] = await navigator.hid.requestDevice({
filters: [{ vendorId: LEDGER_USB_VENDOR_ID }]
})
this.ledgerConnected = !!device
}
}
this.ledgerConnected = connected
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/views/PermissionSend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ export default {
} else {
window.close()
}
} catch (err) {
console.error(err)
} finally {
this.signRequestModalOpen = false
this.loading = false
Expand Down
2 changes: 1 addition & 1 deletion src/views/Send/Send.vue
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ export default {
customFee: this.customFee
})
const url = `/index.html#/accounts/${this.accountId}/${this.asset}/send?${sendParams}`
chrome.tabs.create({ url: browser.runtime.getURL(url) })
browser.tabs.create({ url: browser.runtime.getURL(url) })
} else {
this.currentStep = 'confirm'
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/Swap/Swap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ export default {
selectedQuote: this.selectedQuote
})
const url = `/index.html#/accounts/${this.accountId}/${this.asset}/swap?${swapParams}`
chrome.tabs.create({ url: browser.runtime.getURL(url) })
browser.tabs.create({ url: browser.runtime.getURL(url) })
} else {
this.currentStep = 'confirm'
}
Expand Down
Loading

0 comments on commit ef43c17

Please sign in to comment.