Skip to content
Draft
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
11 changes: 8 additions & 3 deletions examples/next/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ const Header = () => {
<div className="absolute right-0 top-full mt-1 bg-background shadow-lg rounded-md min-w-[160px] py-1 z-10 border border-gray-600">
<button
className="block w-full px-4 py-2 text-left hover:bg-gray-600 transition-colors border-b border-gray-600"
onClick={() => controllerConnector.controller.openProfile()}
onClick={() =>
controllerConnector.controller.open({ target: "profile" })
}
>
Profile
</button>
<button
className="block w-full px-4 py-2 text-left hover:bg-gray-600 transition-colors border-b border-gray-600"
onClick={() => controllerConnector.controller.openSettings()}
onClick={() =>
controllerConnector.controller.open({ target: "settings" })
}
>
Settings
</button>
Expand All @@ -181,7 +185,8 @@ const Header = () => {
<Button
onClick={() => {
controllerConnector.controller.open({
redirectUrl: window.location.href,
target: "standalone",
options: { redirectUrl: window.location.href },
});
}}
disabled={!isControllerReady}
Expand Down
83 changes: 63 additions & 20 deletions examples/next/src/components/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export function Profile() {
<h2>Open Starterpack</h2>
<div className="flex flex-col gap-1">
<div className="flex flex-wrap gap-1">
<Button onClick={() => ctrlConnector.controller.openStarterPack(0)}>
<Button
onClick={() =>
ctrlConnector.controller.open({ target: "starterpack", id: 0 })
}
>
Nums
</Button>
</div>
Expand All @@ -91,65 +95,103 @@ export function Profile() {
<div className="flex flex-col gap-1">
<div className="flex flex-wrap gap-1">
<Button
onClick={() => ctrlConnector.controller.openProfile("inventory")}
onClick={() =>
ctrlConnector.controller.open({
target: "profile",
tab: "inventory",
})
}
>
Inventory
</Button>
<Button
onClick={() => ctrlConnector.controller.openProfile("achievements")}
onClick={() =>
ctrlConnector.controller.open({
target: "profile",
tab: "achievements",
})
}
>
Achievements
</Button>
<Button
onClick={() => ctrlConnector.controller.openProfile("leaderboard")}
onClick={() =>
ctrlConnector.controller.open({
target: "profile",
tab: "leaderboard",
})
}
>
Leaderboard
</Button>
<Button
onClick={() => ctrlConnector.controller.openProfile("activity")}
onClick={() =>
ctrlConnector.controller.open({
target: "profile",
tab: "activity",
})
}
>
Activity
</Button>
<Button
onClick={() => ctrlConnector.controller.openProfileTo("followers")}
onClick={() =>
ctrlConnector.controller.open({
target: "profile",
to: "followers",
})
}
>
Followers
</Button>
<Button
onClick={() => ctrlConnector.controller.openProfileTo("following")}
onClick={() =>
ctrlConnector.controller.open({
target: "profile",
to: "following",
})
}
>
Following
</Button>
<Button
onClick={() => ctrlConnector.controller.openProfileAt("/funding")}
onClick={() =>
ctrlConnector.controller.open({
target: "profile",
at: "/funding",
})
}
>
Funding
</Button>
</div>
<div className="flex flex-wrap gap-1">
<Button
onClick={() =>
ctrlConnector.controller.openProfileTo(
`inventory/token/${STRK_CONTRACT_ADDRESS}?preset=cartridge`,
)
ctrlConnector.controller.open({
target: "profile",
to: `inventory/token/${STRK_CONTRACT_ADDRESS}?preset=cartridge`,
})
}
>
Open to Token STRK
</Button>
<Button
onClick={() =>
ctrlConnector.controller.openProfileTo(
`inventory/token/${ETH_CONTRACT_ADDRESS}?preset=cartridge`,
)
ctrlConnector.controller.open({
target: "profile",
to: `inventory/token/${ETH_CONTRACT_ADDRESS}?preset=cartridge`,
})
}
>
Open to Token ETH
</Button>
<Button
onClick={() =>
ctrlConnector.controller.openProfileTo(
`inventory/token/${STRK_CONTRACT_ADDRESS}/send?preset=cartridge`,
)
ctrlConnector.controller.open({
target: "profile",
to: `inventory/token/${STRK_CONTRACT_ADDRESS}/send?preset=cartridge`,
})
}
>
Open to Token STRK Send
Expand All @@ -158,9 +200,10 @@ export function Profile() {
<div className="flex flex-wrap gap-1">
<Button
onClick={() =>
ctrlConnector.controller.openProfileAt(
"account/bal7hazar/inventory/collection/0x046dA8955829ADF2bDa310099A0063451923f02E648cF25A1203aac6335CF0e4/token/0x000000000000000000000000000000000000000000000000000000000000c527?ps=arcade-main&preset=arcade&address=0x027917d3084dC0dcd3C4ED5189733d14b0c4C13E762829BD3D1D761aa36201AB&purchaseView=true&tokenIds=0x000000000000000000000000000000000000000000000000000000000000c527",
)
ctrlConnector.controller.open({
target: "profile",
at: "account/bal7hazar/inventory/collection/0x046dA8955829ADF2bDa310099A0063451923f02E648cF25A1203aac6335CF0e4/token/0x000000000000000000000000000000000000000000000000000000000000c527?ps=arcade-main&preset=arcade&address=0x027917d3084dC0dcd3C4ED5189733d14b0c4C13E762829BD3D1D761aa36201AB&purchaseView=true&tokenIds=0x000000000000000000000000000000000000000000000000000000000000c527",
})
}
>
Open at Purchase
Expand Down
3 changes: 1 addition & 2 deletions examples/next/src/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export function Settings() {
const cartridgeConnector = connector as unknown as ControllerConnector;

const onOpenSettings = async () => {
if (!account) return;
cartridgeConnector.controller.openSettings();
cartridgeConnector.controller.open({ target: "settings" });
};

if (!account) {
Expand Down
16 changes: 9 additions & 7 deletions examples/next/src/components/Starterpack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ export const Starterpack = () => {
/>
<Button
onClick={() => {
controllerConnector.controller.openStarterPack(
purchaseOnchainSpId,
);
controllerConnector.controller.open({
target: "starterpack",
id: purchaseOnchainSpId,
});
}}
>
Purchase
Expand All @@ -106,12 +107,13 @@ export const Starterpack = () => {
<Button
onClick={() => {
if (claimSpId.trim()) {
controllerConnector.controller.openStarterPack(
claimSpId.trim(),
{
controllerConnector.controller.open({
target: "starterpack",
id: claimSpId.trim(),
options: {
preimage: claimPreimage.trim(),
},
);
});
}
}}
>
Expand Down
17 changes: 17 additions & 0 deletions packages/connector/src/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ControllerProvider, {
AuthOptions,
ControllerOptions,
OpenPageTarget,
} from "@cartridge/controller";
import { Connector, InjectedConnector } from "@starknet-react/core";

Expand Down Expand Up @@ -47,6 +48,22 @@ export default class ControllerConnector extends InjectedConnector {
return super.connect({ chainIdHint: args?.chainIdHint });
}

async open(args: OpenPageTarget) {
return this.controller.open(args);
}

async openProfile() {
return this.controller.openProfile();
}

async openSettings() {
return this.controller.openSettings();
}

async openStarterPack(id: string | number) {
return this.controller.openStarterPack(id);
}

static fromConnectors(connectors: Connector[]): ControllerConnector {
const connector = connectors.find((c) => c.id === "controller");
if (!connector) {
Expand Down
Loading