Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(1CT) Rename Modified Chain Properties #3302

Merged
merged 9 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/stores/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ export class AccountStore<Injects extends Record<string, any>[] = []> {
}) as Uint8Array;

const privateKey = new PrivKeySecp256k1(
fromBase64(oneClickTradingInfo.privateKey)
fromBase64(oneClickTradingInfo.sessionKey)
);

const gasLimit = Int53.fromString(String(fee.gas)).toNumber();
Expand Down
6 changes: 1 addition & 5 deletions packages/stores/src/account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
Currency,
OneClickTradingHumanizedSessionPeriod,
OneClickTradingResetPeriods,
OneClickTradingTimeLimit,
} from "@osmosis-labs/types";
import { MsgData } from "cosmjs-types/cosmos/base/abci/v1beta1/abci";
Expand Down Expand Up @@ -103,7 +102,7 @@ export interface TxEvents {
export interface OneClickTradingInfo {
readonly authenticatorId: string;
readonly publicKey: string;
readonly privateKey: string;
readonly sessionKey: string;
readonly userOsmoAddress: string;

networkFeeLimit: Currency & {
Expand All @@ -115,9 +114,6 @@ export interface OneClickTradingInfo {
amount: string;
};

// Period to reset the spend limit quota.
readonly resetPeriod: OneClickTradingResetPeriods;

// Time limit for the session to be considered valid.
readonly sessionPeriod: OneClickTradingTimeLimit;
readonly humanizedSessionPeriod: OneClickTradingHumanizedSessionPeriod;
Expand Down
22 changes: 6 additions & 16 deletions packages/trpc/src/one-click-trading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
getFeeTokenGasPriceStep,
getSessionAuthenticator,
queryAuthenticatorSpendLimit,
queryBaseAccount,
} from "@osmosis-labs/server";
import {
AssetList,
Expand All @@ -27,7 +26,7 @@ export const oneClickTradingRouter = createTRPCRouter({
}): Promise<
Pick<
OneClickTradingTransactionParams,
"networkFeeLimit" | "resetPeriod" | "spendLimit" | "sessionPeriod"
"networkFeeLimit" | "spendLimit" | "sessionPeriod"
> & {
spendLimitTokenDecimals: number;
}
Expand All @@ -44,7 +43,6 @@ export const oneClickTradingRouter = createTRPCRouter({
spendLimit: new PricePretty(DEFAULT_VS_CURRENCY, new Dec(5_000)),
spendLimitTokenDecimals: usdcAsset.coinDecimals,
networkFeeLimit: networkFeeLimitStep.average,
resetPeriod: "day" as const,
sessionPeriod: {
end: "1hour" as const,
},
Expand Down Expand Up @@ -77,24 +75,16 @@ export const oneClickTradingRouter = createTRPCRouter({

return sessionAuthenticator;
}),
getAccountPubKeyAndAuthenticators: publicProcedure
getAuthenticators: publicProcedure
.input(UserOsmoAddressSchema.required())
.query(async ({ input, ctx }) => {
const [cosmosAccount, authenticators] = await Promise.all([
queryBaseAccount({
bech32Address: input.userOsmoAddress,
chainList: ctx.chainList,
}),
getAuthenticators({
userOsmoAddress: input.userOsmoAddress,
chainList: ctx.chainList,
}),
]);
const authenticators = await getAuthenticators({
userOsmoAddress: input.userOsmoAddress,
chainList: ctx.chainList,
});

return {
accountPubKey: cosmosAccount.account.pub_key?.key,
authenticators,
shouldAddFirstAuthenticator: authenticators.length === 0,
};
}),
getAmountSpent: publicProcedure
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/autheticator-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export interface RawAuthenticator {
}

export interface RawNestedAuthenticator {
Config: string;
Type: AuthenticatorType;
config: string;
type: AuthenticatorType;
}

export interface MessageFilterAuthenticator {
Expand Down
3 changes: 0 additions & 3 deletions packages/types/src/one-click-trading-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export interface OneClickTradingTransactionParams {
spendLimit: PricePretty;
networkFeeLimit: CoinPretty;

// Period to reset the spend limit quota.
resetPeriod: OneClickTradingResetPeriods;

// Time limit for the session to be considered valid.
sessionPeriod: {
end: OneClickTradingHumanizedSessionPeriod;
Expand Down
22 changes: 11 additions & 11 deletions packages/utils/src/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ export function parseNestedAuthenticator({
authenticator: RawNestedAuthenticator;
}): NestedAuthenticator {
try {
if (rawNestedAuthenticator.Type === "SignatureVerification") {
if (rawNestedAuthenticator.type === "SignatureVerification") {
return {
type: "SignatureVerification",
publicKey: rawNestedAuthenticator.Config,
publicKey: rawNestedAuthenticator.config,
};
}

if (rawNestedAuthenticator.Type === "CosmwasmAuthenticatorV1") {
if (rawNestedAuthenticator.type === "CosmwasmAuthenticatorV1") {
const parsedData: { contract: string; params: string } = JSON.parse(
Buffer.from(rawNestedAuthenticator.Config, "base64").toString("utf-8")
Buffer.from(rawNestedAuthenticator.config, "base64").toString("utf-8")
);
const parsedParams = JSON.parse(
Buffer.from(parsedData.params, "base64").toString("utf-8")
Expand All @@ -107,9 +107,9 @@ export function parseNestedAuthenticator({
} as CosmwasmAuthenticatorV1;
}

if (rawNestedAuthenticator.Type === "MessageFilter") {
if (rawNestedAuthenticator.type === "MessageFilter") {
const parsedData: { "@type": string } = JSON.parse(
Buffer.from(rawNestedAuthenticator.Config, "base64").toString("utf-8")
Buffer.from(rawNestedAuthenticator.config, "base64").toString("utf-8")
);
return {
type: "MessageFilter",
Expand All @@ -118,15 +118,15 @@ export function parseNestedAuthenticator({
}

if (
rawNestedAuthenticator.Type === "AnyOf" ||
rawNestedAuthenticator.Type === "AllOf"
rawNestedAuthenticator.type === "AnyOf" ||
rawNestedAuthenticator.type === "AllOf"
) {
const subAuthenticators: RawNestedAuthenticator[] = JSON.parse(
Buffer.from(rawNestedAuthenticator.Config, "base64").toString("utf-8")
Buffer.from(rawNestedAuthenticator.config, "base64").toString("utf-8")
);

return {
type: rawNestedAuthenticator.Type,
type: rawNestedAuthenticator.type,
subAuthenticators: subAuthenticators.map(
(subAuthenticator: RawNestedAuthenticator) => {
return parseNestedAuthenticator({
Expand All @@ -138,7 +138,7 @@ export function parseNestedAuthenticator({
}

throw new Error(
`Unknown nested authenticator type: ${rawNestedAuthenticator.Type}`
`Unknown nested authenticator type: ${rawNestedAuthenticator.type}`
);
} catch (error) {
console.error("Error parsing nested authenticator:", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe("compare1CTTransactionParams", () => {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

Expand All @@ -38,7 +37,6 @@ describe("compare1CTTransactionParams", () => {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

Expand All @@ -56,7 +54,6 @@ describe("compare1CTTransactionParams", () => {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

Expand All @@ -69,45 +66,24 @@ describe("compare1CTTransactionParams", () => {
expect(changes).toContain("networkFeeLimit");
});

it("should detect changes in resetPeriod", () => {
const prevParams: OneClickTradingTransactionParams = {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

const nextParams: OneClickTradingTransactionParams = {
...prevParams,
resetPeriod: "week",
};

const changes = compare1CTTransactionParams({ prevParams, nextParams });
expect(changes).toContain("resetPeriod");
});

it("should detect multiple changes including sessionPeriod", () => {
const prevParams: OneClickTradingTransactionParams = {
isOneClickEnabled: true,
spendLimit: mockPricePretty(5000),
networkFeeLimit: mockCoinPretty(13485),
resetPeriod: "day",
sessionPeriod: { end: "1hour" },
};

const nextParams: OneClickTradingTransactionParams = {
...prevParams,
spendLimit: mockPricePretty(7000),
networkFeeLimit: mockCoinPretty(16000),
resetPeriod: "month",
sessionPeriod: { end: "3hours" },
};

const changes = compare1CTTransactionParams({ prevParams, nextParams });
expect(changes).toContain("spendLimit");
expect(changes).toContain("networkFeeLimit");
expect(changes).toContain("resetPeriod");
expect(changes).toContain("sessionPeriod");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import { Icon } from "~/components/assets";
import { Spinner } from "~/components/loaders";
import { SkeletonLoader } from "~/components/loaders/skeleton-loader";
import { NetworkFeeLimitScreen } from "~/components/one-click-trading/screens/network-fee-limit-screen";
import {
getResetPeriodTranslationKey,
ResetPeriodScreen,
} from "~/components/one-click-trading/screens/reset-period-screen";
import {
getSessionPeriodTranslationKey,
SessionPeriodScreen,
Expand Down Expand Up @@ -47,7 +43,6 @@ enum SettingsScreens {
SpendLimit = "spendLimit",
NetworkFeeLimit = "networkFeeLimit",
SessionPeriod = "sessionPeriod",
ResetPeriod = "resetPeriod",
}

interface OneClickTradingSettingsProps {
Expand Down Expand Up @@ -93,10 +88,6 @@ export function compare1CTTransactionParams({
changes.add("networkFeeLimit");
}

if (prevParams?.resetPeriod !== nextParams?.resetPeriod) {
changes.add("resetPeriod");
}

if (prevParams?.sessionPeriod.end !== nextParams?.sessionPeriod.end) {
changes.add("sessionPeriod");
}
Expand Down Expand Up @@ -418,40 +409,6 @@ export const OneClickTradingSettings = ({
}
isDisabled={isDisabled}
/>
<SettingRow
title={t("oneClickTrading.settings.resetPeriodTitle")}
onClick={() =>
setCurrentScreen(SettingsScreens.ResetPeriod)
}
content={
<Button
variant="link"
size="sm"
className={classNames(
"flex items-center gap-2 px-0 !text-base text-wosmongton-200 transition-none hover:no-underline group-hover:text-white-full",
changes.includes("resetPeriod") && "text-bullish-400"
)}
disabled={isDisabled}
>
<p>
{transaction1CTParams
? t(
getResetPeriodTranslationKey(
transaction1CTParams.resetPeriod
)
)
: ""}
</p>
<Icon
id="chevron-right"
width={18}
height={18}
className="text-osmoverse-500 group-hover:text-white-full"
/>
</Button>
}
isDisabled={isDisabled}
/>
</div>

{hasExistingSession &&
Expand Down Expand Up @@ -548,20 +505,6 @@ export const OneClickTradingSettings = ({
/>
</div>
</Screen>

<Screen screenName={SettingsScreens.ResetPeriod}>
<div
className={classNames(
"flex w-full flex-col gap-12",
classes?.root
)}
>
<ResetPeriodScreen
transaction1CTParams={transaction1CTParams!}
setTransaction1CTParams={setTransaction1CTParams}
/>
</div>
</Screen>
</>
)}
</ScreenManager>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ProfileOneClickTradingSettings = ({
enabled: shouldFetchSessionAuthenticator,
cacheTime: 15_000, // 15 seconds
staleTime: 15_000, // 15 seconds
retry: false,
}
);

Expand Down
Loading
Loading