Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sync-8.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmerz committed Jan 12, 2024
2 parents 1b3e534 + 222ca25 commit fb25a5e
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 98 deletions.
Binary file modified public/icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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": "8.0.4",
"version_name": "8.0.4",
"version": "8.0.5",
"version_name": "8.0.5",
"background": {
"service_worker": "background.js"
},
Expand Down
41 changes: 25 additions & 16 deletions src/auth/scripts/keystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const isLoginNeeded = async () => {
if (!wallets) return false

if (shouldStorePassword()) {
return !(await getStoredPassword())
return !(await isLoggedIn()) && !(await getStoredPassword())
} else {
return !(await isLoggedIn())
}
Expand All @@ -118,26 +118,34 @@ export const passwordExists = () => {
return !!passwordChallenge
}

// unlocks the wallet when the user inset the password on the login screen
export const unlockWallets = (password: string) => {
const passwordChallenge = localStorage.getItem(
LocalStorage.PASSWORD_CHALLENGE
)
if (!passwordChallenge) return
if (decrypt(passwordChallenge, password) !== CHALLENGE_TEXT)
throw new Error("Incorrect password")

setLogin(true)
}

// checks if the given password is valid
export const isPasswordValid = (password: string) => {
const passwordChallenge = localStorage.getItem(
LocalStorage.PASSWORD_CHALLENGE
)

// if user has not set a password yet, it's valid
if (!passwordChallenge) return true
// [RECOVERY]: if password challenge has not been set
if (!passwordChallenge) {
const walletChallenge = getStoredWallets()
.map((w) => {
if ("encryptedSeed" in w) {
return w.encryptedSeed
} else if ("encrypted" in w) {
return w.encrypted[330]
}
})
.filter((w): w is string => !!w)

if (!walletChallenge.length) return false

try {
const isValid = !!decrypt(walletChallenge[0], password)
if (isValid) storePasswordChallenge(password)
return isValid
} catch {
return false
}
}

try {
return decrypt(passwordChallenge, password) === CHALLENGE_TEXT
Expand Down Expand Up @@ -290,7 +298,8 @@ type AddWalletParams =
| MultisigWallet

export const addWallet = (params: AddWalletParams, password: string) => {
if (!isPasswordValid(password)) throw new Error("Invalid password")
if (passwordExists() && !isPasswordValid(password))
throw new Error("Invalid password")
const wallets = getStoredWallets()

if (wallets.find((wallet) => wallet.name === params.name))
Expand Down
41 changes: 24 additions & 17 deletions src/data/queries/swap/skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,36 +139,43 @@ const getTimelineMessages = (
swap: SwapState,
network: IInterchainNetworks
) => {
let swapOccured = false
let swapsOccured = 0
const swapsRequired = route.operations.filter(
(op: any) => Object.keys(op)[0] === "swap"
).length


const timelineMsgs: TimelineMessage[] = route.operations.map(
// eslint-disable-next-line array-callback-return
(op: any, i: number) => {
const type = Object.keys(op)[0] as OperationType
const swapIn = route.operations[i + 1]?.swap?.swap_in
const swapOut = route.operations[i + 1]?.swap?.swap_out
const venue = (swapIn ?? swapOut)?.swap_venue

if (type === "transfer") {
const fromChainId = op[type].chain_id
const toChainId =
route.operations[i + 1]?.transfer?.chain_id ??
route.operations[i + 1]?.swap.swap_in.swap_venue.chain_id
return {
type,
symbol: swapOccured ? swap.askAsset.symbol : swap.offerAsset.symbol, // TODO: make robust against multiple swaps
from: network[fromChainId]?.name ?? "Unknown",
to: network[toChainId ?? swap.askAsset.chainId]?.name ?? "Unknown", // get final chainId from askAsset or next one in ops
}
const toChainId = venue?.chain_id
return {
type,
symbol: swapsOccured === swapsRequired ? swap.askAsset.symbol : swap.offerAsset.symbol,
from: network[fromChainId]?.name ?? "Unknown",
to: network[toChainId ?? swap.askAsset.chainId]?.name ?? "Unknown", // get final chainId from askAsset or next one in ops
}
}

if (type === "swap") {
swapOccured = true
return {
type,
venue: op[type].swap_in.swap_venue.name as SwapVenue,
askAssetSymbol: swap.askAsset.symbol,
offerAssetSymbol: swap.offerAsset.symbol,
swapsOccured++
if (venue?.name) {
return {
type,
venue: venue.name as SwapVenue,
askAssetSymbol: swap.askAsset.symbol,
offerAssetSymbol: swap.offerAsset.symbol,
}
}
}
}
)
return timelineMsgs
return timelineMsgs.filter(Boolean)
}
2 changes: 2 additions & 0 deletions src/data/queries/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ export interface SwapAssetExtra extends SwapAssetBase {
export enum SwapVenue {
OSMOSIS = "osmosis-poolmanager",
ASTROPORT = "terra-astroport",
NEUTRON = "neutron-astroport",
}

export const swapVenueToName = {
"osmosis-poolmanager": "Osmosis",
"terra-astroport": "Astroport",
"neutron-astroport": "Astroport",
}
export type SwapOperation = any[]

Expand Down
3 changes: 1 addition & 2 deletions src/extension/auth/MigrationWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ const MigrationWizard = () => {

return (
<ExtensionPage
img={icon}
title={t("Import wallets")}
title={t("Migrate wallets")}
subtitle={t(
"You will be required to migrate your accounts to Station v3. Please provide your password or recovery phrase for each wallet to proceed."
)}
Expand Down
4 changes: 4 additions & 0 deletions src/extension/auth/PasswordForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
createNewPassword,
getStoredPassword,
isPasswordValid,
passwordExists,
Expand Down Expand Up @@ -82,7 +83,10 @@ const PasswordForm = ({ onComplete, onCompleteLedger }: Props) => {
{ shouldFocus: true }
)
return
} else if (!passwordExists()) {
createNewPassword(password)
}

if (rememberPassword) {
setShouldStorePassword(true)
storePassword(password)
Expand Down
5 changes: 2 additions & 3 deletions src/extension/components/ExtensionFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { ExternalLink } from "components/general"
import styles from "./ExtensionFooter.module.scss"
import { useThemeFavicon } from "data/settings/Theme"
import browser from "webextension-polyfill"
import { StationIcon } from "@terra-money/station-ui"

export default function ExtensionFooter() {
const icon = useThemeFavicon()
const version = browser.runtime?.getManifest?.()?.version

return (
<footer className={styles.footer}>
<section className={styles.version}>
<img src={icon} alt="Station" width={16} />
<StationIcon width={16} height={16} />
<span> Station Wallet</span>
{version && ` v${version}`}
</section>
Expand Down
17 changes: 13 additions & 4 deletions src/extension/modules/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
isLoginNeeded,
isPasswordValid,
lockWallet,
setLogin,
setShouldStorePassword,
shouldStorePassword,
storePassword,
unlockWallets,
} from "auth/scripts/keystore"
import {
Checkbox,
Expand Down Expand Up @@ -50,12 +51,16 @@ export const useLogin = () => {
return {
isLoggedIn: loginState.isLoggedIn,
isLoading: loginState.isLoading,
login: (password: string) => {
unlockWallets(password)
login: (password: string): boolean => {
if (!isPasswordValid(password)) {
return false
}
setLogin(true)
setLoginState({
isLoading: false,
isLoggedIn: true,
})
return true
},
logout: () => {
lockWallet()
Expand Down Expand Up @@ -109,7 +114,11 @@ const Login = () => {
const submit = async () => {
try {
if (!password.current?.value) return setError("Password is required")
login(password.current?.value)
if (!login(password.current?.value)) {
setError("Invalid password")
setIsValid(false)
return
}

if (rememberPassword) {
setShouldStorePassword(true)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/activity/ActivityItem.module.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@import "mixins";

.activityitems > * {
padding: 8px;
margin: 10px 0px;
padding: 12px;
}

.activityitem {
Expand All @@ -23,6 +22,7 @@
.transaction__progress {
padding-top: 8px;
position: relative;
margin-left: 50px;

.transaction__timer {
transition: 300ms;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/wallet/Asset.module.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "mixins";

.asset {
padding: 10px;
padding: 12px;
border-radius: 10px;
position: relative; // to loading indicator
cursor: pointer;
Expand Down
6 changes: 4 additions & 2 deletions src/pages/wallet/AssetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const AssetPage = () => {
const [chain, denom] = routeDenom.includes("*")
? routeDenom.split("*")
: [params.chain, routeDenom]
const { token, symbol, decimals, icon } = readNativeDenom(denom, chain)

const tokenInfo = readNativeDenom(denom, chain)
const { token, symbol, decimals, icon } = tokenInfo
const unknownIBCDenoms = useUnknownIBCDenoms()
const navigate = useNavigate()

Expand Down Expand Up @@ -127,7 +129,7 @@ const AssetPage = () => {
)}
</h1>
</div>
<WalletActionButtons denom={token} />
<WalletActionButtons token={tokenInfo} />
</section>
)
}
Expand Down
11 changes: 6 additions & 5 deletions src/pages/wallet/SendPage/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import { useLocation } from "react-router-dom"

const Address = () => {
const { form, goToStep, getWalletName, networks } = useSend()
const { state } = useLocation()
const { state: denom } = useLocation()
const { recipients } = useRecentRecipients()
const { register, setValue, formState, watch, trigger } = form
const { errors } = formState
const { recipient } = watch()
const { t } = useTranslation()

useEffect(() => {
setValue("asset", state?.denom)
}, [state?.denom, setValue])
setValue("asset", denom) // pre-selected from asset page
}, [denom, setValue])

const [tab, setTab] = useState("wallets")

Expand All @@ -45,7 +45,8 @@ const Address = () => {
},
]

const handleKnownWallet = (recipient: AccAddress | WalletName) => {
const handleKnownWallet = (recipient: AccAddress | WalletName, _: number, memo?: string) => {
setValue("memo", memo)
if (!AccAddress.validate(recipient ?? "")) {
setValue("recipient", recipient)
goToStep(2)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/wallet/SendPage/Components/AddressBookList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const AddressBookList = ({
items: AddressBook[]
title?: string
icon?: ReactNode
onClick?: (address: string, index: number) => void
onClick?: (address: string, index: number, memo?: string) => void
}) => {
const network = useNetwork()
const { t } = useTranslation()
Expand All @@ -29,7 +29,7 @@ export const AddressBookList = ({
walletName={i.name}
walletAddress={truncate(i.recipient, [11, 6])}
chainIcon={network[getChainIdFromAddress(i.recipient, network)]?.icon}
onClick={() => onClick?.(i.recipient, index)}
onClick={() => onClick?.(i.recipient, index, i.memo)}
/>
))}
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/wallet/SendPage/Components/MyWallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAuth } from "auth"
import { ReactComponent as ActiveWalletIcon } from "styles/images/icons/ActiveWallet.svg"

interface MyWalletsProps {
onClick?: (address: string, index: number) => void
onClick?: (address: string, index: number, memo?: string) => void
tab: string
}

Expand Down
Loading

0 comments on commit fb25a5e

Please sign in to comment.