• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / lace / 8535836959

03 Apr 2024 08:45AM UTC coverage: 50.56% (-3.3%) from 53.839%
8535836959

push

github

2dd801
web-flow
chore(extension): update lace version v1.10.0 LW-10198 (#1015)

2172 of 5362 branches covered (40.51%)

Branch coverage included in aggregate %.

5147 of 9114 relevant lines covered (56.47%)

52.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/apps/browser-extension-wallet/src/lib/scripts/background/cip30.ts
1
import { cip30 as walletCip30 } from '@cardano-sdk/wallet';
×
2
import { ensureUiIsOpenAndLoaded } from './util';
×
3
import { userPromptService } from './services/dappService';
×
4
import { authenticator } from './authenticator';
×
5
import { wallet$, walletManager, walletRepository } from './wallet';
×
6
import { runtime } from 'webextension-polyfill';
×
7
import { exposeApi, RemoteApiPropertyType, cip30 } from '@cardano-sdk/web-extension';
×
8
import { DAPP_CHANNELS } from '../../../utils/constants';
×
9
import { DappDataService } from '../types';
10
import { BehaviorSubject, of } from 'rxjs';
×
11
import { APIErrorCode, ApiError } from '@cardano-sdk/dapp-connector';
×
12
import { Wallet } from '@lace/cardano';
13
import pDebounce from 'p-debounce';
×
14
import { dappInfo$ } from './requestAccess';
×
15
import { senderToDappInfo } from '@src/utils/senderToDappInfo';
×
16

17
const DEBOUNCE_THROTTLE = 500;
×
18

19
const dappSetCollateral$ = new BehaviorSubject<{
×
20
  dappInfo: Wallet.DappInfo;
21
  collateralRequest: walletCip30.GetCollateralCallbackParams['data'];
22
}>(undefined);
23

24
export const confirmationCallback: walletCip30.CallbackConfirmation = {
×
25
  submitTx: async () =>
×
26
    // We don't need another callback for this callback, so long as we ensure callbacks for signing tx's
27
    // Remove this method once it is dropped from the SDK in future build
28
    // Also transactions can be submitted by the dApps externally
29
    // once they've got the witnesss keys if they construct their own transactions
30
    Promise.resolve(true),
×
31
  signTx: pDebounce(async () => {
×
32
    try {
×
33
      await ensureUiIsOpenAndLoaded({ walletManager, walletRepository }, '#/dapp/sign-tx');
×
34

35
      return userPromptService.readyToSignTx();
×
36
    } catch (error) {
37
      console.error(error);
×
38
      return Promise.reject(new ApiError(APIErrorCode.InternalError, 'Unable to sign transaction'));
×
39
    }
40
  }, DEBOUNCE_THROTTLE),
41
  signData: pDebounce(async () => {
×
42
    try {
×
43
      await ensureUiIsOpenAndLoaded({ walletManager, walletRepository }, '#/dapp/sign-data');
×
44

45
      return userPromptService.readyToSignData();
×
46
    } catch (error) {
47
      console.error(error);
×
48
      // eslint-disable-next-line unicorn/no-useless-undefined
49
      return Promise.reject(new ApiError(APIErrorCode.InternalError, 'Unable to sign data'));
×
50
    }
51
  }, DEBOUNCE_THROTTLE),
52
  getCollateral: pDebounce(async (args) => {
×
53
    try {
×
54
      const dappInfo = await senderToDappInfo(args.sender);
×
55
      dappSetCollateral$.next({ dappInfo, collateralRequest: args.data });
×
56
      await ensureUiIsOpenAndLoaded({ walletManager, walletRepository }, '#/dapp/set-collateral');
×
57

58
      return userPromptService.getCollateralRequest();
×
59
    } catch (error) {
60
      // eslint-disable-next-line unicorn/no-useless-undefined
61
      dappSetCollateral$.next(undefined);
×
62
      throw new Error(error);
×
63
    }
64
  }, DEBOUNCE_THROTTLE)
65
};
66

67
const walletApi = walletCip30.createWalletApi(wallet$, confirmationCallback, { logger: console });
×
68

69
cip30.initializeBackgroundScript(
×
70
  { walletName: process.env.WALLET_NAME },
71
  { authenticator, logger: console, runtime, walletApi }
72
);
73

74
exposeApi<DappDataService>(
×
75
  {
76
    baseChannel: DAPP_CHANNELS.dappData,
77
    properties: {
78
      getCollateralRequest: RemoteApiPropertyType.MethodReturningPromise,
79
      getDappInfo: RemoteApiPropertyType.MethodReturningPromise
80
    },
81
    api$: of({
82
      getCollateralRequest: () => Promise.resolve(dappSetCollateral$.value),
×
83
      getDappInfo: () => Promise.resolve(dappInfo$.value)
×
84
    })
85
  },
86
  { logger: console, runtime }
87
);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc