Skip to content

Commit

Permalink
Merge branch 'stage' into mattupham/fe-513-eslint-disallow-default-ex…
Browse files Browse the repository at this point in the history
…ports
  • Loading branch information
mattupham committed Jun 6, 2024
2 parents a50fbc5 + daf9bef commit 796391b
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"prettier": "^2.8.8",
"ts-jest": "^29.1.2",
"turbo": "^1.13.3",
"typescript": "5.4.3"
"typescript": "5.4.5"
},
"packageManager": "[email protected]",
"resolutions": {
Expand Down
51 changes: 51 additions & 0 deletions packages/tx/src/__tests__/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ describe("getSumTotalSpenderCoinsSpent", () => {

expect(coins).toEqual([]);
});

it("should only total the amounts for the specified sender", () => {
const coins = getSumTotalSpenderCoinsSpent(
"osmo1gtgx92pxk6hvhc3c3g0xlkrwqq6knymu0e0caw",
mockMultipleEvents
);

// Expected result is the sum of the amounts for the specified sender, not for osmo13vhcd3xllpvz8tql4dzp8yszxeas8zxpzptyvjttdy7m64kuyz5sv6caqq
const expectedResult = [
{
denom:
"factory/osmo1z0qrq605sjgcqpylfl4aa6s90x738j7m58wyatt0tdzflg2ha26q67k743/wbtc",
amount: "58573",
},
{
denom:
"ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5",
amount: "21083680327000100",
},
{
denom:
"ibc/F4A070A6D78496D53127EA85C094A9EC87DFC1F36071B8CCDDBD020F933D213D",
amount: "131211643845355500",
},
{ denom: "uosmo", amount: "95799380" },
];

expect(coins).toEqual(expectedResult);
});
});

describe("matchRawCoinValue", () => {
Expand Down Expand Up @@ -225,4 +254,26 @@ const mockMultipleEvents = [
},
],
},
{
type: "coin_spent",
attributes: [
{
key: "spender",
value:
"osmo13vhcd3xllpvz8tql4dzp8yszxeas8zxpzptyvjttdy7m64kuyz5sv6caqq",
index: true,
},
{
key: "amount",
value:
"2605ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
index: true,
},
{
key: "msg_index",
value: "0",
index: true,
},
],
},
];
3 changes: 2 additions & 1 deletion packages/tx/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function getSumTotalSpenderCoinsSpent(
if (type !== "coin_spent") return;
if (attributes.length === 0) return;
const spendAttribute = attributes.find((attr) => attr.key === "spender");
if (spendAttribute && spendAttribute.value !== spenderBech32Address) return;
if (!spendAttribute || spendAttribute.value !== spenderBech32Address)
return;

// a comma separated list of coins spent
const coinsSpentRawAttribute = attributes.find(
Expand Down
12 changes: 9 additions & 3 deletions packages/tx/src/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,15 @@ export async function getGasFeeAmount({
bech32Address,
}),
]);
const feeBalances = balances.filter((balance) =>
chainFeeDenoms.includes(balance.denom)
);
const feeBalances: { denom: string; amount: string }[] = [];

// iterate in order of fee denoms
for (const denom of chainFeeDenoms) {
const balance = balances.find((balance) => balance.denom === denom);
if (balance) {
feeBalances.push(balance);
}
}

if (!feeBalances.length) {
throw new InsufficientFeeError(
Expand Down
9 changes: 3 additions & 6 deletions packages/web/components/swap-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,10 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
});
}
})
.catch((error) => {
console.error("swap failed", error);
if (error instanceof Error && error.message === "Request rejected") {
// don't log when the user rejects in wallet
return;
.catch((e) => {
if (e instanceof Error && e.message.includes("Failed to send")) {
logEvent([EventName.Swap.swapFailed, baseEvent]);
}
logEvent([EventName.Swap.swapFailed, baseEvent]);
})
.finally(() => {
setIsSendingTx(false);
Expand Down
4 changes: 4 additions & 0 deletions packages/web/config/ibc-overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ const MainnetIBCAdditionalData: Partial<
depositUrlOverride: "https://app.picasso.network/?from=SOLANA&to=OSMOSIS",
withdrawUrlOverride: "https://app.picasso.network/?from=OSMOSIS&to=SOLANA",
},
WHINE: {
depositUrlOverride: "https://app.picasso.network/?from=SOLANA&to=OSMOSIS",
withdrawUrlOverride: "https://app.picasso.network/?from=OSMOSIS&to=SOLANA",
},
};

export const IBCAdditionalData: AdditionalData = IS_TESTNET
Expand Down
57 changes: 36 additions & 21 deletions packages/web/hooks/use-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ export function useSwap(
// includes check for quoteQueryEnabled
!isQuoteLoading &&
Boolean(quote) &&
Boolean(account?.address);
Boolean(account?.address) &&
inAmountInput.debouncedInAmount !== null &&
inAmountInput.balance &&
inAmountInput.debouncedInAmount.toDec().lte(inAmountInput.balance.toDec());
const {
data: networkFee,
error: networkFeeError,
Expand Down Expand Up @@ -269,14 +272,18 @@ export function useSwap(
() =>
new Promise<"multiroute" | "multihop" | "exact-in">(
async (resolve, reject) => {
if (!maxSlippage) return reject("No max slippage");
if (!inAmountInput.amount) return reject("No input amount");
if (!account) return reject("No account");
if (!swapAssets.fromAsset) return reject("No from asset");
if (!swapAssets.toAsset) return reject("No to asset");
if (!maxSlippage)
return reject(new Error("Max slippage is not defined."));
if (!inAmountInput.amount)
return reject(new Error("Input amount is not specified."));
if (!account)
return reject(new Error("Account information is missing."));
if (!swapAssets.fromAsset)
return reject(new Error("From asset is not specified."));
if (!swapAssets.toAsset)
return reject(new Error("To asset is not specified."));

let txParams: ReturnType<typeof getSwapTxParameters>;

try {
txParams = getSwapTxParameters({
coinAmount: inAmountInput.amount.toCoin().amount,
Expand All @@ -287,7 +294,9 @@ export function useSwap(
});
} catch (e) {
const error = e as Error;
return reject(error.message);
return reject(
new Error(`Transaction preparation failed: ${error.message}`)
);
}

const { routes, tokenIn, tokenOutMinAmount } = txParams;
Expand Down Expand Up @@ -344,7 +353,7 @@ export function useSwap(
);
});
} catch (e) {
return reject("Rejected manual approval");
return reject(new Error("Rejected manual approval"));
}
}

Expand Down Expand Up @@ -373,14 +382,15 @@ export function useSwap(
tokenOutMinAmount,
undefined,
signOptions,
() => {
resolve(pools.length === 1 ? "exact-in" : "multihop");
({ code }) => {
if (code)
reject(
new Error("Failed to send swap exact amount in message")
);
else resolve(pools.length === 1 ? "exact-in" : "multihop");
}
)
.catch((reason) => {
reject(reason);
});
return pools.length === 1 ? "exact-in" : "multihop";
.catch(reject);
} else if (routes.length > 1) {
account.osmosis
.sendSplitRouteSwapExactAmountInMsg(
Expand All @@ -389,15 +399,20 @@ export function useSwap(
tokenOutMinAmount,
undefined,
signOptions,
() => {
resolve("multiroute");
({ code }) => {
if (code)
reject(
new Error(
"Failed to send split route swap exact amount in message"
)
);
else resolve("multiroute");
}
)
.catch((reason) => {
reject(reason);
});
.catch(reject);
} else {
reject("No routes given");
// should not be possible because button should be disabled
reject(new Error("No routes given"));
}
}
).finally(() => {
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25447,12 +25447,7 @@ typeforce@^1.11.3, typeforce@^1.11.5, typeforce@^1.18.0:
resolved "https://registry.npmjs.org/typeforce/-/typeforce-1.18.0.tgz"
integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==

[email protected]:
version "5.4.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff"
integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==

"typescript@>=3 < 6", typescript@^5.4.5:
[email protected], "typescript@>=3 < 6", typescript@^5.4.5:
version "5.4.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611"
integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==
Expand Down

0 comments on commit 796391b

Please sign in to comment.