Skip to content

Commit 93520f4

Browse files
authored
fix: fix eos transactions
2 parents de3480a + 2cc79aa commit 93520f4

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

config/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export const ONBOARDING_LINK =
2-
process.env.ONBOARDING_LINK || "https://hyphawallet.page.link/get-hypha-wallet";
31
export const AUTHENTICATOR_NAME = "Hypha Wallet";
42
export const BUTTON_BACKGROUND_COLOR = "#1D2946";
53
export const BUTTON_TEXT_COLOR = "white";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hypha-dao/ual-hypha",
3-
"version": "1.0.13",
3+
"version": "1.0.14",
44
"description": "UAL implementation for Hypha Wallet",
55
"type": "module",
66
"source": "index.js",

src/HyphaAuthenticator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import WebTransportLink from "./web-transport/index.js";
44
import ESRUtil from "./utils/esr.js";
55

66
import {
7-
ONBOARDING_LINK,
87
AUTHENTICATOR_NAME,
98
BUTTON_BACKGROUND_COLOR,
109
BUTTON_TEXT_COLOR,
@@ -65,9 +64,10 @@ export class HyphaAuthenticator extends Authenticator {
6564
/**
6665
* Returns a URL where the user can download and install the underlying authenticator
6766
* if it is not found by the UAL Authenticator.
67+
* We return undefined - we do not want people to download the wallet other than with an onboarding link
6868
*/
6969
getOnboardingLink() {
70-
return ONBOARDING_LINK;
70+
return undefined;
7171
}
7272

7373
/**

src/utils/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import { v4 as uuidv4 } from "uuid";
22

3-
4-
export const poll = function (fn, data, interval) {
3+
export const poll = function (fn, data, interval, totalTimeout) {
54
interval = interval || 100;
5+
totalTimeout = totalTimeout || 120000;
6+
7+
const startTime = Date.now();
68

79
var checkCondition = async (resolve, reject) => {
8-
var result = await fn(data);
9-
if (result) {
10-
resolve(result);
11-
} else {
12-
setTimeout(checkCondition, interval, resolve, reject);
10+
try {
11+
var result = await fn(data);
12+
if (result) {
13+
resolve(result);
14+
} else {
15+
if (Date.now() - startTime < totalTimeout) {
16+
setTimeout(checkCondition, interval, resolve, reject);
17+
} else {
18+
reject(new Error("Timeout"));
19+
}
20+
}
21+
} catch (error) {
22+
reject(error);
1323
}
1424
};
1525

src/web-transport/index.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,29 @@ const checkLoginData = function (transaction, loginCode, loginContract) {
2121
};
2222

2323
class WebTransportLink {
24-
constructor(esrUtil, pollingInterval = 2000) {
24+
constructor(
25+
esrUtil,
26+
pollingInterval = 1000,
27+
transactionCheckInterval = 500,
28+
pollTimeout = 10 * 60 * 1000, // 10 minutes
29+
transactionCheckTimeout = 30 * 1000 // 30 seconds
30+
) {
31+
if (!esrUtil || !esrUtil.rpc) {
32+
throw new Error("Invalid esrUtil or esrUtil.rpc not found " + esrUtil);
33+
}
34+
2535
this.dialog = new Dialog();
2636
this.esrUtil = esrUtil;
2737
this.rpc = esrUtil.rpc;
2838
this.pollingInterval = pollingInterval;
39+
this.transactionCheckInterval = transactionCheckInterval;
40+
this.pollTimeout = pollTimeout;
41+
this.transactionCheckTimeout = transactionCheckTimeout;
2942
this.login = this.login.bind(this);
3043
this.restore = this.restore.bind(this);
3144
this.logout = this.logout.bind(this);
45+
this.checkTransactionId = this.checkTransactionId.bind(this);
46+
3247
}
3348

3449
getContractFromTransaction(transactions) {
@@ -45,6 +60,17 @@ class WebTransportLink {
4560
const data = response.text();
4661
return data;
4762
} catch (e) {
63+
//console.error("error polling: " + e)
64+
return;
65+
}
66+
}
67+
68+
async checkTransactionId(txId) {
69+
try {
70+
const transactionInfo = await this.rpc.history_get_transaction(txId);
71+
return transactionInfo;
72+
} catch (e) {
73+
//console.log("checkTransactionId error: " + e)
4874
return;
4975
}
5076
}
@@ -74,7 +100,7 @@ class WebTransportLink {
74100
throw new UALHyphaWalletError(
75101
"No transaction has been passed to sign transaction"
76102
);
77-
const { pollingInterval } = this;
103+
const { pollingInterval, transactionCheckInterval, pollTimeout, transactionCheckTimeout } = this;
78104
const uid = getTransactionUID(transaction);
79105
const callbackUrl = `${CALLBACK_HOST}/transaction?uid=${uid}&tx_id={{tx}}`;
80106
const esr = await this.esrUtil.encodeESR(
@@ -100,9 +126,9 @@ class WebTransportLink {
100126

101127
await this.dialog.showDialog(dialog);
102128

103-
const txId = await poll(this.checkForConfirmation, uid, pollingInterval);
129+
const txId = await poll(this.checkForConfirmation, uid, pollingInterval, pollTimeout);
104130

105-
const transactionInfo = await this.rpc.history_get_transaction(txId);
131+
const transactionInfo = await poll(this.checkTransactionId, txId, transactionCheckInterval, transactionCheckTimeout);
106132

107133
this.dialog.hide();
108134
return transactionInfo;

0 commit comments

Comments
 (0)