Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main #22

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cosmsnap/snap",
"version": "0.1.16",
"version": "0.1.17",
"description": "The Cosmos extension for your Metamask wallet.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@cosmjs/proto-signing": "^0.30.1",
"@cosmjs/stargate": "^0.30.1",
"@cosmjs/stargate": "^0.31.1",
"@metamask/snaps-types": "^0.32.2",
"@metamask/snaps-ui": "^0.32.2",
"buffer": "^6.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "0.1.16",
"version": "0.1.17",
"description": "Cosmos Extension that adds Cosmos support to Metamask.",
"proposedName": "Cosmos Extension",
"repository": {
"type": "git",
"url": "https://github.com/cosmos/snap.git"
},
"source": {
"shasum": "G6BNnjUBiC+8a0LSrhRyG/mffBn3hYTTO2Uk1mk49I4=",
"shasum": "O3k1mxMGVbP98FqhLnd57TJxwMWUsG+W0YwDNMrJpnY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
]

signDocAmino.msgs.map(item => {
ui.push(heading(item.type)),
ui.push(text(JSON.stringify(bigintReplacer(item.value), null, 2))),
ui.push(divider())
uiAmino.push(heading(item.type)),
uiAmino.push(text(JSON.stringify(bigintReplacer(item.value), null, 2))),
uiAmino.push(divider())
});

// Ensure user confirms transaction
Expand Down
2 changes: 1 addition & 1 deletion packages/snapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cosmsnap/snapper",
"version": "0.1.25",
"version": "0.1.26",
"description": "A helper package with utilities to interact with the Cosmos Extension for MetaMask.",
"repository": {
"type": "git",
Expand Down
14 changes: 11 additions & 3 deletions packages/snapper/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface SnapProvider {
chainId: string,
tx: Uint8Array,
): Promise<DeliverTxResponse>;
getOfflineSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner;
getOfflineSigner(chainId: string, mode: string): OfflineAminoSigner & OfflineDirectSigner;
getKey(chainId: string): Promise<Key>
enable(): Promise<boolean>;
getChains(): Promise<Chain[]>;
Expand Down Expand Up @@ -169,7 +169,15 @@ export class CosmosSnap implements SnapProvider {
let res = await sendTx(chainId, tx, this.snap_id);
return res
}
getOfflineSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner {
return new CosmJSOfflineSigner(chainId, this.snap_id);
getOfflineSigner(chainId: string, mode = 'direct'): OfflineAminoSigner & OfflineDirectSigner {
if (mode == 'amino') {
let signer = new CosmJSOfflineSigner(chainId, this.snap_id);
signer.signDirect = undefined;
return signer
} else {
let signer = new CosmJSOfflineSigner(chainId, this.snap_id);
signer.signAmino = undefined;
return signer
}
}
}
3 changes: 2 additions & 1 deletion packages/snapper/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { AccountData, AminoSignResponse, StdSignDoc } from '@cosmjs/amino';
import { OfflineDirectSigner } from '@cosmjs/proto-signing';
import { getAccountInfo, signAmino, signDirect, DEFAULT_SNAP_ID } from './snap.js';
import Long from 'long';
import { OfflineAminoSigner } from '@cosmjs/amino';

export class CosmJSOfflineSigner implements OfflineDirectSigner {
export class CosmJSOfflineSigner implements OfflineDirectSigner, OfflineAminoSigner {
readonly chainId: string;
readonly snapId: string;

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@cosmjs/crypto": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@cosmsnap/snapper": "^0.1.25",
"@cosmsnap/snapper": "^0.1.26",
"@keplr-wallet/types": "0.12.12",
"@metamask/detect-provider": "^2.0.0",
"@sveltejs/adapter-node": "^1.3.1",
Expand Down
11 changes: 7 additions & 4 deletions packages/ui/src/components/Transfer.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { chains } from "../store/chains";
import Info from "./Info.svelte";
import { balances } from "../store/balances";
import { balances, forceUpdate } from "../store/balances";
import { getSkipRecommendation, getMsgs, type CoinIBC } from '../utils/ibc';
import { state } from "../store/state";
import type { Chain, Msg } from "@cosmsnap/snapper";
Expand All @@ -12,6 +12,7 @@
import ChainSelector from "./ChainSelector.svelte";
import { sendTxAlert } from "@cosmsnap/snapper";
import Select from "./Select.svelte";
import { snapId } from "../utils/snap";

let loading = false;
let source = "cosmoshub-4";
Expand Down Expand Up @@ -114,7 +115,8 @@

if (tx.code == 0) {
await addTransaction({address: fromAddress, chain: source, when: new Date().toLocaleString(), tx_hash: tx.transactionHash});
await sendTxAlert(source, tx.transactionHash);
await sendTxAlert(source, tx.transactionHash, snapId);
forceUpdate();
} else {
if (tx.rawLog) {
$state.alertText = tx.rawLog
Expand Down Expand Up @@ -160,11 +162,12 @@
typeUrl: item.msg_type_url
};
});
const tx = await window.cosmos.signAndBroadcast(source, messages, fees);
const tx = await client.signAndBroadcast(fromAddress, messages, fees);

if (tx.code == 0) {
await addTransaction({address: fromAddress, chain: source, when: new Date().toDateString(), tx_hash: tx.transactionHash});
//await sendTxAlert(source, tx.transactionHash);
await sendTxAlert(source, tx.transactionHash, snapId);
forceUpdate();
} else {
if (tx.rawLog) {
$state.alertText = tx.rawLog
Expand Down
16 changes: 0 additions & 16 deletions packages/ui/src/routes/fiat/+page.svelte

This file was deleted.

20 changes: 0 additions & 20 deletions packages/ui/src/routes/swap/+page.svelte

This file was deleted.

7 changes: 6 additions & 1 deletion packages/ui/src/store/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ export interface ChainBalances extends Chain {
// Store to hold a loading state
export const isLoading: Writable<boolean> = writable(false);

export let forceUpdate: () => void;

// The derived balances store
export const balances: Readable<ChainBalances[]> = derived(
chains,
($chains, set: (value: ChainBalances[]) => void) => {
forceUpdate = () => {
updateBalances($chains, set);
}
updateBalances($chains, set);
},
[] as ChainBalances[]
);

const updateBalances = async ($chains: Chain[], set: (value: ChainBalances[]) => void): Promise<void> => {
export const updateBalances = async ($chains: Chain[], set: (value: ChainBalances[]) => void): Promise<void> => {
isLoading.set(true);
try {
const res = await fetch(`${denoUrl}/balances`, {
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ __metadata:
languageName: node
linkType: hard

"@cosmsnap/snapper@npm:^0.1.25":
version: 0.1.25
resolution: "@cosmsnap/snapper@npm:0.1.25"
"@cosmsnap/snapper@npm:^0.1.26":
version: 0.1.26
resolution: "@cosmsnap/snapper@npm:0.1.26"
dependencies:
"@keplr-wallet/proto-types": 0.12.12
"@keplr-wallet/types": 0.12.12
ses: ^0.18.4
checksum: 65f23e43e880c1d8f2fff7f3716a7b178f5e0e1c963eb8753e93a0cbb5ba92b581417dd92c530c746132a44dc4fb34aab2fc9e49602d7280ba3c331f353ece4e
checksum: f549a790ea3867cdf973d691e2628f452c2bbf49a2a2997a6032be1ac74bed42d6c22929aa066bf2b73f191dc91fda309ba6a40716988e30056216a3ba9f530a
languageName: node
linkType: hard

Expand All @@ -280,7 +280,7 @@ __metadata:
dependencies:
"@cosmjs/crypto": ^0.31.1
"@cosmjs/stargate": ^0.31.1
"@cosmsnap/snapper": ^0.1.25
"@cosmsnap/snapper": ^0.1.26
"@fullhuman/postcss-purgecss": ^5.0.0
"@keplr-wallet/types": 0.12.12
"@metamask/detect-provider": ^2.0.0
Expand Down
71 changes: 1 addition & 70 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1679,16 +1679,6 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/json-rpc@npm:^0.30.1":
version: 0.30.1
resolution: "@cosmjs/json-rpc@npm:0.30.1"
dependencies:
"@cosmjs/stream": ^0.30.1
xstream: ^11.14.0
checksum: 750686d53cd4ee239fd24a41d556ab08307f099c9f7bb633a566af417b0baad0ff954498272b6bdb02d4cad596c7ac8f24e38f0cf25c7fbe6200b539c2f56266
languageName: node
linkType: hard

"@cosmjs/json-rpc@npm:^0.31.1":
version: 0.31.1
resolution: "@cosmjs/json-rpc@npm:0.31.1"
Expand Down Expand Up @@ -1798,18 +1788,6 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/socket@npm:^0.30.1":
version: 0.30.1
resolution: "@cosmjs/socket@npm:0.30.1"
dependencies:
"@cosmjs/stream": ^0.30.1
isomorphic-ws: ^4.0.1
ws: ^7
xstream: ^11.14.0
checksum: ef5e5d7bbcd89b5bfbd6fa4039133e15e5db848e6b0bc812b89872d28d9ced73d8a12fbf6581e6b0b08de28f2c1a9c7b05825804be65eb07d2f3d3532babea91
languageName: node
linkType: hard

"@cosmjs/socket@npm:^0.31.1":
version: 0.31.1
resolution: "@cosmjs/socket@npm:0.31.1"
Expand Down Expand Up @@ -1842,26 +1820,6 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/stargate@npm:^0.30.1":
version: 0.30.1
resolution: "@cosmjs/stargate@npm:0.30.1"
dependencies:
"@confio/ics23": ^0.6.8
"@cosmjs/amino": ^0.30.1
"@cosmjs/encoding": ^0.30.1
"@cosmjs/math": ^0.30.1
"@cosmjs/proto-signing": ^0.30.1
"@cosmjs/stream": ^0.30.1
"@cosmjs/tendermint-rpc": ^0.30.1
"@cosmjs/utils": ^0.30.1
cosmjs-types: ^0.7.1
long: ^4.0.0
protobufjs: ~6.11.3
xstream: ^11.14.0
checksum: 2eb089c4a7f995b787702d52f22e1c808704cd02c29ec4feee57897d350d9dbde645785e89bf34181da7acd67547dc2b0f17f9f49cfbb0272d70cb7f553a8644
languageName: node
linkType: hard

"@cosmjs/stargate@npm:^0.31.1":
version: 0.31.1
resolution: "@cosmjs/stargate@npm:0.31.1"
Expand Down Expand Up @@ -1891,15 +1849,6 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/stream@npm:^0.30.1":
version: 0.30.1
resolution: "@cosmjs/stream@npm:0.30.1"
dependencies:
xstream: ^11.14.0
checksum: f9e48a8377c2d3cfbf288fcf4fad745905c042dabc442d2cbb93d4280033e3c8e493a3328f58c0b645b60f9c2188d14603b2bb37a174bc0619686c5e70b13dca
languageName: node
linkType: hard

"@cosmjs/stream@npm:^0.31.1":
version: 0.31.1
resolution: "@cosmjs/stream@npm:0.31.1"
Expand Down Expand Up @@ -1927,24 +1876,6 @@ __metadata:
languageName: node
linkType: hard

"@cosmjs/tendermint-rpc@npm:^0.30.1":
version: 0.30.1
resolution: "@cosmjs/tendermint-rpc@npm:0.30.1"
dependencies:
"@cosmjs/crypto": ^0.30.1
"@cosmjs/encoding": ^0.30.1
"@cosmjs/json-rpc": ^0.30.1
"@cosmjs/math": ^0.30.1
"@cosmjs/socket": ^0.30.1
"@cosmjs/stream": ^0.30.1
"@cosmjs/utils": ^0.30.1
axios: ^0.21.2
readonly-date: ^1.0.0
xstream: ^11.14.0
checksum: 6900711886d2d9b02dd9ec17d341a174d7d2a20c432618e96d7f33fa6732dcb77fe21f37c67d452c09095f099260a679a4ac5de0caeec376cd683d3d12790ed8
languageName: node
linkType: hard

"@cosmjs/tendermint-rpc@npm:^0.31.1":
version: 0.31.1
resolution: "@cosmjs/tendermint-rpc@npm:0.31.1"
Expand Down Expand Up @@ -2023,7 +1954,7 @@ __metadata:
resolution: "@cosmsnap/snap@workspace:packages/snap"
dependencies:
"@cosmjs/proto-signing": ^0.30.1
"@cosmjs/stargate": ^0.30.1
"@cosmjs/stargate": ^0.31.1
"@keplr-wallet/proto-types": 0.12.12
"@lavamoat/allow-scripts": ^2.0.3
"@metamask/auto-changelog": ^2.6.0
Expand Down
Loading