From 2dac16198dac1b4438c6b8791fbc1588588a0f7b Mon Sep 17 00:00:00 2001 From: NIK Date: Mon, 29 Jan 2024 16:16:04 +0800 Subject: [PATCH 1/4] remove link to app store --- config/index.js | 2 -- src/HyphaAuthenticator.js | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/config/index.js b/config/index.js index edd922a..e81d244 100644 --- a/config/index.js +++ b/config/index.js @@ -1,5 +1,3 @@ -export const ONBOARDING_LINK = - process.env.ONBOARDING_LINK || "https://hyphawallet.page.link/get-hypha-wallet"; export const AUTHENTICATOR_NAME = "Hypha Wallet"; export const BUTTON_BACKGROUND_COLOR = "#1D2946"; export const BUTTON_TEXT_COLOR = "white"; diff --git a/src/HyphaAuthenticator.js b/src/HyphaAuthenticator.js index 66a4615..26612e6 100644 --- a/src/HyphaAuthenticator.js +++ b/src/HyphaAuthenticator.js @@ -4,7 +4,6 @@ import WebTransportLink from "./web-transport/index.js"; import ESRUtil from "./utils/esr.js"; import { - ONBOARDING_LINK, AUTHENTICATOR_NAME, BUTTON_BACKGROUND_COLOR, BUTTON_TEXT_COLOR, @@ -65,9 +64,10 @@ export class HyphaAuthenticator extends Authenticator { /** * Returns a URL where the user can download and install the underlying authenticator * if it is not found by the UAL Authenticator. + * We return undefined - we do not want people to download the wallet other than with an onboarding link */ getOnboardingLink() { - return ONBOARDING_LINK; + return undefined; } /** From 1c0f541dafc5500d9770366e871dd21fe3516dd7 Mon Sep 17 00:00:00 2001 From: NIK Date: Mon, 29 Jan 2024 16:18:07 +0800 Subject: [PATCH 2/4] polling for history transactions history transaction might take a while to appear --- src/web-transport/index.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/web-transport/index.js b/src/web-transport/index.js index 8eb0a86..e9e87b8 100644 --- a/src/web-transport/index.js +++ b/src/web-transport/index.js @@ -21,14 +21,21 @@ const checkLoginData = function (transaction, loginCode, loginContract) { }; class WebTransportLink { - constructor(esrUtil, pollingInterval = 2000) { + constructor(esrUtil, pollingInterval = 1000, transactionCheckInterval = 500) { + if (!esrUtil || !esrUtil.rpc) { + throw new Error("Invalid esrUtil or esrUtil.rpc not found " + esrUtil); + } + this.dialog = new Dialog(); this.esrUtil = esrUtil; this.rpc = esrUtil.rpc; this.pollingInterval = pollingInterval; + this.transactionCheckInterval = transactionCheckInterval; this.login = this.login.bind(this); this.restore = this.restore.bind(this); this.logout = this.logout.bind(this); + this.checkTransactionId = this.checkTransactionId.bind(this); + } getContractFromTransaction(transactions) { @@ -45,6 +52,17 @@ class WebTransportLink { const data = response.text(); return data; } catch (e) { + //console.error("error polling: " + e) + return; + } + } + + async checkTransactionId(txId) { + try { + const transactionInfo = await this.rpc.history_get_transaction(txId); + return transactionInfo; + } catch (e) { + //console.log("checkTransactionId error: " + e) return; } } @@ -74,7 +92,7 @@ class WebTransportLink { throw new UALHyphaWalletError( "No transaction has been passed to sign transaction" ); - const { pollingInterval } = this; + const { pollingInterval, transactionCheckInterval } = this; const uid = getTransactionUID(transaction); const callbackUrl = `${CALLBACK_HOST}/transaction?uid=${uid}&tx_id={{tx}}`; const esr = await this.esrUtil.encodeESR( @@ -102,7 +120,7 @@ class WebTransportLink { const txId = await poll(this.checkForConfirmation, uid, pollingInterval); - const transactionInfo = await this.rpc.history_get_transaction(txId); + const transactionInfo = await poll(this.checkTransactionId, txId, transactionCheckInterval); this.dialog.hide(); return transactionInfo; From cda40a2b24dee463623a2987a3f7112ad4857a59 Mon Sep 17 00:00:00 2001 From: NIK Date: Mon, 29 Jan 2024 21:14:06 +0800 Subject: [PATCH 3/4] added timeout to polling --- src/utils/index.js | 24 +++++++++++++++++------- src/web-transport/index.js | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index 73f2ce1..aaf9d3b 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,15 +1,25 @@ import { v4 as uuidv4 } from "uuid"; - -export const poll = function (fn, data, interval) { +export const poll = function (fn, data, interval, totalTimeout) { interval = interval || 100; + totalTimeout = totalTimeout || 120000; + + const startTime = Date.now(); var checkCondition = async (resolve, reject) => { - var result = await fn(data); - if (result) { - resolve(result); - } else { - setTimeout(checkCondition, interval, resolve, reject); + try { + var result = await fn(data); + if (result) { + resolve(result); + } else { + if (Date.now() - startTime < totalTimeout) { + setTimeout(checkCondition, interval, resolve, reject); + } else { + reject(new Error("Timeout")); + } + } + } catch (error) { + reject(error); } }; diff --git a/src/web-transport/index.js b/src/web-transport/index.js index e9e87b8..a2309bf 100644 --- a/src/web-transport/index.js +++ b/src/web-transport/index.js @@ -21,7 +21,13 @@ const checkLoginData = function (transaction, loginCode, loginContract) { }; class WebTransportLink { - constructor(esrUtil, pollingInterval = 1000, transactionCheckInterval = 500) { + constructor( + esrUtil, + pollingInterval = 1000, + transactionCheckInterval = 500, + pollTimeout = 10 * 60 * 1000, // 10 minutes + transactionCheckTimeout = 30 * 1000 // 30 seconds + ) { if (!esrUtil || !esrUtil.rpc) { throw new Error("Invalid esrUtil or esrUtil.rpc not found " + esrUtil); } @@ -31,6 +37,8 @@ class WebTransportLink { this.rpc = esrUtil.rpc; this.pollingInterval = pollingInterval; this.transactionCheckInterval = transactionCheckInterval; + this.pollTimeout = pollTimeout; + this.transactionCheckTimeout = transactionCheckTimeout; this.login = this.login.bind(this); this.restore = this.restore.bind(this); this.logout = this.logout.bind(this); @@ -92,7 +100,7 @@ class WebTransportLink { throw new UALHyphaWalletError( "No transaction has been passed to sign transaction" ); - const { pollingInterval, transactionCheckInterval } = this; + const { pollingInterval, transactionCheckInterval, pollTimeout, transactionCheckTimeout } = this; const uid = getTransactionUID(transaction); const callbackUrl = `${CALLBACK_HOST}/transaction?uid=${uid}&tx_id={{tx}}`; const esr = await this.esrUtil.encodeESR( @@ -118,9 +126,9 @@ class WebTransportLink { await this.dialog.showDialog(dialog); - const txId = await poll(this.checkForConfirmation, uid, pollingInterval); + const txId = await poll(this.checkForConfirmation, uid, pollingInterval, pollTimeout); - const transactionInfo = await poll(this.checkTransactionId, txId, transactionCheckInterval); + const transactionInfo = await poll(this.checkTransactionId, txId, transactionCheckInterval, transactionCheckTimeout); this.dialog.hide(); return transactionInfo; From 2cc79aa0f78572b3338d6ebf9a7fc66543c056ac Mon Sep 17 00:00:00 2001 From: NIK Date: Tue, 30 Jan 2024 10:42:45 +0800 Subject: [PATCH 4/4] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 750aae0..ca11ec1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hypha-dao/ual-hypha", - "version": "1.0.13", + "version": "1.0.14", "description": "UAL implementation for Hypha Wallet", "type": "module", "source": "index.js",