Skip to content

Commit

Permalink
fix send cosmos tx (use from chain)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed Jul 2, 2024
1 parent 944c4d9 commit 12fcb5b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const BridgeProviderDropdown = ({
)}
onClick={() => onSelect(provider.id)}
>
<div className="flex items-center gap-2">
<div className="flex items-center gap-3">
<Image
src={provider.logoUrl}
alt={`${provider.id} logo`}
Expand All @@ -148,7 +148,7 @@ export const BridgeProviderDropdown = ({
</div>
</div>

<div className="flex flex-col text-start">
<div className="flex flex-col text-end">
<p className="body1">{expectedOutputFiat.toString()}</p>
<p className="body2 whitespace-nowrap text-osmoverse-200">
~{totalFee} {t("transfer.fee")}
Expand Down
7 changes: 6 additions & 1 deletion packages/web/components/bridge/immersive/review-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ export const ReviewScreen: FunctionComponent<ConfirmationScreenProps> = ({
/>
)}
<div className="flex w-full items-center gap-3 py-3">
<Button className="w-full" variant="secondary" onClick={onCancel}>
<Button
className="w-full"
variant="secondary"
onClick={onCancel}
disabled={quote.isTxPending}
>
<h6>{t("transfer.cancel")}</h6>
</Button>
<Button
Expand Down
34 changes: 17 additions & 17 deletions packages/web/components/bridge/immersive/use-bridge-quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,10 @@ export const useBridgeQuotes = ({
]
);

const [isApprovingToken, setIsApprovingToken] = useState(false);

const isTxPending = (() => {
if (!toChain) return false;
return toChain.chainType === "cosmos"
? accountStore.getWallet(toChain.chainId)?.txTypeInProgress !== ""
if (!fromChain) return false;
return fromChain.chainType === "cosmos"
? accountStore.getWallet(fromChain.chainId)?.txTypeInProgress !== ""
: isEthTxPending;
})();

Expand All @@ -427,6 +425,7 @@ export const useBridgeQuotes = ({
}
}, [isTxPending, onRequestClose, transferInitiated]);

const [isApprovingToken, setIsApprovingToken] = useState(false);
const handleEvmTx = async (
quote: NonNullable<typeof selectedQuote>["quote"]
) => {
Expand Down Expand Up @@ -503,13 +502,13 @@ export const useBridgeQuotes = ({
const handleCosmosTx = async (
quote: NonNullable<typeof selectedQuote>["quote"]
) => {
if (!toChain || toChain?.chainType !== "cosmos") {
throw new Error("Destination chain is not cosmos");
if (!fromChain || fromChain?.chainType !== "cosmos") {
throw new Error("Initiating chain is not cosmos");
}
const transactionRequest =
quote.transactionRequest as CosmosBridgeTransactionRequest;
return accountStore.signAndBroadcast(
toChain.chainId,
fromChain.chainId,
transactionRequest.msgTypeUrl,
[
{
Expand All @@ -522,7 +521,7 @@ export const useBridgeQuotes = ({
undefined,
(tx: DeliverTxResponse) => {
if (tx.code == null || tx.code === 0) {
const queries = queriesStore.get(toChain.chainId);
const queries = queriesStore.get(fromChain.chainId);

// After succeeding to send token, refresh the balance.
const queryBalance = queries.queryBalances
Expand Down Expand Up @@ -560,14 +559,14 @@ export const useBridgeQuotes = ({

if (!transactionRequest || !quote) return;

if (transactionRequest.type === "evm") {
await handleEvmTx({ ...quote, transactionRequest });
} else if (transactionRequest.type === "cosmos") {
await handleCosmosTx({
...quote,
transactionRequest,
});
}
const tx =
transactionRequest.type === "evm"
? handleEvmTx({ ...quote, transactionRequest })
: handleCosmosTx({ ...quote, transactionRequest });

await tx.catch((e) => {
console.error(transactionRequest.type, "transaction failed", e);
});
};

const hasNoQuotes = someError?.message.includes(
Expand Down Expand Up @@ -662,6 +661,7 @@ export const useBridgeQuotes = ({
refetchInterval,

userCanInteract,
isTxPending,
onTransfer,

isApprovingToken,
Expand Down

0 comments on commit 12fcb5b

Please sign in to comment.