Skip to content

Commit

Permalink
refactor: remove legacy clients (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Jul 15, 2024
1 parent 4c39407 commit 18da7ea
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 426 deletions.
2 changes: 0 additions & 2 deletions packages/adena-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
"dependencies": {
"@cosmjs/ledger-amino": "^0.32.4",
"@gnolang/gno-js-client": "1.3.0",
"@gnolang/gno-js-client-legacy": "npm:@gnolang/[email protected]",
"@gnolang/tm2-js-client": "1.2.1",
"@gnolang/tm2-js-client-legacy": "npm:@gnolang/[email protected]",
"@ledgerhq/hw-transport": "^6.30.4",
"@ledgerhq/hw-transport-mocker": "^6.28.4",
"@ledgerhq/hw-transport-webhid": "^6.28.4",
Expand Down
283 changes: 0 additions & 283 deletions packages/adena-module/src/utils/messages-legacy.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Provider,
TransactionEndpoint,
} from '@gnolang/tm2-js-client';
import { Wallet as Tm2WalletLegacy } from '@gnolang/tm2-js-client-legacy';
import { v4 as uuidv4 } from 'uuid';
import { Bip39, EnglishMnemonic } from '../../crypto';
import { useTm2Wallet, decodeTxMessages, Document, documentToTx, makeSignedTx } from './../..';
Expand Down Expand Up @@ -66,7 +65,7 @@ export class HDWalletKeyring implements Keyring {
return this.signByWallet(wallet, document);
}

private async signByWallet(wallet: Tm2Wallet | Tm2WalletLegacy, document: Document) {
private async signByWallet(wallet: Tm2Wallet, document: Document) {
const signedTx = await makeSignedTx(wallet, document);
return {
signed: signedTx,
Expand Down
19 changes: 4 additions & 15 deletions packages/adena-module/src/wallet/keyring/keyring-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ import { LedgerKeyring } from './ledger-keyring';
import { PrivateKeyKeyring } from './private-key-keyring';
import { Web3AuthKeyring } from './web3-auth-keyring';
import { Tx, Wallet as Tm2Wallet } from '@gnolang/tm2-js-client';
import { Wallet as Tm2WalletLegacy } from '@gnolang/tm2-js-client-legacy';
import { Document, documentToTx, decodeTxMessages } from './../../utils/messages';
import {
documentToTx as documentToTxLegacy,
decodeTxMessages as decodeTxMessagesLegacy,
} from './../../utils/messages-legacy';

const LEGACY_NETWORKS = ['test3'];

export function isHDWalletKeyring(keyring: Keyring): keyring is HDWalletKeyring {
return keyring.type === 'HD_WALLET';
Expand Down Expand Up @@ -49,17 +42,13 @@ export function hasPrivateKey(
return false;
}

export function useTm2Wallet(document: Document): typeof Tm2Wallet | typeof Tm2WalletLegacy {
if (LEGACY_NETWORKS.includes(document.chain_id)) {
return Tm2WalletLegacy;
}
export function useTm2Wallet(document: Document): typeof Tm2Wallet {
return Tm2Wallet;
}

export function makeSignedTx(wallet: Tm2Wallet | Tm2WalletLegacy, document: Document): Promise<Tx> {
const isLegacy = LEGACY_NETWORKS.includes(document.chain_id);
const tx = isLegacy ? documentToTxLegacy(document) : documentToTx(document);
const decodeTxMessageFunction = isLegacy ? decodeTxMessagesLegacy : decodeTxMessages;
export function makeSignedTx(wallet: Tm2Wallet, document: Document): Promise<Tx> {
const tx = documentToTx(document);
const decodeTxMessageFunction = decodeTxMessages;

return wallet.signTransaction(tx, decodeTxMessageFunction);
}
3 changes: 1 addition & 2 deletions packages/adena-module/src/wallet/keyring/ledger-keyring.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { v4 as uuidv4 } from 'uuid';
import { Provider, TransactionEndpoint, Wallet as Tm2Wallet } from '@gnolang/tm2-js-client';
import { Wallet as Tm2WalletLegacy } from '@gnolang/tm2-js-client-legacy';
import { Keyring, KeyringData, KeyringType } from './keyring';
import { generateHDPath, Tx } from '@gnolang/tm2-js-client';
import { LedgerConnector } from '@cosmjs/ledger-amino';
Expand Down Expand Up @@ -46,7 +45,7 @@ export class LedgerKeyring implements Keyring {
return this.signByWallet(wallet, document);
}

private async signByWallet(wallet: Tm2Wallet | Tm2WalletLegacy, document: Document) {
private async signByWallet(wallet: Tm2Wallet, document: Document) {
const signedTx = await makeSignedTx(wallet, document);
return {
signed: signedTx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Provider, TransactionEndpoint, Tx, Wallet as Tm2Wallet } from '@gnolang/tm2-js-client';
import { Wallet as Tm2WalletLegacy } from '@gnolang/tm2-js-client-legacy';
import { v4 as uuidv4 } from 'uuid';
import { Keyring, KeyringData, KeyringType } from './keyring';
import { Document, documentToTx, decodeTxMessages, useTm2Wallet, makeSignedTx } from './../..';
import { Document, useTm2Wallet, makeSignedTx } from './../..';

export class PrivateKeyKeyring implements Keyring {
public readonly id: string;
Expand Down Expand Up @@ -34,7 +33,7 @@ export class PrivateKeyKeyring implements Keyring {
return this.signByWallet(wallet, document);
}

private async signByWallet(wallet: Tm2Wallet | Tm2WalletLegacy, document: Document) {
private async signByWallet(wallet: Tm2Wallet, document: Document) {
const signedTx = await makeSignedTx(wallet, document);
return {
signed: signedTx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Provider, TransactionEndpoint, Tx, Wallet as Tm2Wallet } from '@gnolang/tm2-js-client';
import { Wallet as Tm2WalletLegacy } from '@gnolang/tm2-js-client-legacy';
import { v4 as uuidv4 } from 'uuid';

import { Keyring, KeyringData, KeyringType } from './keyring';
Expand Down Expand Up @@ -36,7 +35,7 @@ export class Web3AuthKeyring implements Keyring {
return this.signByWallet(wallet, document);
}

private async signByWallet(wallet: Tm2Wallet | Tm2WalletLegacy, document: Document) {
private async signByWallet(wallet: Tm2Wallet, document: Document) {
const signedTx = await makeSignedTx(wallet, document);
return {
signed: signedTx,
Expand Down
Loading

0 comments on commit 18da7ea

Please sign in to comment.