Skip to content

Commit

Permalink
Merge branch 'sync-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmerz committed Jan 9, 2024
2 parents 90a7117 + d44b2e0 commit 5b6388d
Show file tree
Hide file tree
Showing 349 changed files with 48,063 additions and 38,318 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

cd station-extension
npm run pre-commit
10 changes: 0 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,4 @@ npm run build
echo "Building Chrome zip."
zip -r "$name $version - Chrome.zip" build/ > /dev/null

echo "Building Firefox zip."
# use firefox manifest
cp build/manifest.json build/chrome.manifest.json
cp build/firefox.manifest.json build/manifest.json
zip -r "$name $version - Firefox.zip" build/* > /dev/null

# put files back in the right position
cp build/manifest.json build/firefox.manifest.json
cp build/chrome.manifest.json build/manifest.json

echo "DONE!"
63,345 changes: 33,924 additions & 29,421 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"scripts": {
"start": "npm run fix-extension-polyfills && react-scripts start",
"build-scripts": "webpack --config scripts/webpack.config.js",
"build": "cross-env react-app-rewired build && npm run build-scripts",
"build": "npm run fix-extension-polyfills && cross-env react-app-rewired build && npm run build-scripts",
"test": "react-scripts test",
"prepare": "husky install",
"prepare": "cd .. && husky install station-extension/.husky",
"pre-commit": "lint-staged",
"analyze": "source-map-explorer 'build/static/js/*.js'",
"fix-extension-polyfills": "sed -i '' 's/!globalThis\\.chrome\\?\\.runtime\\?\\.id/false/g' \"node_modules/webextension-polyfill/dist/browser-polyfill.js\""
},
"dependencies": {
"@0xsquid/sdk": "^1.14.11",
"@amplitude/analytics-browser": "^2.1.2",
"@anchor-protocol/anchor.js": "^5.1.1",
"@ledgerhq/hw-transport-web-ble": "^6.27.1",
"@mui/icons-material": "^5.8.0",
"@mui/material": "^5.9.1",
Expand All @@ -27,7 +27,8 @@
"@terra-money/log-finder-ruleset": "^3.0.3",
"@terra-money/msg-reader": "^3.0.1",
"@terra-money/station-connector": "^1.0.12",
"@terra-money/terra-utils": "^1.1.1",
"@terra-money/station-ui": "^1.0.1",
"@terra-money/terra-utils": "^1.2.0-beta.7",
"@terra-money/terra.js": "^3.1.9",
"@terra-money/terra.proto": "^2.0.0",
"@terra-money/wallet-kit": "^1.0.15",
Expand All @@ -45,6 +46,7 @@
"js-base64": "^3.7.2",
"keccak256": "^1.0.6",
"lottie-react": "^2.3.1",
"moment": "^2.29.4",
"numeral": "^2.0.6",
"prettier": "^2.6.2",
"qrcode.react": "^3.1.0",
Expand All @@ -53,7 +55,7 @@
"react": "^18.2.0",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.29.0",
"react-hook-form": "^7.45.4",
"react-i18next": "^11.18.1",
"react-modal": "^3.15.1",
"react-query": "^3.39.3",
Expand Down
4 changes: 2 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 3,
"name": "Station Wallet",
"version": "7.4.13",
"version_name": "7.4.13",
"version": "8.0.0",
"version_name": "8.0.0",
"background": {
"service_worker": "background.js"
},
Expand Down
34 changes: 31 additions & 3 deletions scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,44 @@ browser.runtime.onMessage.addListener(function (request, sender) {
})

/* popup */
// TODO: Actions such as transaction rejection if user closes a popup
let tabId = undefined
let isPopupOpen = false
browser.tabs.onRemoved.addListener(() => {
tabId = undefined
isPopupOpen = false
// reject transaction and connect requests
browser.storage.local
.get(["sign", "post", "connect"])
.then(({ sign = [], post = [], connect = { request: [] } }) => {
browser.storage.local.set({
sign: sign.map((s) =>
typeof success !== "boolean"
? {
...s,
success: false,
error: "User denied, extension popup was closed.",
}
: s
),
post: post.map((s) =>
typeof success !== "boolean"
? {
...s,
success: false,
error: "User denied, extension popup was closed.",
}
: s
),
connect: {
...connect,
request: [],
},
})
})
})

const POPUP_WIDTH = 480
const POPUP_HEIGHT = 600 // Chrome extension maximum height
const POPUP_WIDTH = 400
const POPUP_HEIGHT = 632 // Chrome extension maximum height

const getCenter = (window) => {
return {
Expand Down
26 changes: 16 additions & 10 deletions scripts/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async function setupStationProvider() {

case "theme":
const handleGetTheme = ({ connect = { allowed: [] }, theme }) => {
const isAllowed = connect.allowed.includes(origin)
const isAllowed = (connect.allowed || []).includes(origin)

if (isAllowed) {
sendResponse(true, theme)
Expand All @@ -188,8 +188,10 @@ async function setupStationProvider() {

const denied =
oldValue &&
oldValue.request.length - 1 === newValue.request.length &&
oldValue.allowed.length === newValue.allowed.length
(oldValue.request || []).length - 1 ===
(newValue.request || []).length &&
(oldValue.allowed || []).length ===
(newValue.allowed || []).length

if (denied) {
sendResponse(false, "User denied the connection request.")
Expand All @@ -211,12 +213,12 @@ async function setupStationProvider() {
// - send back the response and close the popup.
// 2. If not,
// - store the address on the storage and open the popup to request it (only if it is not the requested address).
const isAllowed = connect.allowed.includes(origin)
const allowed = connect.allowed || []
const request = connect.request || []

const isAllowed = allowed.includes(origin)
const walletExists = wallet.address
const alreadyRequested = [
...connect.request,
...connect.allowed,
].includes(origin)
const alreadyRequested = [...request, ...allowed].includes(origin)

if (isAllowed && walletExists) {
sendResponse(true, wallet)
Expand All @@ -225,7 +227,7 @@ async function setupStationProvider() {
} else {
!alreadyRequested &&
browser.storage.local.set({
connect: { ...connect, request: [origin, ...connect.request] },
connect: { ...connect, request: [origin, ...request] },
})

openPopup()
Expand Down Expand Up @@ -268,7 +270,7 @@ async function setupStationProvider() {
// - send back the response and close the popup.
// 2. If not,
// - store the address on the storage and open the popup to request it (only if it is not the requested address).
const isAllowed = connect.allowed.includes(origin)
const isAllowed = (connect.allowed || []).includes(origin)
const hasPubKey = wallet.pubkey

if (isAllowed && hasPubKey) {
Expand Down Expand Up @@ -350,7 +352,11 @@ function setupEvents() {
// if replaceKeplr changed, refresh the page
browser.storage.onChanged.addListener((changes, namespace) => {
if (namespace === "local") {
// if replaceKeplr changed, refresh the page
if (changes.replaceKeplr) {
console.warn(
"🛰️ STATION: Reloading window to set Station Extension as the default wallet."
)
window.location.reload()
}
}
Expand Down
5 changes: 4 additions & 1 deletion scripts/inpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ if (
window.interchainWallets = [STATION_INFO]
}

window.station = new Station()
Object.defineProperty(window, 'station', {
value: new Station(),
writable: false
});
30 changes: 24 additions & 6 deletions scripts/keplr.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import Station from "@terra-money/station-connector"

function injectKeplr() {
window.station = new Station()
const station = new Station()

window.getOfflineSigner = window.station.getOfflineSigner
try {
Object.defineProperty(window, "getOfflineSigner", {
value: station.getOfflineSigner,
writable: false,
})

window.getOfflineSignerOnlyAmino = window.station.getOfflineSigner
Object.defineProperty(window, "getOfflineSignerOnlyAmino", {
value: station.getOfflineSigner,
writable: false,
})

window.getOfflineSignerAuto = async (chainID) =>
window.station.getOfflineSigner(chainID)
Object.defineProperty(window, "getOfflineSignerAuto", {
value: async (chainID) => station.getOfflineSigner(chainID),
writable: false,
})

window.keplr = window.station.keplr
Object.defineProperty(window, "keplr", {
value: station.keplr,
writable: false,
})
} catch (e) {
// another wallet has already set one of the previous proprety as read-only
console.error(
"🛰️ STATION: Unable to set Station Extension as the default wallet."
)
}
}

injectKeplr()
Expand Down
85 changes: 0 additions & 85 deletions src/app/App.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/InitTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const InitTheme = () => {

useEffect(() => {
setTheme(valid ? theme : DefaultTheme)
}, [valid, theme, setTheme])
}, [valid]) // eslint-disable-line

return null
}
Expand Down
Loading

0 comments on commit 5b6388d

Please sign in to comment.