@cityofzion/bs-multichain 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,11 @@
1
+ import { IBlockchainService, IBSWithWalletConnect } from '@cityofzion/blockchain-service';
1
2
  import { ErrorResponse } from '@walletconnect/jsonrpc-utils';
2
3
  import type { PendingRequestTypes, SessionTypes } from '@walletconnect/types';
3
4
  import { SdkErrorKey } from '@walletconnect/utils';
4
- import { TWalletKitHelperFilterSessionsParams, TWalletKitHelperGetProposalDetailsParams, TWalletKitHelperGetSessionDetailsParams, TWalletKitHelperProcessRequestParams, TWalletKitHelperProposalDetails, TWalletKitHelperSessionDetails } from './types';
5
+ import { type TWalletKitHelperFilterSessionsParams, type TWalletKitHelperGetProposalDetailsParams, type TWalletKitHelperGetSessionDetailsParams, type TWalletKitHelperProcessRequestParams, type TWalletKitHelperProposalDetails, type TWalletKitHelperSessionDetails, type TWalletKitHelperGetProposalServicesParams } from './types';
5
6
  export declare class WalletKitHelper {
6
- static getProposalDetails<N extends string>({ address, proposal, services, }: TWalletKitHelperGetProposalDetailsParams<N>): TWalletKitHelperProposalDetails<N>;
7
+ static getProposalDetails<N extends string>({ address, proposal, service, }: TWalletKitHelperGetProposalDetailsParams<N>): TWalletKitHelperProposalDetails<N>;
8
+ static getProposalServices<N extends string>({ proposal, services }: TWalletKitHelperGetProposalServicesParams<N>): (IBlockchainService<N, string> & IBSWithWalletConnect)[];
7
9
  static getSessionDetails<N extends string>({ session, services, }: TWalletKitHelperGetSessionDetailsParams<N>): TWalletKitHelperSessionDetails<N>;
8
10
  static getError(key: SdkErrorKey): {
9
11
  message: string;
@@ -14,11 +14,10 @@ const blockchain_service_1 = require("@cityofzion/blockchain-service");
14
14
  const jsonrpc_utils_1 = require("@walletconnect/jsonrpc-utils");
15
15
  const utils_1 = require("@walletconnect/utils");
16
16
  class WalletKitHelper {
17
- static getProposalDetails({ address, proposal, services, }) {
17
+ static getProposalDetails({ address, proposal, service, }) {
18
18
  const mergedNamespacesObject = (0, utils_1.mergeRequiredAndOptionalNamespaces)(proposal.requiredNamespaces, proposal.optionalNamespaces);
19
19
  const allChains = new Set((0, utils_1.getChainsFromRequiredNamespaces)(mergedNamespacesObject));
20
- const service = services.find((service) => (0, blockchain_service_1.hasWalletConnect)(service) && allChains.has(service.walletConnectService.chain));
21
- if (!service)
20
+ if (!(0, blockchain_service_1.hasWalletConnect)(service) || !allChains.has(service.walletConnectService.chain))
22
21
  throw new blockchain_service_1.BSError('Requested chain(s) not supported by any service', 'NO_SERVICE');
23
22
  const namespaceObject = mergedNamespacesObject[service.walletConnectService.namespace];
24
23
  if (!namespaceObject)
@@ -37,6 +36,12 @@ class WalletKitHelper {
37
36
  const methods = namespaceObject.methods;
38
37
  return { approvedNamespaces, methods, service, blockchain: service.name };
39
38
  }
39
+ static getProposalServices({ proposal, services }) {
40
+ const mergedNamespacesObject = (0, utils_1.mergeRequiredAndOptionalNamespaces)(proposal.requiredNamespaces, proposal.optionalNamespaces);
41
+ const allChains = new Set((0, utils_1.getChainsFromRequiredNamespaces)(mergedNamespacesObject));
42
+ const proposalServices = services.filter((service) => (0, blockchain_service_1.hasWalletConnect)(service) && allChains.has(service.walletConnectService.chain));
43
+ return proposalServices;
44
+ }
40
45
  static getSessionDetails({ session, services, }) {
41
46
  const sessionAccounts = (0, utils_1.getAccountsFromNamespaces)(session.namespaces);
42
47
  const [sessionAddress] = (0, utils_1.getAddressesFromAccounts)(sessionAccounts);
@@ -3,6 +3,10 @@ import { PendingRequestTypes, ProposalTypes, SessionTypes } from '@walletconnect
3
3
  export type TWalletKitHelperGetProposalDetailsParams<N extends string = string> = {
4
4
  proposal: ProposalTypes.Struct;
5
5
  address: string;
6
+ service: IBlockchainService<N>;
7
+ };
8
+ export type TWalletKitHelperGetProposalServicesParams<N extends string = string> = {
9
+ proposal: ProposalTypes.Struct;
6
10
  services: IBlockchainService<N>[];
7
11
  };
8
12
  export type TWalletKitHelperProposalDetails<N extends string = string> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-multichain",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",