Skip to content

Commit

Permalink
Fixed openurl package issue (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalrajbacancy authored Aug 22, 2023
1 parent 344aa4f commit 54de301
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
10 changes: 2 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.1.4",
"version": "1.1.5",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand All @@ -15,7 +15,10 @@
"license": "MIT",
"homepage": "https://etherspot.dev",
"main": "./dist/node.js",
"browser": "./dist/browser.js",
"browser": {
"./dist/browser.js": "./dist/browser.js",
"child_process": false
},
"types": "./dist/index.d.ts",
"scripts": {
"start": "exit 1",
Expand Down Expand Up @@ -46,7 +49,6 @@
"class-validator": "0.14.0",
"commander": "^10.0.1",
"ethers": "5.7.0",
"openurl": "1.1.1",
"prettier": "^2.8.8",
"reflect-metadata": "0.1.13"
},
Expand Down
1 change: 1 addition & 0 deletions src/sdk/common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './random-private-key';
export * from './sleep';
export * from './stringify-json';
export * from './to-hex';
export * from './openurl';
37 changes: 37 additions & 0 deletions src/sdk/common/utils/openurl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const platformCommands = {
darwin: 'open',
win32: 'explorer.exe',
linux: 'xdg-open'
};

export function openUrl(url, callback?) {
if (typeof window === 'undefined') {
var spawn = require('child_process').spawn;
}

const command = platformCommands[process.platform];
if (!command) {
throw new Error('Unsupported platform: ' + process.platform);
}

const child = spawn(command, [url]);
let errorText = "";

child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
errorText += data;
});

child.stderr.on('end', function () {
if (errorText.length > 0) {
var error = new Error(errorText);
if (callback) {
callback(error);
} else {
throw error;
}
} else if (callback) {
callback(error);
}
});
}
11 changes: 8 additions & 3 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { BehaviorSubject } from 'rxjs';
import * as open from 'openurl';
import { State, StateService } from './state';
import { isWalletProvider, WalletProviderLike } from './wallet';
import { SdkOptions } from './interfaces';
import { Network } from "./network";
import { BatchUserOpsRequest, Exception, getGasFee, onRampApiKey, UserOpsRequest } from "./common";
import { BatchUserOpsRequest, Exception, getGasFee, onRampApiKey, openUrl, UserOpsRequest } from "./common";
import { BigNumber, ethers, providers } from 'ethers';
import { getNetworkConfig, Networks, onRamperAllNetworks } from './network/constants';
import { UserOperationStruct } from './contracts/src/aa-4337/core/BaseAccount';
Expand Down Expand Up @@ -256,7 +255,13 @@ export class PrimeSdk {
`${params.onlyFiats ? `&onlyFiats=${params.onlyFiats}` : ``}` +
`${params.excludeFiats ? `&excludeFiats=${params.excludeFiats}` : ``}` +
`&themeName=${params.themeName ?? 'dark'}`;
open.open(url)

if (typeof window === 'undefined') {
openUrl(url);
} else {
window.open(url);
}

return url;
}

Expand Down

0 comments on commit 54de301

Please sign in to comment.