Skip to content

Commit

Permalink
chore(ui): evm to solana swap
Browse files Browse the repository at this point in the history
  • Loading branch information
ramenuncle committed Oct 25, 2022
1 parent 58b95d9 commit 21ff312
Show file tree
Hide file tree
Showing 12 changed files with 785 additions and 178 deletions.
2 changes: 1 addition & 1 deletion apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@swim-io/evm": "^0.40.0",
"@swim-io/evm-contracts": "^0.40.0",
"@swim-io/pool-math": "^0.40.0",
"@swim-io/solana": "^0.40.0",
"@swim-io/solana": "workspace:^",
"@swim-io/solana-contracts": "^0.40.0",
"@swim-io/token-projects": "^0.40.0",
"@swim-io/utils": "^0.40.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
import { EuiLoadingSpinner, EuiText } from "@elastic/eui";
import type { TokenConfig } from "@swim-io/core/types";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import type { VFC } from "react";
import { useTranslation } from "react-i18next";

import { useSwimUsd } from "../../hooks";

import { TxEcosystemList } from "./TxList";

interface Props {
readonly isLoading: boolean;
readonly tokenConfig: TokenConfig;
readonly transactions: readonly string[];
}

export const ClaimSwimUsdOnSolana: VFC<Props> = ({
export const ClaimTokenOnSolana: VFC<Props> = ({
isLoading,
tokenConfig,
transactions,
}) => {
const { t } = useTranslation();
const swimUsd = useSwimUsd();

if (swimUsd === null) {
return null;
}

return (
<EuiText size="m">
<span style={{ display: "flex", alignItems: "center" }}>
{isLoading && <EuiLoadingSpinner size="m" style={{ marginRight: 8 }} />}
<span>
{t("recent_interactions.claim_token_on_solana", {
tokenName: TOKEN_PROJECTS_BY_ID[swimUsd.projectId].displayName,
tokenName: TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].displayName,
})}
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
isTargetChainOperationCompleted,
} from "../../../models";
import { AddTransfer } from "../AddTransfer";
import { ClaimSwimUsdOnSolana } from "../ClaimSwimUsdOnSolana";
import { ClaimTokenOnSolana } from "../ClaimTokenOnSolana";
import { RemoveTransfer } from "../RemoveTransfer";
import { SwapFromSwimUsd } from "../SwapFromSwimUsd";
import { SwapToSwimUsd } from "../SwapToSwimUsd";
Expand Down Expand Up @@ -314,9 +314,10 @@ const buildClaimTokenOnSolanaStep = (
interactionStatus: InteractionStatusV2,
): EuiStepProps => {
const {
claimTokenOnSolanaTxId,
postVaaOnSolanaTxIds,
swapFromSwimUsdTxId,
verifySignatureTxId,
postVaaOnSolanaTxId,
completeNativeWithPayloadTxId,
processSwimPayloadTxId,
interaction: {
params: { toTokenData },
},
Expand All @@ -333,21 +334,18 @@ const buildClaimTokenOnSolanaStep = (
status,
children: (
<>
<ClaimSwimUsdOnSolana
isLoading={status === "loading" && claimTokenOnSolanaTxId === null}
<ClaimTokenOnSolana
isLoading={
status === "loading" && completeNativeWithPayloadTxId === null
}
tokenConfig={toTokenData.tokenConfig}
transactions={[
...postVaaOnSolanaTxIds,
claimTokenOnSolanaTxId,
verifySignatureTxId,
postVaaOnSolanaTxId,
completeNativeWithPayloadTxId,
processSwimPayloadTxId,
].filter(isNotNull)}
/>
{!isSwimUsd(toTokenData.tokenConfig) && (
<SwapFromSwimUsd
ecosystemId={toTokenData.ecosystemId}
toToken={toTokenData.tokenConfig}
isLoading={status === "loading"}
txId={swapFromSwimUsdTxId}
/>
)}
</>
),
};
Expand Down
15 changes: 8 additions & 7 deletions apps/ui/src/fixtures/swim/interactionStateV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,11 @@ export const CROSS_CHAIN_EVM_TO_SOLANA_SWAP_INTERACTION_STATE_INIT: CrossChainEv
requiredSplTokenAccounts: SPL_TOKEN_ACCOUNTS_INIT,
approvalTxIds: [],
crossChainInitiateTxId: null,
signatureSetAddress: null,
postVaaOnSolanaTxIds: [],
claimTokenOnSolanaTxId: null,
swapFromSwimUsdTxId: null,
auxiliarySignerPublicKey: null,
verifySignatureTxId: null,
postVaaOnSolanaTxId: null,
completeNativeWithPayloadTxId: null,
processSwimPayloadTxId: null,
};

export const CROSS_CHAIN_EVM_TO_SOLANA_SWAP_INTERACTION_STATE_EXISTING_SPL_TOKEN_ACCOUNTS: CrossChainEvmToSolanaSwapInteractionState =
Expand All @@ -398,16 +399,16 @@ export const CROSS_CHAIN_EVM_TO_SOLANA_SWAP_INTERACTION_STATE_SWAP_AND_TRANSFER_
export const CROSS_CHAIN_EVM_TO_SOLANA_SWAP_INTERACTION_STATE_POST_VAA_COMPLETED: CrossChainEvmToSolanaSwapInteractionState =
{
...CROSS_CHAIN_EVM_TO_SOLANA_SWAP_INTERACTION_STATE_SWAP_AND_TRANSFER_COMPLETED,
postVaaOnSolanaTxIds: [
verifySignatureTxId:
"53r98E5EiffkmJ6WVA2VKmq78LVCT4zcRVxo76EWoUFiNpdxbno7UVeUT6oQgsVM3xeU99mQmnUjFVscz7PC1gK8",
postVaaOnSolanaTxId:
"53r98E5EiffkmJ6WVA2VKmq78LVCT4zcRVxo76EWoUFiNpdxbno7UVeUT6oQgsVM3xeU99mQmnUjFVscz7PC1gK9",
],
};

export const CROSS_CHAIN_EVM_TO_SOLANA_SWAP_INTERACTION_STATE_COMPLETED: CrossChainEvmToSolanaSwapInteractionState =
{
...CROSS_CHAIN_EVM_TO_SOLANA_SWAP_INTERACTION_STATE_POST_VAA_COMPLETED,
claimTokenOnSolanaTxId:
completeNativeWithPayloadTxId:
"53r98E5EiffkmJ6WVA2VKmq78LVCT4zcRVxo76EWoUFiNpdxbno7UVeUT6oQgsVM3xeU99mQmnUjFVscz7PC1gK8",
};

Expand Down
9 changes: 5 additions & 4 deletions apps/ui/src/hooks/interaction/useCreateInteractionStateV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ const createSwapInteractionState = (
requiredSplTokenAccounts,
approvalTxIds: [],
crossChainInitiateTxId: null,
signatureSetAddress: null,
postVaaOnSolanaTxIds: [],
claimTokenOnSolanaTxId: null,
swapFromSwimUsdTxId: null,
auxiliarySignerPublicKey: null,
verifySignatureTxId: null,
postVaaOnSolanaTxId: null,
completeNativeWithPayloadTxId: null,
processSwimPayloadTxId: null,
};
}
};
Expand Down
Loading

0 comments on commit 21ff312

Please sign in to comment.