Skip to content

Commit

Permalink
Merge pull request #131 from axelarnetwork/feat/share-haiku-on-x
Browse files Browse the repository at this point in the history
feat/share haiku on x
  • Loading branch information
canhtrinh authored Jan 11, 2024
2 parents 711749a + c0d77e0 commit 1f1800e
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 51 deletions.
5 changes: 5 additions & 0 deletions apps/maestro/public/logos/x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export const Step3: FC = () => {
async (e) => {
e.preventDefault();

if (
state.isEstimatingGasFees ||
state.hasGasFeesEstimationError ||
!state.remoteDeploymentGasFees ||
!state.evmChains ||
!deployCanonicalTokenAsync
) {
const hasGasfees =
!rootState.selectedChains.length ||
(state.totalGasFee &&
!state.isEstimatingGasFees &&
!state.hasGasFeesEstimationError);

if (!deployCanonicalTokenAsync || !hasGasfees) {
console.warn("gas prices not loaded");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useChainFromRoute } from "~/lib/hooks";
import { useEVMChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useInterchainTokensQuery } from "~/services/gmp/hooks";
import GMPTxStatusMonitor from "~/ui/compounds/GMPTxStatusMonitor";
import { ShareHaikuButton } from "~/ui/compounds/MultiStepForm";
import { persistTokenDeploymentTxHash } from "~/ui/pages/InterchainTokenDetailsPage/ConnectedInterchainTokensPage";
import { useCanonicalTokenDeploymentStateContainer } from "../../CanonicalTokenDeployment.state";

Expand Down Expand Up @@ -68,21 +69,28 @@ const Review: FC = () => {
<>
<div className="grid gap-4">
{state.txState.type === "deployed" && (
<Alert status="success">
<div className="flex justify-center font-semibold md:justify-start">
Origin token deployed successfully!
</div>
<div className="flex items-center justify-center md:justify-start">
Address:
<CopyToClipboardButton
copyText={state.txState.tokenAddress}
size="sm"
variant="ghost"
>
{maskAddress(state.txState.tokenAddress)}
</CopyToClipboardButton>
</div>
</Alert>
<>
<Alert status="success">
<div className="flex justify-center font-semibold md:justify-start">
Origin token deployed successfully!
</div>
<div className="flex items-center justify-center md:justify-start">
Address:
<CopyToClipboardButton
copyText={state.txState.tokenAddress}
size="sm"
variant="ghost"
>
{maskAddress(state.txState.tokenAddress)}
</CopyToClipboardButton>
</div>
</Alert>
<ShareHaikuButton
additionalChainNames={state.selectedChains}
originChainName={chain?.name ?? ""}
tokenName={state.tokenDetails.tokenName}
/>
</>
)}
{(state.txState.type === "deployed" ||
state.txState.type === "deploying") && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
}, [input, tokenId, withDecimals, destinationChainNames, originalChainName]);

const totalGasFee = useMemo(() => {
const remoteDeploymentsGas = Maybe.of(input?.remoteDeploymentGasFees).mapOr(
0n,
reduce((a, b) => a + b, 0n)
);
const remoteDeploymentsGas = Maybe.of(
input?.remoteDeploymentGasFees
).mapOrUndefined(reduce((a, b) => a + b, 0n));

// the total gas fee is the sum of the remote deployments gas fee,
// the remote transfers gas fee and the origin transfer gas fee
Expand All @@ -152,7 +151,9 @@ export function useDeployAndRegisterRemoteInterchainTokenMutation(
chainId,
value: totalGasFee,
args: [multicallArgs],
enabled: multicallArgs.length > 0 && totalGasFee > 0n,
enabled:
multicallArgs.length > 0 &&
(totalGasFee === undefined || totalGasFee > 0n),
});

const multicall = useInterchainTokenFactoryMulticall(prepareMulticall.config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export const Step3: FC = () => {
async (e) => {
e.preventDefault();

if (
state.isEstimatingGasFees ||
state.hasGasFeesEstimationError ||
!state.remoteDeploymentGasFees ||
!state.evmChains ||
!deployInterchainTokenAsync
) {
const hasGasfees =
!rootState.selectedChains.length ||
(state.totalGasFee &&
!state.isEstimatingGasFees &&
!state.hasGasFeesEstimationError);

if (!deployInterchainTokenAsync || !hasGasfees) {
console.warn("gas prices not loaded");
return;
}
Expand Down Expand Up @@ -109,10 +109,10 @@ export const Step3: FC = () => {
});
},
[
rootState.selectedChains.length,
state.totalGasFee,
state.isEstimatingGasFees,
state.hasGasFeesEstimationError,
state.remoteDeploymentGasFees,
state.evmChains,
deployInterchainTokenAsync,
actions,
sourceChain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useChainFromRoute } from "~/lib/hooks";
import { useEVMChainConfigsQuery } from "~/services/axelarscan/hooks";
import { useInterchainTokensQuery } from "~/services/gmp/hooks";
import GMPTxStatusMonitor from "~/ui/compounds/GMPTxStatusMonitor";
import { ShareHaikuButton } from "~/ui/compounds/MultiStepForm";
import { persistTokenDeploymentTxHash } from "~/ui/pages/InterchainTokenDetailsPage/ConnectedInterchainTokensPage";
import { useInterchainTokenDeploymentStateContainer } from "../../InterchainTokenDeployment.state";

Expand Down Expand Up @@ -68,21 +69,28 @@ const Review: FC = () => {
<>
<div className="grid gap-4">
{state.txState.type === "deployed" && (
<Alert status="success">
<div className="flex justify-center font-semibold md:justify-start">
Origin token deployed successfully!
</div>
<div className="flex items-center justify-center md:justify-start">
Address:
<CopyToClipboardButton
copyText={state.txState.tokenAddress}
size="sm"
variant="ghost"
>
{maskAddress(state.txState.tokenAddress)}
</CopyToClipboardButton>
</div>
</Alert>
<>
<Alert status="success">
<div className="flex justify-center font-semibold md:justify-start">
Origin token deployed successfully!
</div>
<div className="flex items-center justify-center md:justify-start">
Address:
<CopyToClipboardButton
copyText={state.txState.tokenAddress}
size="sm"
variant="ghost"
>
{maskAddress(state.txState.tokenAddress)}
</CopyToClipboardButton>
</div>
</Alert>
<ShareHaikuButton
additionalChainNames={state.selectedChains}
originChainName={chain?.name ?? ""}
tokenName={state.tokenDetails.tokenName}
/>
</>
)}
{(state.txState.type === "deployed" ||
state.txState.type === "deploying") && (
Expand Down
59 changes: 59 additions & 0 deletions apps/maestro/src/ui/compounds/MultiStepForm/MultiStepForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import tw from "@axelarjs/ui/tw";
import {
useCallback,
useMemo,
type ComponentProps,
type FC,
type PropsWithChildren,
Expand All @@ -24,6 +25,8 @@ import { useSession } from "next-auth/react";

import { useAccount } from "wagmi";

import { trpc } from "~/lib/trpc";
import { useEVMChainConfigsQuery } from "~/services/axelarscan/hooks";
import EVMChainsDropdown from "~/ui/components/EVMChainsDropdown";
import ConnectWalletButton from "../ConnectWalletButton";

Expand Down Expand Up @@ -206,3 +209,59 @@ export const MultiStepDialog: FC<ProtectedDialogProps> = ({
</Dialog>
);
};

export const ShareHaikuButton: FC<{
tokenName: string;
originChainName: string;
additionalChainNames: string[];
}> = (props) => {
const { mutateAsync, isLoading, isSuccess } =
trpc.openai.generateInterchainDeploymentHaiku.useMutation();

const { computed } = useEVMChainConfigsQuery();

const additionalChainNames = useMemo(() => {
return props.additionalChainNames.map((chainName) => {
const chain = computed.indexedById[chainName];
return chain?.name ?? "";
});
}, [computed, props.additionalChainNames]);

const handleShareHaiku = useCallback(async () => {
try {
const { value } = await mutateAsync({ ...props, additionalChainNames });

// redirect to twitter with haiku
const url = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
value.trim()
)}`;

window.open(url, "_blank");
} catch (error) {
console.error(error);
}
}, [additionalChainNames, mutateAsync, props]);

return (
<Button
onClick={handleShareHaiku}
loading={isLoading}
disabled={isLoading || isSuccess}
className="bg-black"
aria-label="Share my token deployment on X"
>
<svg
height="1em"
viewBox="0 0 1200 1227"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M714.163 519.284L1160.89 0H1055.03L667.137 450.887L357.328 0H0L468.492 681.821L0 1226.37H105.866L515.491 750.218L842.672 1226.37H1200L714.137 519.284H714.163ZM569.165 687.828L521.697 619.934L144.011 79.6944H306.615L611.412 515.685L658.88 583.579L1055.08 1150.3H892.476L569.165 687.854V687.828Z"
fill="white"
/>
</svg>
{isSuccess ? "Done!" : "Share my token deployment"}
</Button>
);
};

2 comments on commit 1f1800e

@vercel
Copy link

@vercel vercel bot commented on 1f1800e Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

axelar-registry – ./apps/registry

axelar-registry-axelar-network.vercel.app
axelar-registry-git-main-axelar-network.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 1f1800e Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

axelar-ui – ./packages/ui

axelar-ui-axelar-network.vercel.app
axelar-ui-git-main-axelar-network.vercel.app
axelar-ui.vercel.app
ui.axelar.dev

Please sign in to comment.