From 65e96f4ca0c281c44e62f0b930de8a38b1c257e2 Mon Sep 17 00:00:00 2001 From: Voltair <voltair0@protonmail.com> Date: Sun, 12 Jul 2020 15:19:52 +0800 Subject: [PATCH] modify sendOperations to redirect to callback after success --- src/app/utils/HiveSigner.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/app/utils/HiveSigner.js b/src/app/utils/HiveSigner.js index b4494dda..a049f55f 100644 --- a/src/app/utils/HiveSigner.js +++ b/src/app/utils/HiveSigner.js @@ -1,11 +1,15 @@ import { isLoggedIn, extractLoginData } from 'app/utils/UserUtil'; import hivesigner from 'hivesigner'; import { APP_URL, HIVE_SIGNER_APP } from 'app/client_config'; +import { encodeOps } from 'hive-uri'; -const HOST_URL = - typeof window !== 'undefined' - ? window.location.protocol + '//' + window.location.host - : APP_URL; +const isBrowser = () => typeof window !== 'undefined' && window; + +const HOST_URL = isBrowser() + ? window.location.protocol + '//' + window.location.host + : APP_URL; + +const HIVE_SIGNER_URL = 'https://hivesigner.com'; export const hiveSignerClient = new hivesigner.Client({ app: HIVE_SIGNER_APP, @@ -43,4 +47,15 @@ export const setHiveSignerAccessToken = ( hiveSignerClient.setAccessToken(access_token); }; -export const sendOperationsWithHiveSigner = hivesigner.sendOperations; +export const sendOperationsWithHiveSigner = (ops, params, cb) => { + if (!params) params = {}; + if (!params.callback) { + params.callback = window.location.href; + } + const uri = encodeOps(ops, params); + const webUrl = uri.replace('hive://', `${HIVE_SIGNER_URL}/`); + if (cb && isBrowser()) { + window.location = webUrl; + } + return webUrl; +}; -- GitLab