Skip to content

Commit 24e9d1f

Browse files
authored
feat/552 - Updates to integrations, better support chain ID updates (#554)
* fix: bump versions to 0.2.0 * fix: hook up staking to chain state * fix: index integrations and accounts by something other than chain ID * fix: ibc updates * fix: index extension connect status by chain key, fix ledger reveal pk * fix: ui clean up * fix: return chainKey in accounts query to properly map in interface * fix: version bump 0.2.1, hook up staking & proposals
1 parent 788a89b commit 24e9d1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+445
-615
lines changed

apps/airdrop/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"lint:fix": "npx yarn lint -- --fix"
1919
},
2020
"dependencies": {
21-
"@namada/components": "0.1.0",
22-
"@namada/hooks": "0.1.0",
23-
"@namada/utils": "0.1.0",
21+
"@namada/components": "0.2.1",
22+
"@namada/hooks": "0.2.1",
23+
"@namada/utils": "0.2.1",
2424
"buffer": "^6.0.3",
2525
"dompurify": "^3.0.2",
2626
"gsap": "^3.12.2",

apps/extension/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@namada/extension",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Namada Browser Extension",
55
"repository": "https://github.com/anoma/namada-interface/",
66
"author": "Heliax Dev <[email protected]>",
@@ -36,13 +36,13 @@
3636
"@ledgerhq/hw-transport": "^6.30.0",
3737
"@ledgerhq/hw-transport-webhid": "^6.28.0",
3838
"@ledgerhq/hw-transport-webusb": "^6.28.0",
39-
"@namada/chains": "0.1.0",
40-
"@namada/components": "0.1.0",
41-
"@namada/crypto": "0.1.0",
42-
"@namada/shared": "0.1.0",
43-
"@namada/storage": "0.1.0",
44-
"@namada/types": "0.1.0",
45-
"@namada/utils": "0.1.0",
39+
"@namada/chains": "0.2.1",
40+
"@namada/components": "0.2.1",
41+
"@namada/crypto": "0.2.1",
42+
"@namada/shared": "0.2.1",
43+
"@namada/storage": "0.2.1",
44+
"@namada/types": "0.2.1",
45+
"@namada/utils": "0.2.1",
4646
"@zondax/ledger-namada": "^0.0.3",
4747
"bignumber.js": "^9.1.1",
4848
"buffer": "^6.0.3",

apps/extension/src/App/Accounts/AddAccount.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback, useEffect, useState } from "react";
22
import { useNavigate } from "react-router-dom";
33

4-
import { chains, defaultChainId } from "@namada/chains";
4+
import { chains } from "@namada/chains";
55
import { ActionButton, Input, Toggle } from "@namada/components";
66
import { AccountType, DerivedAccount } from "@namada/types";
77
import { makeBip44Path } from "@namada/utils";
@@ -147,7 +147,7 @@ const AddAccount: React.FC<Props> = ({
147147

148148
const bip44Prefix = "m/44";
149149
const zip32Prefix = "m/32";
150-
const { coinType } = chains[defaultChainId].bip44;
150+
const { coinType } = chains.namada.bip44;
151151

152152
const authorize = useAuth(requester);
153153

@@ -207,7 +207,7 @@ const AddAccount: React.FC<Props> = ({
207207
index,
208208
};
209209
const bip44PathString = makeBip44Path(
210-
chains[defaultChainId].bip44.coinType,
210+
chains.namada.bip44.coinType,
211211
bip44Path
212212
);
213213

@@ -383,9 +383,8 @@ const AddAccount: React.FC<Props> = ({
383383

384384
<div className="text-sm text-neutral-400">
385385
Derivation path:{" "}
386-
<span>{`${parentDerivationPath}${
387-
isTransparent ? `${change}/` : ""
388-
}${index}`}</span>
386+
<span>{`${parentDerivationPath}${isTransparent ? `${change}/` : ""
387+
}${index}`}</span>
389388
</div>
390389

391390
<div className="text-xs py-1 text-red-500">{validation}</div>

apps/extension/src/Approvals/ApproveTx/ConfirmLedgerTx.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { toBase64 } from "@cosmjs/encoding";
22
import BigNumber from "bignumber.js";
33
import { useCallback, useEffect, useState } from "react";
44

5-
import { defaultChainId as chainId } from "@namada/chains";
65
import { ActionButton, Alert, Stack } from "@namada/components";
76
import { TxType, TxTypeLabel } from "@namada/shared";
87
import { Message, Tokens, TxMsgValue, TxProps } from "@namada/types";
@@ -19,6 +18,7 @@ import {
1918
SubmitSignedTxMsg,
2019
} from "background/ledger";
2120
import { useRequester } from "hooks/useRequester";
21+
import { GetChainMsg } from "provider";
2222
import { Ports } from "router";
2323
import { closeCurrentTab } from "utils";
2424

@@ -44,11 +44,16 @@ export const ConfirmLedgerTx: React.FC<Props> = ({ details }) => {
4444
"Public key not found! Review and approve reveal pk on your Ledger"
4545
);
4646

47+
const chain = await requester.sendMessage(
48+
Ports.Background,
49+
new GetChainMsg()
50+
);
51+
4752
const txArgs: TxProps = {
4853
token: Tokens.NAM.address || "",
4954
feeAmount: new BigNumber(0),
5055
gasLimit: new BigNumber(20_000),
51-
chainId,
56+
chainId: chain.chainId,
5257
publicKey,
5358
};
5459

apps/extension/src/background/chains/service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { chains, defaultChainId } from "@namada/chains";
1+
import { chains } from "@namada/chains";
22
import { KVStore } from "@namada/storage";
33
import { Chain } from "@namada/types";
44
import { ExtensionBroadcaster } from "extension";
@@ -9,13 +9,13 @@ export class ChainsService {
99
constructor(
1010
protected readonly chainsStore: KVStore<Chain>,
1111
protected readonly broadcaster: ExtensionBroadcaster
12-
) {}
12+
) { }
1313

14-
async getChain(): Promise<Chain | undefined> {
14+
async getChain(): Promise<Chain> {
1515
const chain = await this.chainsStore.get(CHAINS_KEY);
1616
if (!chain) {
1717
// Initialize default chain in storage
18-
const defaultChain = chains[defaultChainId];
18+
const defaultChain = chains.namada;
1919
await this.chainsStore.set(CHAINS_KEY, defaultChain);
2020
return defaultChain;
2121
}

apps/extension/src/background/keyring/keyring.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { deserialize } from "@dao-xyz/borsh";
22

3-
import { chains, defaultChainId } from "@namada/chains";
3+
import { chains } from "@namada/chains";
44
import {
55
HDWallet,
66
Mnemonic,
@@ -191,7 +191,7 @@ export class KeyRing {
191191
const phrase = accountSecret.seedPhrase.join(" ");
192192
const mnemonic = Mnemonic.from_phrase(phrase);
193193
const seed = mnemonic.to_seed();
194-
const { coinType } = chains[defaultChainId].bip44;
194+
const { coinType } = chains.namada.bip44;
195195
const bip44Path = makeBip44PathArray(coinType, path);
196196
const hdWallet = new HDWallet(seed);
197197
const key = hdWallet.derive(new Uint32Array(bip44Path));
@@ -262,7 +262,7 @@ export class KeyRing {
262262
path: Bip44Path,
263263
parentId: string
264264
): DerivedAccountInfo {
265-
const { coinType } = chains[defaultChainId].bip44;
265+
const { coinType } = chains.namada.bip44;
266266
const derivationPath = makeBip44PathArray(coinType, path);
267267
const hdWallet = new HDWallet(seed);
268268
const key = hdWallet.derive(new Uint32Array(derivationPath));
@@ -619,7 +619,7 @@ export class KeyRing {
619619
throw new Error(`Account for ${address} not found!`);
620620
}
621621
const { path } = accountStore;
622-
const { coinType } = chains[defaultChainId].bip44;
622+
const { coinType } = chains.namada.bip44;
623623
const bip44Path = makeBip44PathArray(coinType, path);
624624

625625
const sensitiveProps =

apps/extension/src/background/keyring/service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export class KeyRingService {
259259
): Promise<void> {
260260
const offscreenDocumentPath = "offscreen.html";
261261
const routerId = await getNamadaRouterId(this.extensionStore);
262+
const rpc = await this.sdkService.getRpc();
262263

263264
if (!(await hasOffscreenDocument(offscreenDocumentPath))) {
264265
await createOffscreenWithTxWorker(offscreenDocumentPath);
@@ -268,7 +269,7 @@ export class KeyRingService {
268269
type: SUBMIT_TRANSFER_MSG_TYPE,
269270
target: OFFSCREEN_TARGET,
270271
routerId,
271-
data: { transferMsg, txMsg, msgId, signingKey },
272+
data: { transferMsg, txMsg, msgId, signingKey, rpc },
272273
});
273274

274275
if (result?.error) {
@@ -284,12 +285,14 @@ export class KeyRingService {
284285
msgId: string,
285286
signingKey: SigningKey
286287
): Promise<void> {
288+
const rpc = await this.sdkService.getRpc();
287289
initSubmitTransferWebWorker(
288290
{
289291
transferMsg,
290292
txMsg,
291293
msgId,
292294
signingKey,
295+
rpc,
293296
},
294297
this.handleTransferCompleted.bind(this)
295298
);

apps/extension/src/background/ledger/ledger.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import TransportUSB from "@ledgerhq/hw-transport-webusb";
2-
import TransportHID from "@ledgerhq/hw-transport-webhid";
31
import Transport from "@ledgerhq/hw-transport";
2+
import TransportHID from "@ledgerhq/hw-transport-webhid";
3+
import TransportUSB from "@ledgerhq/hw-transport-webusb";
44

5+
import { toHex } from "@cosmjs/encoding";
6+
import { chains } from "@namada/chains";
7+
import { makeBip44Path } from "@namada/utils";
58
import {
9+
LedgerError,
610
NamadaApp,
711
ResponseAppInfo,
812
ResponseSign,
913
ResponseVersion,
10-
LedgerError,
1114
} from "@zondax/ledger-namada";
12-
import { defaultChainId, chains } from "@namada/chains";
13-
import { makeBip44Path } from "@namada/utils";
14-
import { toHex } from "@cosmjs/encoding";
1515

16-
const namadaChain = chains[defaultChainId];
17-
const { coinType } = namadaChain.bip44;
16+
const { coinType } = chains.namada.bip44;
1817

1918
export const initLedgerUSBTransport = async (): Promise<Transport> => {
2019
return await TransportUSB.create();
@@ -31,7 +30,7 @@ export const DEFAULT_LEDGER_BIP44_PATH = makeBip44Path(coinType, {
3130
});
3231

3332
export class Ledger {
34-
constructor(public readonly namadaApp: NamadaApp | undefined = undefined) {}
33+
constructor(public readonly namadaApp: NamadaApp | undefined = undefined) { }
3534

3635
/**
3736
* Returns an initialized Ledger class instance with initialized Transport
@@ -78,9 +77,8 @@ export class Ledger {
7877
}
7978

8079
const path = bip44Path || DEFAULT_LEDGER_BIP44_PATH;
81-
const { address, publicKey } = await this.namadaApp.getAddressAndPubKey(
82-
path
83-
);
80+
const { address, publicKey } =
81+
await this.namadaApp.getAddressAndPubKey(path);
8482

8583
return {
8684
// Return address as bech32-encoded string
@@ -100,9 +98,8 @@ export class Ledger {
10098
const path = bip44Path || DEFAULT_LEDGER_BIP44_PATH;
10199

102100
try {
103-
const { address, publicKey } = await this.namadaApp.showAddressAndPubKey(
104-
path
105-
);
101+
const { address, publicKey } =
102+
await this.namadaApp.showAddressAndPubKey(path);
106103

107104
return {
108105
// Return address as bech32-encoded string

apps/extension/src/background/ledger/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fromBase64 } from "@cosmjs/encoding";
22
import { deserialize } from "@dao-xyz/borsh";
33

4-
import { chains, defaultChainId } from "@namada/chains";
4+
import { chains } from "@namada/chains";
55
import { TxType } from "@namada/shared";
66
import { KVStore } from "@namada/storage";
77
import { AccountType, TxMsgValue } from "@namada/types";
@@ -31,7 +31,7 @@ export class LedgerService {
3131
async getRevealPKBytes(
3232
txMsg: string
3333
): Promise<{ bytes: Uint8Array; path: string }> {
34-
const { coinType } = chains[defaultChainId].bip44;
34+
const { coinType } = chains.namada.bip44;
3535

3636
try {
3737
// Deserialize txMsg to retrieve source
@@ -154,7 +154,7 @@ export class LedgerService {
154154

155155
const { txMsg, specificMsg } = storeResult;
156156

157-
const { coinType } = chains[defaultChainId].bip44;
157+
const { coinType } = chains.namada.bip44;
158158

159159
try {
160160
// Query account from Ledger storage to determine path for signer

apps/extension/src/background/offscreen/offscreen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const SW_TTL = 20000;
2222
// sent using sendResponse; false otherwise.
2323
function handleMessages(
2424
submitTransferMessage: SubmitTransferMessage,
25-
sender: unknown,
25+
_sender: unknown,
2626
sendResponse: (response?: unknown) => void
2727
): boolean {
2828
const { data, type, routerId, target } = submitTransferMessage;

0 commit comments

Comments
 (0)