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

wip: migrating to adena sdk #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Binary file modified frontend/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@gnolang/gno-js-client": "^1.3.0",
"@gnolang/tm2-js-client": "^1.2.1",
"@tanstack/react-query": "^5.51.11",
"adena-sdk-ts": "/Users/agherasie/Dev/gno/adena-sdk-ts/adena-sdk-ts-0.0.1.tgz",
"axios": "^1.7.2",
"env-var": "^7.5.0",
"framer-motion": "^11.2.11",
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/hooks/useBuyNFT.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { constants } from "../constants";
import { AdenaService } from "../services/adena/adena";
import { EMessageType } from "../services/adena/adena.types";
import { useAccountStore } from "../store";
import { BuyNFTDto } from "../types/nfts";
import { EMessageType, signAndSendTransaction } from "adena-sdk-ts";

const useBuyNFT = () => {
const { address } = useAccountStore();
const queryClient = useQueryClient();

return useMutation({
mutationFn: ({ price, ...payload }: BuyNFTDto & { price: number }) =>
AdenaService.sendTransaction(
signAndSendTransaction(
[
{
type: EMessageType.MSG_CALL,
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/hooks/useCreateCollection.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { constants } from "../constants";
import { AdenaService } from "../services/adena/adena";
import { EMessageType } from "../services/adena/adena.types";
import { useAccountStore } from "../store";
import { CreateCollectionDto } from "../types/collections";
import { EMessageType, signAndSendTransaction } from "adena-sdk-ts";

const useCreateCollection = () => {
const { address } = useAccountStore();
const queryClient = useQueryClient();

return useMutation({
mutationFn: (payload: CreateCollectionDto) =>
AdenaService.sendTransaction(
signAndSendTransaction(
[
{
type: EMessageType.MSG_CALL,
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/hooks/useMint.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { constants } from "../constants";
import { AdenaService } from "../services/adena/adena";
import { EMessageType } from "../services/adena/adena.types";
import { useAccountStore } from "../store";
import { MintDto } from "../types/nfts";
import { EMessageType, signAndSendTransaction } from "adena-sdk-ts";

const useMint = () => {
const { address } = useAccountStore();
const queryClient = useQueryClient();

return useMutation({
mutationFn: (payload: MintDto) =>
AdenaService.sendTransaction(
signAndSendTransaction(
[
{
type: EMessageType.MSG_CALL,
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/hooks/useSetForSale.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { constants } from "../constants";
import { AdenaService } from "../services/adena/adena";
import { EMessageType } from "../services/adena/adena.types";
import { useAccountStore } from "../store";
import { SetNFTForSaleDto } from "../types/nfts";
import { EMessageType, signAndSendTransaction } from "adena-sdk-ts";

const useSetForSale = () => {
const { address } = useAccountStore();
const queryClient = useQueryClient();

return useMutation({
mutationFn: (payload: SetNFTForSaleDto) =>
AdenaService.sendTransaction(
signAndSendTransaction(
[
{
type: EMessageType.MSG_CALL,
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/hooks/useStarCollection.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { constants } from "../constants";
import { AdenaService } from "../services/adena/adena";
import { EMessageType } from "../services/adena/adena.types";
import { useAccountStore } from "../store";
import { StarCollectionDto } from "../types/collections";
import { EMessageType, signAndSendTransaction } from "adena-sdk-ts";

const useStarCollection = () => {
const { address } = useAccountStore();
const queryClient = useQueryClient();

return useMutation({
mutationFn: (payload: StarCollectionDto) =>
AdenaService.sendTransaction(
signAndSendTransaction(
[
{
type: EMessageType.MSG_CALL,
Expand Down
86 changes: 42 additions & 44 deletions frontend/src/molecules/ConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
import { HStack, StackDivider, Button, useToast, Text } from "@chakra-ui/react";
import { FC, useState } from "react";
import { AdenaService } from "../services/adena/adena";
import { IAccountInfo } from "../services/adena/adena.types";
import { constants } from "../constants";
import { useAccountStore } from "../store";
import { displayUgnot } from "../utils";
import {
establishConnection,
getAccountInfo,
switchNetwork,
} from "adena-sdk-ts";

const WalletButton: FC = () => {
const toast = useToast();
const { setAddress, setAccountInfo, accountInfo, balance, setBalance } =
useAccountStore();
const [isLoading, setIsLoading] = useState<boolean>(false);

const handleWalletConnect = async () => {
setIsLoading(true);

try {
// Attempt to establish a connection
await AdenaService.establishConnection("openocean");

// Get the account info
const info: IAccountInfo = await AdenaService.getAccountInfo();
const { setAddress, balance, address, setBalance } = useAccountStore();

// Make sure the network is valid
await AdenaService.switchNetwork(constants.chainID);

// Update the account context
setAddress(info.address);
setAccountInfo(info);
setBalance(+info.coins.split("u")[0]);

toast({
colorScheme: "purple",
title: "Connected to Adena",
description: `Connected to ${info.address}`,
status: "success",
duration: 3000,
isClosable: true,
});
} catch (e) {
console.error(e);
const [isLoading, setIsLoading] = useState<boolean>(false);

toast({
title: "Failed to connect to Adena",
description: "Please make sure you have the Adena wallet installed",
status: "error",
duration: 5000,
isClosable: true,
});
}
const handleWalletConnect = () => {
setIsLoading(true);

setIsLoading(false);
establishConnection("openocean")
.then(() =>
switchNetwork(constants.chainID).then(() =>
getAccountInfo().then((info) => {
setAddress(info.address);
setBalance(+info.coins.split("u")[0]);
toast({
colorScheme: "purple",
title: "Connected to Adena",
description: `Connected to ${info.address}`,
status: "success",
duration: 3000,
isClosable: true,
});
})
)
)
.catch((e) => {
console.error(e);
toast({
title: "Failed to connect to Adena",
description: "Please make sure you have the Adena wallet installed",
status: "error",
duration: 5000,
isClosable: true,
});
})
.finally(() => setIsLoading(false));
};

return (
Expand All @@ -63,13 +59,15 @@ const WalletButton: FC = () => {
transition="1s"
divider={<StackDivider />}
>
{!!accountInfo && <Text>{displayUgnot(balance)}</Text>}
{address !== null && <Text>{displayUgnot(balance)}</Text>}
<Button
_hover={{ color: "purple.100" }}
color="purple.200"
isLoading={isLoading}
isDisabled={!!accountInfo}
>{`{ wallet }`}</Button>
isDisabled={address !== null}
>
<span>{`{ wallet }`}</span>
</Button>
</HStack>
);
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const StatsPage: FC = () => {
starred: !!stat.stars.find((s) => s === address),
id: stat.id,
}))
.sort((a, b) => a.sales - b.sales) ?? [],
.sort((a, b) => b.sales - a.sales) ?? [],
[address, data, tabIndex]
);

Expand Down
110 changes: 0 additions & 110 deletions frontend/src/services/adena/adena.ts

This file was deleted.

Loading