Skip to content

Commit

Permalink
feat: Implement configurable app meta
Browse files Browse the repository at this point in the history
  • Loading branch information
mucahit committed May 20, 2022
1 parent b381340 commit 47bc6d5
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 39 deletions.
153 changes: 150 additions & 3 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@perawallet/connect",
"version": "0.0.9",
"version": "0.0.10",
"description": "JavaScript SDK for integrating Pera Wallet to web applications.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -14,6 +14,7 @@
"@hipo/eslint-config-base": "^4.1.1",
"@hipo/eslint-config-react": "^2.2.0",
"@hipo/eslint-config-typescript": "^1.1.0",
"@rollup/plugin-image": "^2.1.1",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.14",
"@typescript-eslint/eslint-plugin": "^5.17.0",
Expand All @@ -25,7 +26,6 @@
"rollup": "^2.70.1",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-react-svg": "^3.0.3",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"sass": "^1.49.11",
Expand All @@ -38,9 +38,9 @@
"react-qr-code": "^2.0.5"
},
"peerDependencies": {
"algosdk": "^1.15.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"algosdk": "^1.15.0"
"react-dom": "^17.0.2"
},
"types": "./dist/index.d.ts",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typescript from "rollup-plugin-typescript2";
import {terser} from "rollup-plugin-terser";
import postcss from "rollup-plugin-postcss";
import reactSvg from "rollup-plugin-react-svg";
import image from "@rollup/plugin-image";

export default [
{
Expand All @@ -22,7 +22,7 @@ export default [
"algosdk"
],
plugins: [
reactSvg(),
image(),
terser(),
postcss(),
typescript({
Expand Down
25 changes: 22 additions & 3 deletions src/PeraWalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ import {
encodeUnsignedTransactionInBase64
} from "./util/transaction/transactionUtils";
import {isMobile} from "./util/device/deviceUtils";
import {AppMeta} from "./util/peraWalletTypes";
import {getPeraWalletAppMeta} from "./util/peraWalletUtils";

interface PeraWalletConnectOptions {
bridge: string;
bridge?: string;
deep_link?: string;
app_meta?: AppMeta;
}

const peraWalletConnectModalActions = {
Expand All @@ -41,6 +45,17 @@ class PeraWalletConnect {
localStorage.getItem(PERA_WALLET_LOCAL_STORAGE_KEYS.BRIDGE_URL) ||
"";

if (options?.deep_link) {
localStorage.setItem(PERA_WALLET_LOCAL_STORAGE_KEYS.DEEP_LINK, options.deep_link);
}

if (options?.app_meta) {
localStorage.setItem(
PERA_WALLET_LOCAL_STORAGE_KEYS.APP_META,
JSON.stringify(options.app_meta)
);
}

this.connector = null;
}

Expand Down Expand Up @@ -81,13 +96,15 @@ class PeraWalletConnect {
} catch (error: any) {
console.log(error);

const {name} = getPeraWalletAppMeta();

reject(
new PeraWalletConnectError(
{
type: "SESSION_CONNECT",
detail: error
},
error.message || "There was an error while connecting to Pera Wallet"
error.message || `There was an error while connecting to ${name}`
)
);
}
Expand Down Expand Up @@ -123,12 +140,14 @@ class PeraWalletConnect {
// If the bridge is not active, then disconnect
this.disconnect();

const {name} = getPeraWalletAppMeta();

throw new PeraWalletConnectError(
{
type: "SESSION_RECONNECT",
detail: error
},
error.message || "There was an error while reconnecting to Pera Wallet"
error.message || `There was an error while reconnecting to ${name}`
);
}
}
Expand Down
Loading

0 comments on commit 47bc6d5

Please sign in to comment.