Skip to content

Commit

Permalink
Merge branch 'osmosis-labs:stage' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Gamja authored Jul 24, 2024
2 parents 950472d + 0d0c72f commit 6a90c1d
Show file tree
Hide file tree
Showing 38 changed files with 1,653 additions and 253 deletions.
3 changes: 2 additions & 1 deletion packages/server/src/queries/complex/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function filterAssetList(
assetListAssets,
/** Search is performed on the raw asset list data, instead of `Asset` type. */
["symbol", "name"] as (keyof AssetListAsset)[],
params.search
params.search,
0.2
);
assetListAssets = symbolOrNameMatches;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/stores/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,15 @@ export class AccountStore<Injects extends Record<string, any>[] = []> {
throw new Error("One click trading info is not available");
}

if (memo === "") {
// If the memo is empty, set it to "1CT" so we know it originated from the frontend for
// QA purposes.
memo = "1CT";
} else {
// Otherwise, tack on "1CT" to the end of the memo.
memo += " \n1CT";
}

const pubkey = encodePubkey(
encodeSecp256k1Pubkey(accountFromSigner.pubkey)
);
Expand Down
19 changes: 11 additions & 8 deletions packages/tx/src/__tests__/gas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ describe("simulateCosmosTxBody", () => {
(queryBaseAccount as jest.Mock).mockResolvedValue({
account: {
"@type": BaseAccountTypeStr,
sequence: "1" },
sequence: "1",
},
} as Awaited<ReturnType<typeof queryBaseAccount>>);
(sendTxSimulate as jest.Mock).mockResolvedValue({
gas_info: { gas_used: "200000" },
Expand Down Expand Up @@ -73,11 +74,11 @@ describe("simulateCosmosTxBody", () => {
account: {
"@type": "non-base-type-assummed-vesting",
base_vesting_account: {
base_account: {
sequence: "1"
}
}
},
base_account: {
sequence: "1",
},
},
},
} as Awaited<ReturnType<typeof queryBaseAccount>>);
(sendTxSimulate as jest.Mock).mockResolvedValue({
gas_info: { gas_used: "200000" },
Expand Down Expand Up @@ -118,7 +119,8 @@ describe("simulateCosmosTxBody", () => {
(queryBaseAccount as jest.Mock).mockResolvedValue({
account: {
"@type": BaseAccountTypeStr,
sequence: "invalid" },
sequence: "invalid",
},
} as Awaited<ReturnType<typeof queryBaseAccount>>);

await expect(
Expand Down Expand Up @@ -204,7 +206,8 @@ describe("simulateCosmosTxBody", () => {
(queryBaseAccount as jest.Mock).mockResolvedValue({
account: {
"@type": BaseAccountTypeStr,
sequence: "1" },
sequence: "1",
},
});
(sendTxSimulate as jest.Mock).mockRejectedValue(new Error("Other error"));

Expand Down
4 changes: 2 additions & 2 deletions packages/tx/src/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function generateCosmosUnsignedTx({
bech32Address,
});

const sequence: number = parseSeqeunceFromAccount(account);
const sequence: number = parseSequenceFromAccount(account);

// create placeholder transaction document
const rawUnsignedTx = TxRaw.encode({
Expand Down Expand Up @@ -195,7 +195,7 @@ export async function generateCosmosUnsignedTx({
// Parses the sequence number from the account object.
// The structure of the account object is different for base and vesting accounts.
// Therefore, we need to check the type of the account object to parse the sequence number.
function parseSeqeunceFromAccount(account: any) {
function parseSequenceFromAccount(account: any) {
let sequence: number = 0;
if (account.account["@type"] === BaseAccountTypeStr) {
const base_acc = account as BaseAccount;
Expand Down
33 changes: 18 additions & 15 deletions packages/web/components/bridge/amount-and-review-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const AmountAndReviewScreen = observer(
enabled: !isNil(selectedAssetDenom),
cacheTime: 10 * 60 * 1000, // 10 minutes
staleTime: 10 * 60 * 1000, // 10 minutes
useErrorBoundary: true,
}
);

Expand All @@ -109,18 +110,15 @@ export const AmountAndReviewScreen = observer(
const assetSupportedBridges = new Set<Bridge>();

if (direction === "deposit" && fromAsset) {
Object.values(fromAsset.supportedVariants)
.flat()
.forEach((provider) => assetSupportedBridges.add(provider));
const providers = Object.values(fromAsset.supportedVariants).flat();
providers.forEach((provider) => assetSupportedBridges.add(provider));
} else if (direction === "withdraw" && fromAsset && toAsset) {
// withdraw
counterpartySupportedAssetsByChainId[toAsset.chainId].forEach(
(asset) => {
asset.supportedVariants[fromAsset.address]?.forEach((provider) => {
assetSupportedBridges.add(provider);
});
}
);
const counterpartyAssets =
counterpartySupportedAssetsByChainId[toAsset.chainId];
counterpartyAssets.forEach((asset) => {
const providers = asset.supportedVariants[fromAsset.address] || [];
providers.forEach((provider) => assetSupportedBridges.add(provider));
});
}

return Array.from(assetSupportedBridges).filter(
Expand Down Expand Up @@ -159,14 +157,19 @@ export const AmountAndReviewScreen = observer(
inputAmount: cryptoAmount,
bridges: quoteBridges,
onTransfer: () => {
// Ensures user queries are reset for other chains txs, since
// only cosmos txs reset queries from root store
if (
fromChain?.chainType !== "cosmos" ||
toChain?.chainType !== "cosmos"
) {
refetchUserQueries(apiUtils);
}

setToAsset(undefined);
setFromAsset(undefined);
setCryptoAmount("0");
setFiatAmount("0");

// redundantly ensures user queries are reset for EVM txs, since
// only cosmos txs reset queries from root store
refetchUserQueries(apiUtils);
},
});

Expand Down
40 changes: 24 additions & 16 deletions packages/web/components/bridge/amount-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const AmountScreen = observer(
bridgesSupportedAssets: {
supportedAssetsByChainId: counterpartySupportedAssetsByChainId,
supportedChains,
isLoading: isLoadingSupportedAssets,
},

fromChain,
Expand Down Expand Up @@ -209,9 +210,14 @@ export const AmountScreen = observer(
? evmAddress
: toCosmosCounterpartyAccount?.address;

const { data: osmosisChain } = api.edge.chains.getChain.useQuery({
findChainNameOrId: accountStore.osmosisChainId,
});
const { data: osmosisChain } = api.edge.chains.getChain.useQuery(
{
findChainNameOrId: accountStore.osmosisChainId,
},
{
useErrorBoundary: true,
}
);

const canonicalAsset = assetsInOsmosis?.[0];

Expand Down Expand Up @@ -572,7 +578,7 @@ export const AmountScreen = observer(

if (
isLoadingCanonicalAssetPrice ||
isNil(supportedSourceAssets) ||
isLoadingSupportedAssets ||
!assetsInOsmosis ||
!canonicalAsset ||
!assetInOsmosisPrice ||
Expand All @@ -584,6 +590,13 @@ export const AmountScreen = observer(
return <AmountScreenSkeletonLoader />;
}

/**
* This will trigger an error boundary
*/
if (!supportedSourceAssets) {
throw new Error("Supported source assets are not defined");
}

const resetAssets = () => {
setFromAsset(undefined);
setToAsset(undefined);
Expand Down Expand Up @@ -1096,24 +1109,19 @@ export const AmountScreen = observer(

<div className="flex flex-col items-center gap-4">
{!osmosisWalletConnected ? (
connectWalletButton
<>{connectWalletButton}</>
) : !isWalletNeededConnected || quote.isWrongEvmChainSelected ? (
<Button
onClick={() => checkChainAndConnectWallet()}
className="w-full"
>
<h6 className="flex items-center gap-3">
{quote.isWrongEvmChainSelected ? (
t("switchNetwork")
) : (
<>
<Icon
id="wallet"
className="text-white h-[24px] w-[24px]"
/>
{t("connectWallet")}
</>
)}
{t("transfer.connectTo", {
network:
direction === "deposit"
? fromChain.prettyName
: toChain.prettyName,
})}
</h6>
</Button>
) : (
Expand Down
34 changes: 20 additions & 14 deletions packages/web/components/bridge/asset-select-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,37 @@ export const AssetSelectScreen: FunctionComponent<AssetSelectScreenProps> =
alt={`${asset.coinDenom} asset image`}
/>
<span className="flex flex-col text-left">
<span className="subtitle1 md:body2">
{truncateString(asset.coinName, 22)}
</span>
<div className="flex items-center gap-1">
<span className="subtitle1 md:body2">
{truncateString(asset.coinName, 22)}
</span>
{!asset.isVerified && shouldShowUnverifiedAssets && (
<Tooltip
content={t(
"components.selectToken.unverifiedAsset"
)}
>
<Icon
id="alert-triangle"
className="h-4 w-4 text-osmoverse-400"
/>
</Tooltip>
)}
</div>

<span className="body2 md:caption text-osmoverse-300">
{asset.coinDenom}
</span>
</span>
</div>
{!asset.isVerified && shouldShowUnverifiedAssets && (
<Tooltip
content={t("components.selectToken.unverifiedAsset")}
>
<Icon
id="alert-triangle"
className="h-5 w-5 text-osmoverse-400"
/>
</Tooltip>
)}

{!shouldShowUnverifiedAssets && !asset.isVerified && (
<p className="caption whitespace-nowrap text-wosmongton-200">
{t("components.selectToken.clickToActivate")}
</p>
)}
{asset.amount &&
asset.isVerified &&
(shouldShowUnverifiedAssets || asset.isVerified) &&
asset.usdValue &&
asset.amount.toDec().isPositive() && (
<div className="flex flex-col text-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,23 @@ export const BridgeNetworkSelectModal: FunctionComponent<
"prettyName",
]);

const showSwitchingNetworkState = isEvmWalletConnected && isSwitchingEvmChain;

return (
<ModalBase
title={
<div className="md:subtitle1 mx-auto text-h6 font-h6">
{t("transfer.bridgeNetworkSelect.title")}
</div>
}
className="min-h-[80vh] !max-w-lg"
className={classNames("!max-w-lg", {
"min-h-[80vh]": !showSwitchingNetworkState,
})}
{...modalProps}
onAfterClose={() => setQuery("")}
>
<div className="animate-[fadeIn_0.25s]">
{isEvmWalletConnected && isSwitchingEvmChain && (
{showSwitchingNetworkState && (
<div className="flex items-center justify-center pt-12">
<SwitchingNetworkState
walletLogo={connector?.icon}
Expand Down
Loading

0 comments on commit 6a90c1d

Please sign in to comment.