Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extension/src/helpers/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ export const formatDomain = (domain: string) => {
}
return "Stellar Network";
};

export const isMuxedAccount = (publicKey: string) => publicKey.startsWith("M");

export const isFederationAddress = (address: string) => address.includes("*");
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Card, Loader, Icon } from "@stellar/design-system";
import {
getAssetFromCanonical,
getCanonicalFromAsset,
isMuxedAccount,
xlmToStroop,
getConversionRate,
truncatedFedAddress,
Expand Down Expand Up @@ -245,7 +246,7 @@ export const TransactionDetails = ({ goBack }: { goBack: () => void }) => {
}
};

const showMemo = !isSwap && !destination.startsWith("M");
const showMemo = !isSwap && !isMuxedAccount(destination);

return (
<div className="TransactionDetails">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Button } from "popup/basics/buttons/Button";
import { navigateTo } from "popup/helpers/navigate";
import { useNetworkFees } from "popup/helpers/useNetworkFees";
import { useIsSwap } from "popup/helpers/useIsSwap";
import { isMuxedAccount } from "helpers/stellar";
import { ROUTES } from "popup/constants/routes";
import { PopupWrapper } from "popup/basics/PopupWrapper";
import { SubviewHeader } from "popup/components/SubviewHeader";
Expand Down Expand Up @@ -56,7 +57,7 @@ export const SendSettings = ({
);

// dont show memo for regular sends to Muxed, or for swaps
const showMemo = !isSwap && !destination.startsWith("M");
const showMemo = !isSwap && !isMuxedAccount(destination);
const showSlippage = isPathPayment || isSwap;

return (
Expand Down
12 changes: 7 additions & 5 deletions extension/src/popup/components/sendPayment/SendTo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { useFormik } from "formik";
import BigNumber from "bignumber.js";
import { Input, Loader, TextLink } from "@stellar/design-system";

import { truncatedPublicKey } from "helpers/stellar";
import {
isFederationAddress,
isMuxedAccount,
truncatedPublicKey,
} from "helpers/stellar";

import { AppDispatch } from "popup/App";
import { SubviewHeader } from "popup/components/SubviewHeader";
Expand Down Expand Up @@ -108,8 +112,6 @@ export const SendTo = ({ previous }: { previous: ROUTES }) => {
},
});

const isFederationAddress = (address: string) => address.includes("*");

const isValidPublicKey = (publicKey: string) => {
if (StrKey.isValidMed25519PublicKey(publicKey)) {
return true;
Expand All @@ -132,7 +134,7 @@ export const SendTo = ({ previous }: { previous: ROUTES }) => {
return;
}
// muxed account
if (inputDest.startsWith("M")) {
if (isMuxedAccount(inputDest)) {
setValidatedPubKey(inputDest);
}
// federation address
Expand Down Expand Up @@ -181,7 +183,7 @@ export const SendTo = ({ previous }: { previous: ROUTES }) => {

// TODO - remove once wallet-sdk can handle muxed
let publicKey = validatedPubKey;
if (validatedPubKey.startsWith("M")) {
if (isMuxedAccount(validatedPubKey)) {
const mAccount = MuxedAccount.fromAddress(validatedPubKey, "0");
publicKey = mAccount.baseAccount().accountId();
}
Expand Down
38 changes: 35 additions & 3 deletions extension/src/popup/views/SignTransaction/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React, { useEffect, useRef, useState } from "react";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { useLocation } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { Card, Icon } from "@stellar/design-system";
import { FederationServer, MuxedAccount } from "stellar-sdk";

import { TRANSACTION_WARNING } from "constants/transaction";

import { emitMetric } from "helpers/metrics";
import { getTransactionInfo, truncatedPublicKey } from "helpers/stellar";
import {
getTransactionInfo,
isFederationAddress,
isMuxedAccount,
truncatedPublicKey,
} from "helpers/stellar";
import { decodeMemo } from "popup/helpers/parseTransaction";
import { Button } from "popup/basics/buttons/Button";
import { InfoBlock } from "popup/basics/InfoBlock";
Expand Down Expand Up @@ -52,7 +58,7 @@ export const SignTransaction = () => {
const location = useLocation();
const dispatch: AppDispatch = useDispatch();
const {
accountToSign,
accountToSign: _accountToSign,
transaction,
domain,
isDomainListedAllowed,
Expand All @@ -68,6 +74,7 @@ export const SignTransaction = () => {

const isFeeBump = !!_innerTransaction;
const memo = decodeMemo(_memo);
let accountToSign = _accountToSign;

const [isConfirming, setIsConfirming] = useState(false);
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
Expand Down Expand Up @@ -129,6 +136,31 @@ export const SignTransaction = () => {
const defaultPublicKey = useRef(publicKey);
const allAccountsMap = useRef({} as { [key: string]: Account });

const resolveFederatedAddress = useCallback(async (inputDest) => {
let resolvedPublicKey;
try {
const fedResp = await FederationServer.resolve(inputDest);
resolvedPublicKey = fedResp.account_id;
} catch (e) {
console.error(e);
}

return resolvedPublicKey;
}, []);

const decodeAccountToSign = async () => {
if (_accountToSign) {
if (isMuxedAccount(_accountToSign)) {
const mAccount = MuxedAccount.fromAddress(_accountToSign, "0");
accountToSign = mAccount.baseAccount().accountId();
}
if (isFederationAddress(_accountToSign)) {
accountToSign = await resolveFederatedAddress(accountToSign);
}
}
};
decodeAccountToSign();

useEffect(() => {
if (isMemoRequired) {
emitMetric(METRIC_NAMES.signTransactionMemoRequired);
Expand Down