Skip to content

Commit

Permalink
Fix: use home domain for SEP-10 auth + don't show duplicate logs (ste…
Browse files Browse the repository at this point in the history
…llar#324)

* Fix duplicate logs

* Use home domain for SEP-10 auth
  • Loading branch information
quietbits authored Sep 19, 2023
1 parent 5d60caa commit 16a925b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
8 changes: 3 additions & 5 deletions packages/demo-wallet-client/src/components/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ export const Logs = () => {

document.addEventListener(LOG_MESSAGE_EVENT, onLogEventMessage);

return document.removeEventListener(
LOG_MESSAGE_EVENT,
onLogEventMessage,
true,
);
return () => {
document.removeEventListener(LOG_MESSAGE_EVENT, onLogEventMessage);
};
}, [dispatch]);

const logsToMarkdown = (logItems: LogItemProps[]) => {
Expand Down
9 changes: 8 additions & 1 deletion packages/demo-wallet-client/src/ducks/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ const logsSlice = createSlice({
state.status = ActionStatus.PENDING;
});
builder.addCase(addLogAction.fulfilled, (state, action) => {
state.items = [...state.items, action.payload];
// Make sure we're not duplicating logs
const currentLogId = `${action.payload.type}-${action.payload.title}`;
const previousLog = [...state.items]?.pop();
const previousLogId = `${previousLog?.type}-${previousLog?.title}`;

if (currentLogId !== previousLogId) {
state.items = [...state.items, action.payload];
}
state.status = ActionStatus.SUCCESS;
});
},
Expand Down
5 changes: 2 additions & 3 deletions packages/demo-wallet-client/src/ducks/sep24DepositAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { settingsSelector } from "ducks/settings";
import { custodialSelector } from "ducks/custodial";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
import { getNetworkConfig } from "demo-wallet-shared/build/helpers/getNetworkConfig";
import { normalizeHomeDomainUrl } from "demo-wallet-shared/build/helpers/normalizeHomeDomainUrl";
import { log } from "demo-wallet-shared/build/helpers/log";
import {
sep10AuthStart,
Expand Down Expand Up @@ -114,14 +115,12 @@ export const depositAssetAction = createAsyncThunk<
"SEP-24 deposit is enabled, and requires authentication so we should go through SEP-10",
});

const serviceDomain = new URL(tomlResponse.TRANSFER_SERVER_SEP0024).host;

// SEP-10 start
const challengeTransaction = await sep10AuthStart({
authEndpoint: tomlResponse.WEB_AUTH_ENDPOINT,
serverSigningKey: tomlResponse.SIGNING_KEY,
publicKey: custodialPublicKey || publicKey,
homeDomain: serviceDomain,
homeDomain: normalizeHomeDomainUrl(homeDomain).host,
clientDomain,
memoId: custodialMemoId,
});
Expand Down
5 changes: 2 additions & 3 deletions packages/demo-wallet-client/src/ducks/sep24WithdrawAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { accountSelector } from "ducks/account";
import { custodialSelector } from "ducks/custodial";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
import { getNetworkConfig } from "demo-wallet-shared/build/helpers/getNetworkConfig";
import { normalizeHomeDomainUrl } from "demo-wallet-shared/build/helpers/normalizeHomeDomainUrl";
import { log } from "demo-wallet-shared/build/helpers/log";
import {
sep10AuthStart,
Expand Down Expand Up @@ -91,14 +92,12 @@ export const withdrawAssetAction = createAsyncThunk<
"SEP-24 withdrawal is enabled, and requires authentication so we should go through SEP-10",
});

const serviceDomain = new URL(tomlResponse.TRANSFER_SERVER_SEP0024).host;

// SEP-10 start
const challengeTransaction = await sep10AuthStart({
authEndpoint: tomlResponse.WEB_AUTH_ENDPOINT,
serverSigningKey: tomlResponse.SIGNING_KEY,
publicKey: custodialPublicKey || publicKey,
homeDomain: serviceDomain,
homeDomain: normalizeHomeDomainUrl(homeDomain).host,
clientDomain,
memoId: custodialMemoId,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/demo-wallet-client/src/ducks/sep31Send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RootState, walletBackendEndpoint, clientDomain } from "config/store";
import { accountSelector } from "ducks/account";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
import { getNetworkConfig } from "demo-wallet-shared/build/helpers/getNetworkConfig";
import { normalizeHomeDomainUrl } from "demo-wallet-shared/build/helpers/normalizeHomeDomainUrl";
import { log } from "demo-wallet-shared/build/helpers/log";

import {
Expand Down Expand Up @@ -221,16 +222,15 @@ export const fetchSendFieldsAction = createAsyncThunk<
senderType,
receiverType,
fields,
homeDomain,
} = data;

const serviceDomain = new URL(kycServer).host;

// SEP-10 start
const challengeTransaction = await sep10AuthStart({
authEndpoint,
serverSigningKey,
publicKey,
homeDomain: serviceDomain,
homeDomain: normalizeHomeDomainUrl(homeDomain).host,
clientDomain,
});

Expand Down
5 changes: 2 additions & 3 deletions packages/demo-wallet-client/src/ducks/sep6DepositAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { accountSelector } from "ducks/account";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
import { getNetworkConfig } from "demo-wallet-shared/build/helpers/getNetworkConfig";
import { normalizeHomeDomainUrl } from "demo-wallet-shared/build/helpers/normalizeHomeDomainUrl";
import { log } from "demo-wallet-shared/build/helpers/log";
import { checkDepositWithdrawInfo } from "demo-wallet-shared/build/methods/checkDepositWithdrawInfo";
import {
Expand Down Expand Up @@ -116,14 +117,12 @@ export const initiateDepositAction = createAsyncThunk<
"SEP-6 deposit is enabled, and requires authentication so we should go through SEP-10",
});

const serviceDomain = new URL(tomlResponse.TRANSFER_SERVER).host;

// SEP-10 start
const challengeTransaction = await sep10AuthStart({
authEndpoint: webAuthTomlResponse.WEB_AUTH_ENDPOINT,
serverSigningKey: webAuthTomlResponse.SIGNING_KEY,
publicKey,
homeDomain: serviceDomain,
homeDomain: normalizeHomeDomainUrl(homeDomain).host,
clientDomain,
});

Expand Down
5 changes: 2 additions & 3 deletions packages/demo-wallet-client/src/ducks/sep6WithdrawAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { accountSelector } from "ducks/account";
import { settingsSelector } from "ducks/settings";
import { getErrorMessage } from "demo-wallet-shared/build/helpers/getErrorMessage";
import { getNetworkConfig } from "demo-wallet-shared/build/helpers/getNetworkConfig";
import { normalizeHomeDomainUrl } from "demo-wallet-shared/build/helpers/normalizeHomeDomainUrl";
import { log } from "demo-wallet-shared/build/helpers/log";
import { checkDepositWithdrawInfo } from "demo-wallet-shared/build/methods/checkDepositWithdrawInfo";
import {
Expand Down Expand Up @@ -111,14 +112,12 @@ export const initiateWithdrawAction = createAsyncThunk<
"SEP-6 withdrawal is enabled, and requires authentication so we should go through SEP-10",
});

const serviceDomain = new URL(tomlResponse.TRANSFER_SERVER).host;

// SEP-10 start
const challengeTransaction = await sep10AuthStart({
authEndpoint: webAuthTomlResponse.WEB_AUTH_ENDPOINT,
serverSigningKey: webAuthTomlResponse.SIGNING_KEY,
publicKey,
homeDomain: serviceDomain,
homeDomain: normalizeHomeDomainUrl(homeDomain).host,
clientDomain,
});

Expand Down

0 comments on commit 16a925b

Please sign in to comment.