Skip to content

Commit

Permalink
Merge pull request #62 from leapwallet/main
Browse files Browse the repository at this point in the history
Release v0.1.24 wallet adapter
  • Loading branch information
baryon2 authored Oct 6, 2023
2 parents bc10434 + 2312acd commit af8f4f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/cosmos-snap-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@leapwallet/cosmos-snap-provider",
"version": "0.1.23",
"version": "0.1.24",
"repository": {
"url": "[email protected]:leapwallet/cosmos-metamask-snap.git"
},
Expand Down
34 changes: 19 additions & 15 deletions packages/cosmos-snap-provider/src/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import Long from 'long';
import { defaultSnapOrigin } from './config';
import Chains from './constants/chainInfo';
import { getGasPriceForChainName } from './helper/gas';
import { ChainInfo, GetSnapsResponse, SignAminoOptions, Snap, StdSignDoc, SuggestChainOptions } from './types';
import {
ChainInfo,
GetSnapsResponse,
SignAminoOptions,
Snap,
StdSignDoc,
SuggestChainOptions,
} from './types';

/**
* The fool proof version of getting the ethereum provider suggested by
Expand Down Expand Up @@ -165,21 +172,16 @@ export const requestSignAmino = async (
signDoc: StdSignDoc,
options?: SignAminoOptions,
) => {
const { isADR36 = false } = options || {};

const {
isADR36 = false
} = options || {};

if (chainId !== signDoc.chain_id) {
if (!isADR36 && chainId !== signDoc.chain_id) {
throw new Error('Chain ID does not match signer chain ID');
}

const chain = Chains[chainId as keyof typeof Chains];
// Override gasPrice
if (!options?.preferNoSetFee && chain && chain.denom) {
const gasPriceFromRegistry = await getGasPriceForChainName(
chain.chainName,
);
const gasPriceFromRegistry = await getGasPriceForChainName(chain.chainName);
const gas: any =
'gasLimit' in signDoc.fee ? signDoc.fee.gasLimit : signDoc.fee.gas;
if (gasPriceFromRegistry) {
Expand Down Expand Up @@ -224,20 +226,22 @@ export const isLocalSnap = (snapId: string) => snapId.startsWith('local:');

export const suggestChain = async (
chainInfo: ChainInfo,
options: SuggestChainOptions
options: SuggestChainOptions,
): Promise<{ message: string; chainInfo: ChainInfo }> => {

if(options && options.force) {
if (options && options.force) {
return await sendReqToSnap('suggestChain', {
chainInfo,
});
}

const supportedChains = await sendReqToSnap('getSupportedChains', {}) || {};
const supportedChains = (await sendReqToSnap('getSupportedChains', {})) || {};
if (supportedChains[chainInfo.chainId]) {
return Promise.resolve({ message: 'Chain already added successfully', chainInfo });
return Promise.resolve({
message: 'Chain already added successfully',
chainInfo,
});
}

return await sendReqToSnap('suggestChain', {
chainInfo,
});
Expand Down

0 comments on commit af8f4f8

Please sign in to comment.