Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sync-8.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmerz committed Feb 20, 2024
2 parents e31c538 + aa749b2 commit e5672a8
Show file tree
Hide file tree
Showing 33 changed files with 397 additions and 23,760 deletions.
23,686 changes: 28 additions & 23,658 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"@terra-money/ledger-station-js": "^1.3.7",
"@terra-money/log-finder-ruleset": "^3.0.3",
"@terra-money/msg-reader": "^3.0.1",
"@terra-money/station-connector": "^1.0.12",
"@terra-money/station-ui": "^1.0.4",
"@terra-money/terra-utils": "^1.2.0-beta.7",
"@terra-money/station-ui": "file:../station-ui/terra-money-station-ui-1.0.4.tgz",
"@terra-money/station-connector": "^1.0.17-beta.6",
"@terra-money/terra-utils": "^1.2.0-beta.8",
"@terra-money/terra.js": "^3.1.9",
"@terra-money/terra.proto": "^2.0.0",
"@terra-money/wallet-kit": "^1.0.15",
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": "8.0.5.3",
"version_name": "8.0.5.3",
"version": "8.0.6",
"version_name": "8.0.6",
"background": {
"service_worker": "background.js"
},
Expand Down
8 changes: 7 additions & 1 deletion src/app/components/HeaderIconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ const HeaderIconButton = forwardRef(
return (
// wrap for tooltip
<span className={styles.wrapper}>
<button type="button" {...attrs} className={styles.button} ref={ref} />
<button
type="button"
{...attrs}
className={styles.button}
ref={ref}
data-testid="dashboard-button"
/>
</span>
)
}
Expand Down
15 changes: 12 additions & 3 deletions src/app/sections/settings/NetworkSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,32 @@ const NetworkSetting = () => {
if (!networkOptions) return null

return (
<FlexColumn gap={40} justify="flex-start">
<FlexColumn gap={30} data-testid="network-settings">
<SettingsSelector
accordion
options={networkOptions}
value={network}
onChange={setNetwork}
data-testid="network-options-selector"
/>
<NavButton
icon={
<BuyIcon width={14} height={14} fill={"var(--token-light-white)"} />
}
label="Add Custom LCD Endpoint"
onClick={() => navigate("/preferences/network/lcd")}
data-testid="add-custom-lcd-button"
/>
{!!list.length && (
<>
<SectionHeader title="Custom LCD Endpoints" withLine />
{list.map((i) => (
<SectionHeader
title="Custom LCD Endpoints"
withLine
data-testid="custom-lcd-section-header"
/>
{list.map((i, index) => (
<AddressSelectableListItem
key={index}
active
subLabel={i.lcd ?? ""}
chain={i.chain}
Expand All @@ -55,6 +62,8 @@ const NetworkSetting = () => {
state: { chainID: i.chainID },
})
}
data-testid={`address-selectable-list-item-${index}`}
data-debug="true"
/>
))}
</>
Expand Down
1 change: 1 addition & 0 deletions src/app/sections/settings/SettingsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const SettingsButton = () => {
width={18}
height={18}
onClick={() => navigate("/preferences")}
data-testid="settings-button"
fill={"var(--token-dark-900)"}
/>
</button>
Expand Down
88 changes: 84 additions & 4 deletions src/auth/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Tx,
isTxError,
SeedKey,
Key,
} from "@terra-money/feather.js"
import { AccAddress, SignDoc } from "@terra-money/feather.js"
import { RawKey, SignatureV2 } from "@terra-money/feather.js"
Expand All @@ -24,7 +25,7 @@ import legacyEncrypt from "../scripts/encrypt"
import { encrypt } from "../scripts/aes"
import useAvailable from "./useAvailable"
import { addressFromWords } from "utils/bech32"
import { useNetwork } from "./useNetwork"
import { useAllNetworks, useNetwork } from "./useNetwork"
import { useLedgerKey } from "utils/ledger"
import { useLogin } from "extension/modules/Login"

Expand All @@ -36,6 +37,7 @@ export const walletState = atom({
const useAuth = () => {
const lcd = useInterchainLCDClient()
const networks = useNetwork()
const allNetworks = useAllNetworks()
const available = useAvailable()
const { isLoggedIn } = useLogin()

Expand Down Expand Up @@ -297,8 +299,13 @@ const useAuth = () => {
}
}

const signBytes = (bytes: Buffer, password = "") => {
const signBytes = (
bytes: Buffer,
chainID: string | undefined,
password = ""
) => {
if (!wallet) throw new Error("Wallet is not defined")
const requestedCointype = allNetworks[chainID ?? ""]?.coinType

if (is.ledger(wallet)) {
throw new Error("Ledger can not sign arbitrary data")
Expand All @@ -309,7 +316,7 @@ const useAuth = () => {
if ("seed" in pk) {
const key = new SeedKey({
seed: Buffer.from(pk.seed, "hex"),
coinType: pk.legacy ? 118 : 330,
coinType: Number(requestedCointype) || (pk.legacy ? 118 : 330),
index: pk.index || 0,
})
const { signature, recid } = key.ecdsaSign(bytes)
Expand All @@ -320,7 +327,12 @@ const useAuth = () => {
public_key: key.publicKey?.toAmino().value as string,
}
} else {
const key = new RawKey(Buffer.from(pk["330"], "hex"))
const rawkey = pk[requestedCointype ?? "330"]
if (!rawkey)
throw new Error(
"The requested cointype is not available for the current wallet."
)
const key = new RawKey(Buffer.from(rawkey, "hex"))
const { signature, recid } = key.ecdsaSign(bytes)
if (!signature) throw new Error("Signature is undefined")
return {
Expand All @@ -332,6 +344,73 @@ const useAuth = () => {
}
}

const signArbitrary = async (
bytes: Buffer,
chainID: string | undefined,
password = ""
) => {
if (!wallet) throw new Error("Wallet is not defined")
if (!chainID)
throw new Error("A chainID must be specified for ADR-036 signatures.")

const requestedCointype = allNetworks[chainID]?.coinType ?? 330
const requestedPrefix = allNetworks[chainID]?.prefix ?? "terra"

let key: Key

if (is.ledger(wallet)) {
key = await getLedgerKey(requestedCointype)
} else {
const pk = getKey(password)
if (!pk) throw new Error("Incorrect password")

if ("seed" in pk) {
key = new SeedKey({
seed: Buffer.from(pk.seed, "hex"),
coinType:
pk.legacy && parseInt(requestedCointype) === 330
? 118
: parseInt(requestedCointype),
index: pk.index || 0,
})
} else {
if (!pk[requestedCointype]) throw new Error("Incorrect password")

key = new RawKey(Buffer.from(pk[requestedCointype] ?? "", "hex"))
}
}

return await key.signTx(
Tx.fromAmino({
type: "cosmos-sdk/StdTx",
value: {
msg: [
{
type: "sign/MsgSignData",
value: {
signer: key.accAddress(requestedPrefix),
data: bytes.toString("base64"),
},
},
],
fee: {
amount: [],
gas: "0",
},
memo: "",
signatures: [],
timeout_height: "",
},
}),
{
accountNumber: 0,
sequence: 0,
chainID: "",
signMode: SignatureV2.SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
}
)
}

const post = async (
txOptions: CreateTxOptions,
password = "",
Expand Down Expand Up @@ -374,6 +453,7 @@ const useAuth = () => {
createSignature,
create,
signBytes,
signArbitrary,
sign,
post,
getPubkey,
Expand Down
41 changes: 25 additions & 16 deletions src/auth/modules/create/CreateMultisigWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,33 @@ const CreateMultisigWalletForm = ({ onCreated, onPubkey, onBack }: Props) => {

<MultiInputWrapper label={t("Wallets")} layout="vertical">
{fields.map(({ id }, index) => (
<Input
{...register(`addresses.${index}.value`, {
validate: validate.address,
})}
placeholder={truncate(SAMPLE_ADDRESS, [14, 5])}
key={id}
actionIcon={
fields.length > 2
? {
icon: <DeleteOutlineIcon />,
onClick: () => remove(index),
}
: undefined
}
/>
<div data-testid={`wallet-input-container-${index}`}>
{" "}
{/* Wrapper with data-testid */}
<Input
{...register(`addresses.${index}.value`, {
validate: validate.address,
})}
placeholder={truncate(SAMPLE_ADDRESS, [14, 5])}
key={id}
data-testid={`wallet-input-${index}`} // data-testid for the Input
actionIcon={
fields.length > 2
? {
icon: <DeleteOutlineIcon />,
onClick: () => remove(index),
}
: undefined
}
/>
</div>
))}

<Button variant="dashed" onClick={() => append({ value: "" })}>
<Button
variant="dashed"
onClick={() => append({ value: "" })}
data-testid="add-wallet-button"
>
{t("Add Wallet Address")}
</Button>
</MultiInputWrapper>
Expand Down
5 changes: 4 additions & 1 deletion src/auth/modules/create/CreateWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const CreateWalletForm = () => {
{...register("name", { validate: validate.name })}
autoFocus
placeholder="e.g. 'my-wallet'"
data-testid="wallet-name-input"
/>
</InputWrapper>

Expand All @@ -251,7 +252,7 @@ const CreateWalletForm = () => {
<Value>{mnemonic}</Value>
</InputWrapper>

<Grid gap={4}>
<Grid gap={4} data-testid="recovery-phrase-grid">
<Banner
variant="warning"
title={t(
Expand All @@ -264,6 +265,7 @@ const CreateWalletForm = () => {
{...register("checked", { required: true })}
checked={!!checked}
label={t("I have written down the recovery phrase")}
data-testid="recovery-phrase-checkbox"
/>
</>
) : (
Expand Down Expand Up @@ -304,6 +306,7 @@ const CreateWalletForm = () => {
disabled={!isValid}
variant={"primary"}
className={styles.submit__button}
data-testid="submit-button"
>
{generated ? t("Create Wallet") : t("Import")}
</SubmitButton>
Expand Down
5 changes: 3 additions & 2 deletions src/auth/modules/create/CreatedWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ const CreatedWallet = ({ name, words, onConfirm }: Props) => {
}

return (
<Grid gap={40}>
<Grid gap={40} data-testid="grid-container">
<SummaryHeader
statusLabel={t("Success!")}
statusMessage={t("The wallet was created")}
status={"success"}
summaryTitle={name}
summaryValue={address}
data-testid="summary-header"
/>
<Button variant="primary" onClick={submit}>
<Button variant="primary" onClick={submit} data-testid="submit-button">
{t("Done")}
</Button>
</Grid>
Expand Down
14 changes: 10 additions & 4 deletions src/auth/modules/create/SelectAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ const SelectAddress = () => {
const length = coins.length

return (
<section className={styles.selector__container}>
<div className={styles.selector__title}>
<h1>m/44'/{bip}'</h1>
<h4>{truncate(address)}</h4>
<section
className={styles.selector__container}
data-testid={`details-section-${bip}`}
>
<div
className={styles.selector__title}
data-testid={`title-div-${bip}`}
>
<h1 data-testid={`bip-title-${bip}`}>m/44'/{bip}'</h1>
<h4 data-testid={`address-title-${bip}`}>{truncate(address)}</h4>
</div>

<div className={styles.selector__details}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/layout/SettingsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const SettingsSelector = ({

return (
<FlexColumn align="stretch" justify="flex-start">
<RadioList>
<RadioList data-testid="radio-list">
{options.map(({ value, label }, index) => (
<RadioListItem
key={value}
label={label}
checked={value === selectedOption}
onClick={() => onChange(value)}
data-testid={`radio-list-item-${index}`}
data-debug="true"
{...(accordion && {
isOpen: openAcc === index,
setOpenAcc: () =>
Expand Down
8 changes: 7 additions & 1 deletion src/data/queries/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ export const useTxActivity = () => {
)

result.forEach((tx, i) => {
if (discarededTxsHashes.includes(tx.txhash)) return
if (
discarededTxsHashes.includes(tx.txhash) ||
!!tx.logs.find((log) =>
log.events.find((e) => e.type === "timeout_packet")
)
)
return

const senderDetails = getIbcTxDetails(tx)

Expand Down
Loading

0 comments on commit e5672a8

Please sign in to comment.