bridge_ui: fix allow migration from any token acct
Change-Id: Ia4a267bd940e2e3e7f2b5643e6b9322ec4f34024
This commit is contained in:
parent
25d98e8500
commit
6e8668e56d
|
@ -168,7 +168,7 @@ function App() {
|
||||||
<Route exact path="/register">
|
<Route exact path="/register">
|
||||||
<Attest />
|
<Attest />
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/migrate/:legacyAsset">
|
<Route exact path="/migrate/:legacyAsset/:fromTokenAccount">
|
||||||
<Migration />
|
<Migration />
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/">
|
<Route exact path="/">
|
||||||
|
|
|
@ -26,7 +26,6 @@ import { COLORS } from "../../muiTheme";
|
||||||
import { MIGRATION_PROGRAM_ADDRESS, SOLANA_HOST } from "../../utils/consts";
|
import { MIGRATION_PROGRAM_ADDRESS, SOLANA_HOST } from "../../utils/consts";
|
||||||
import { getMultipleAccounts, signSendAndConfirm } from "../../utils/solana";
|
import { getMultipleAccounts, signSendAndConfirm } from "../../utils/solana";
|
||||||
import ButtonWithLoader from "../ButtonWithLoader";
|
import ButtonWithLoader from "../ButtonWithLoader";
|
||||||
import LowBalanceWarning from "../LowBalanceWarning";
|
|
||||||
import ShowTx from "../ShowTx";
|
import ShowTx from "../ShowTx";
|
||||||
import SmartAddress from "../SmartAddress";
|
import SmartAddress from "../SmartAddress";
|
||||||
import SolanaCreateAssociatedAddress, {
|
import SolanaCreateAssociatedAddress, {
|
||||||
|
@ -94,9 +93,11 @@ const getBalance = async (
|
||||||
export default function Workflow({
|
export default function Workflow({
|
||||||
fromMint,
|
fromMint,
|
||||||
toMint,
|
toMint,
|
||||||
|
fromTokenAccount,
|
||||||
}: {
|
}: {
|
||||||
fromMint: string;
|
fromMint: string;
|
||||||
toMint: string;
|
toMint: string;
|
||||||
|
fromTokenAccount: string;
|
||||||
}) {
|
}) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
|
@ -112,9 +113,6 @@ export default function Workflow({
|
||||||
|
|
||||||
const [poolAddress, setPoolAddress] = useState("");
|
const [poolAddress, setPoolAddress] = useState("");
|
||||||
const [poolExists, setPoolExists] = useState<boolean | undefined>(undefined);
|
const [poolExists, setPoolExists] = useState<boolean | undefined>(undefined);
|
||||||
const [fromTokenAccount, setFromTokenAccount] = useState<string | undefined>(
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
const [fromTokenAccountBalance, setFromTokenAccountBalance] = useState<
|
const [fromTokenAccountBalance, setFromTokenAccountBalance] = useState<
|
||||||
string | undefined
|
string | undefined
|
||||||
>(undefined);
|
>(undefined);
|
||||||
|
@ -254,23 +252,6 @@ export default function Workflow({
|
||||||
}
|
}
|
||||||
}, [poolAddress]);
|
}, [poolAddress]);
|
||||||
|
|
||||||
//Set the associated token accounts when the designated mint changes
|
|
||||||
useEffect(() => {
|
|
||||||
if (wallet?.publicKey && fromMint) {
|
|
||||||
Token.getAssociatedTokenAddress(
|
|
||||||
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
||||||
TOKEN_PROGRAM_ID,
|
|
||||||
new PublicKey(fromMint),
|
|
||||||
wallet?.publicKey || new PublicKey([])
|
|
||||||
).then(
|
|
||||||
(result) => {
|
|
||||||
setFromTokenAccount(result.toString());
|
|
||||||
},
|
|
||||||
(error) => {}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, [fromMint, wallet?.publicKey]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (wallet?.publicKey && toMint) {
|
if (wallet?.publicKey && toMint) {
|
||||||
Token.getAssociatedTokenAddress(
|
Token.getAssociatedTokenAddress(
|
||||||
|
@ -426,12 +407,11 @@ export default function Workflow({
|
||||||
Convert assets from legacy bridges to Wormhole V2 tokens
|
Convert assets from legacy bridges to Wormhole V2 tokens
|
||||||
</Typography>
|
</Typography>
|
||||||
<Divider className={classes.divider} />
|
<Divider className={classes.divider} />
|
||||||
|
|
||||||
<SolanaWalletKey />
|
<SolanaWalletKey />
|
||||||
<LowBalanceWarning chainId={CHAIN_ID_SOLANA} />
|
<div className={classes.spacer} />
|
||||||
{fromTokenAccount && toTokenAccount && fromTokenAccountBalance ? (
|
{fromTokenAccount && toTokenAccount ? (
|
||||||
<>
|
<>
|
||||||
<Typography variant="body2">
|
<Typography variant="body2" component="div">
|
||||||
<span>This will migrate</span>
|
<span>This will migrate</span>
|
||||||
{fromMintPretty}
|
{fromMintPretty}
|
||||||
<span>tokens in this account:</span>
|
<span>tokens in this account:</span>
|
||||||
|
@ -446,7 +426,7 @@ export default function Workflow({
|
||||||
})`}
|
})`}
|
||||||
</Typography>
|
</Typography>
|
||||||
<div className={classes.spacer} />
|
<div className={classes.spacer} />
|
||||||
<Typography variant="body2">
|
<Typography variant="body2" component="div">
|
||||||
<span>into </span>
|
<span>into </span>
|
||||||
{toMintPretty}
|
{toMintPretty}
|
||||||
<span> tokens in this account:</span>
|
<span> tokens in this account:</span>
|
||||||
|
@ -476,7 +456,7 @@ export default function Workflow({
|
||||||
{poolAddress && toCustodyAddress && toCustodyBalance ? (
|
{poolAddress && toCustodyAddress && toCustodyBalance ? (
|
||||||
<>
|
<>
|
||||||
<div className={classes.spacer} />
|
<div className={classes.spacer} />
|
||||||
<Typography variant="body2">
|
<Typography variant="body2" component="div">
|
||||||
<span>Using pool </span>
|
<span>Using pool </span>
|
||||||
<SmartAddress
|
<SmartAddress
|
||||||
address={poolAddress}
|
address={poolAddress}
|
||||||
|
|
|
@ -7,29 +7,46 @@ import { withRouter } from "react-router";
|
||||||
|
|
||||||
interface RouteParams {
|
interface RouteParams {
|
||||||
legacyAsset: string;
|
legacyAsset: string;
|
||||||
|
fromTokenAccount: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Migration extends RouteComponentProps<RouteParams> {}
|
interface Migration extends RouteComponentProps<RouteParams> {}
|
||||||
|
|
||||||
const MigrationRoot: React.FC<Migration> = (props) => {
|
const MigrationRoot: React.FC<Migration> = (props) => {
|
||||||
const legacyAsset: string = props.match.params.legacyAsset;
|
const legacyAsset: string = props.match.params.legacyAsset;
|
||||||
|
const fromTokenAccount: string = props.match.params.fromTokenAccount;
|
||||||
const targetAsset: string | undefined = MIGRATION_ASSET_MAP.get(legacyAsset);
|
const targetAsset: string | undefined = MIGRATION_ASSET_MAP.get(legacyAsset);
|
||||||
|
|
||||||
let fromMint: string | undefined = "";
|
let fromMint: string | undefined = "";
|
||||||
let toMint: string | undefined = "";
|
let toMint: string | undefined = "";
|
||||||
|
let fromTokenAcct: string | undefined = "";
|
||||||
try {
|
try {
|
||||||
fromMint = legacyAsset && new PublicKey(legacyAsset).toString();
|
fromMint = legacyAsset && new PublicKey(legacyAsset).toString();
|
||||||
toMint = targetAsset && new PublicKey(targetAsset).toString();
|
toMint = targetAsset && new PublicKey(targetAsset).toString();
|
||||||
|
fromTokenAcct =
|
||||||
|
fromTokenAccount && new PublicKey(fromTokenAccount).toString();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
if (fromMint && toMint) {
|
if (!fromMint || !toMint) {
|
||||||
return <Workflow fromMint={fromMint} toMint={toMint} />;
|
|
||||||
} else {
|
|
||||||
return (
|
return (
|
||||||
<Typography style={{ textAlign: "center" }}>
|
<Typography style={{ textAlign: "center" }}>
|
||||||
This asset is not eligible for migration.
|
This asset is not eligible for migration.
|
||||||
</Typography>
|
</Typography>
|
||||||
);
|
);
|
||||||
|
} else if (!fromTokenAcct) {
|
||||||
|
return (
|
||||||
|
<Typography style={{ textAlign: "center" }}>
|
||||||
|
Invalid token account.
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<Workflow
|
||||||
|
fromMint={fromMint}
|
||||||
|
toMint={toMint}
|
||||||
|
fromTokenAccount={fromTokenAcct}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,9 @@ function Source({
|
||||||
const shouldLockFields = useSelector(selectTransferShouldLockFields);
|
const shouldLockFields = useSelector(selectTransferShouldLockFields);
|
||||||
const { isReady, statusMessage } = useIsWalletReady(sourceChain);
|
const { isReady, statusMessage } = useIsWalletReady(sourceChain);
|
||||||
const handleMigrationClick = useCallback(() => {
|
const handleMigrationClick = useCallback(() => {
|
||||||
parsedTokenAccount?.mintKey &&
|
history.push(
|
||||||
history.push("/migrate/" + parsedTokenAccount.mintKey);
|
`/migrate/${parsedTokenAccount?.mintKey}/${parsedTokenAccount?.publicKey}`
|
||||||
|
);
|
||||||
}, [history, parsedTokenAccount]);
|
}, [history, parsedTokenAccount]);
|
||||||
const handleSourceChange = useCallback(
|
const handleSourceChange = useCallback(
|
||||||
(event) => {
|
(event) => {
|
||||||
|
|
Loading…
Reference in New Issue