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

🐛 Add version compatibility check for token transfer #1157

Merged
merged 2 commits into from
Dec 16, 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
1 change: 1 addition & 0 deletions packages/controller/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default class ControllerProvider extends BaseProvider {
},
rpcUrl: this.rpc.toString(),
username,
version: this.version,
});
}

Expand Down
12 changes: 9 additions & 3 deletions packages/controller/src/iframe/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IFrame, IFrameOptions } from "./base";
export type ProfileIFrameOptions = IFrameOptions<Profile> &
ProfileOptions & {
rpcUrl: string;
version?: string;
username: string;
slot?: string;
namespace?: string;
Expand All @@ -14,14 +15,15 @@ export class ProfileIFrame extends IFrame<Profile> {
constructor({
profileUrl,
rpcUrl,
namespace,
slot,
version,
username,
slot,
namespace,
tokens,
...iframeOptions
}: ProfileIFrameOptions) {
const _profileUrl = (profileUrl || PROFILE_URL).replace(/\/$/, "");
const _url = new URL(
let _url = new URL(
slot
? namespace
? `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(
Expand All @@ -33,6 +35,10 @@ export class ProfileIFrame extends IFrame<Profile> {
: `${_profileUrl}/account/${username}`,
);

if (version) {
_url.searchParams.set("v", encodeURIComponent(version));
}

_url.searchParams.set("rpcUrl", encodeURIComponent(rpcUrl));

if (tokens?.erc20) {
Expand Down
1 change: 1 addition & 0 deletions packages/controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type DeployReply = {
export type IFrames = {
keychain: KeychainIFrame;
profile?: ProfileIFrame;
version?: number;
};

export interface LookupRequest {
Expand Down
1 change: 1 addition & 0 deletions packages/profile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@cartridge/ui-next": "workspace:*",
"@cartridge/utils": "workspace:*",
"@hookform/resolvers": "^3.9.1",
"compare-versions": "^6.1.1",
"posthog-js": "^1.181.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/profile/src/components/context/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ConnectionContextType = {
erc20: string[];
project?: string;
namespace?: string;
version?: string;
isVisible: boolean;
setIsVisible: (isVisible: boolean) => void;
};
Expand Down Expand Up @@ -66,6 +67,11 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
});
}

const versionParam = searchParams.get("v");
if (versionParam) {
state.version = decodeURIComponent(versionParam);
}

const psParam = searchParams.get("ps");
if (psParam && !state.project) {
state.project = decodeURIComponent(psParam);
Expand Down
11 changes: 9 additions & 2 deletions packages/profile/src/components/inventory/token/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { formatEther } from "viem";
import { useAccount } from "@/hooks/account";
import { useToken } from "@/hooks/token";
import { TokenPair } from "@cartridge/utils/api/cartridge";
import { useMemo } from "react";
import { compare } from "compare-versions";

export function Token() {
const { address } = useParams<{ address: string }>();
Expand Down Expand Up @@ -93,7 +95,7 @@ function Credits() {

function ERC20() {
const { address } = useParams<{ address: string }>();

const { version } = useConnection();
const { chainId } = useConnection();
const t = useToken({ tokenAddress: address! });
const { countervalue } = useCountervalue(
Expand All @@ -104,6 +106,11 @@ function ERC20() {
{ enabled: t && ["ETH", "STRK"].includes(t.meta.symbol) },
);

const compatibility = useMemo(() => {
if (!version) return false;
return compare(version, "0.4.0", ">=");
}, [version]);

if (!t) {
return;
}
Expand Down Expand Up @@ -167,7 +174,7 @@ function ERC20() {
</Card>
</LayoutContent>

{isIframe() && (
{isIframe() && compatibility && (
<LayoutFooter>
<Link to="send">
<Button className="w-full">Send</Button>
Expand Down
14 changes: 11 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading