Skip to content

Commit

Permalink
setup SnapProvider using SnapBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
gantunesr committed Dec 13, 2022
1 parent ebde0c8 commit ffd7409
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions app/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ import { MetaMaskKeyring as QRHardwareKeyring } from '@keystonehq/metamask-airga
import Encryptor from './Encryptor';
import { toChecksumAddress } from 'ethereumjs-util';
import RNFetchBlob from 'rn-fetch-blob';
import {
fetchNPMPackage,
fetchNPMPackageAlternative,
} from './SnapExecutionService/fetchNPMPackage';
import Networks, {
isMainnetByChainId,
getDecimalChainId,
Expand All @@ -56,6 +52,7 @@ import { SNAP_BLOCKLIST, checkSnapsBlockList } from '../util/snaps';
import { isZero } from '../util/lodash';
import AnalyticsV2 from '../util/analyticsV2';
import WebviewExecutionService from '../components/Views/Wallet/WebviewExecutionService';
import { SnapBridge } from './SnapExecutionService';

const NON_EMPTY = 'NON_EMPTY';

Expand Down Expand Up @@ -218,11 +215,13 @@ class Engine {
});

this.setupSnapProvider = (snapId, connectionStream) => {
this.setupUntrustedCommunication({
const bridge = new SnapBridge({
snapId,
connectionStream,
sender: { snapId },
subjectType: 'snap',
getRPCMethodMiddleware: (args) => null,
});

bridge.setupProviderConnection();
};

this.snapExecutionService = new WebviewExecutionService({
Expand Down Expand Up @@ -268,23 +267,18 @@ class Engine {
});

setTimeout(async () => {
// await fetchNPMPackage();
// await fetchNPMPackageAlternative();

const snapId = 'npm:@metamask/test-snap-bip44';
const origin = 'origin';

await snapController.installSnaps(origin, { [snapId]: {} });

const result = await snapController.handleRequest({
snapId,
origin,
handler: 'onRpcRequest',
request: { method: 'foo', params: { bar: 'qux' } },
});

// eslint-disable-next-line no-console
console.log(result);
// const snapId = 'npm:@metamask/test-snap-bip44';
// const localSnap = 'local:http://localhost:3000/snap/';
// const origin = 'origin';
// await snapController.installSnaps(origin, { [localSnap]: {} });
// const result = await snapController.handleRequest({
// localSnap,
// origin,
// handler: 'onRpcRequest',
// request: { method: 'foo', params: { bar: 'qux' } },
// });
// // eslint-disable-next-line no-console
// console.log(result);
}, 5000);

// eslint-disable-next-line no-console
Expand Down Expand Up @@ -433,7 +427,7 @@ class Engine {
}),
showApprovalRequest: () => null,
}),
// snapController,
snapController,
];

// set initial state
Expand Down

0 comments on commit ffd7409

Please sign in to comment.