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

Update SDK version #4

Merged
merged 2 commits into from
Aug 9, 2023
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 Metamask/notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Connect your wallet and keep track of your transactions

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) utilizing [`@tatumcom/js`](https://docs.tatum.com/sdk/javascript-typescript-sdk) for a simple [MetaMask](https://metamask.io/) integration. It combines several examples available in [Tatum Docs](https://docs.tatum.com/) into a single straightforward easily customizable mini application capable of connecting to the wallet, displaying recent transactions of native currency and monitoring further outgoing native currency transfers on [Sepolia Testnet](https://sepolia.etherscan.io/).
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) utilizing [`@tatumio/tatum`](https://docs.tatum.com/sdk/javascript-typescript-sdk) for a simple [MetaMask](https://metamask.io/) integration. It combines several examples available in [Tatum Docs](https://docs.tatum.com/) into a single straightforward easily customizable mini application capable of connecting to the wallet, displaying recent transactions of native currency and monitoring further outgoing native currency transfers on [Sepolia Testnet](https://sepolia.etherscan.io/).

![Demo](./public/demo.png)

Expand Down
39 changes: 22 additions & 17 deletions Metamask/notifications/components/organisms/Metamask.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Required since nextjs13 to define a client component */
"use client";

import { TatumSDK, Network, Ethereum } from "@tatumcom/js";
import { TatumSDK, Network, Ethereum } from "@tatumio/tatum";
import * as React from "react";
import Image from "next/image";
import { toast } from "react-hot-toast";
Expand Down Expand Up @@ -36,11 +36,11 @@ const Metamask = (): JSX.Element => {
const connectMetamask = async () => {
setLoading(LoadingStatus.TX);

try {
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
});
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
});

try {
/* https://docs.tatum.com/docs/wallet-provider/metamask/connect-a-wallet */
const acc = await tatum.walletProvider.metaMask.connect();

Expand All @@ -63,17 +63,20 @@ const Metamask = (): JSX.Element => {
console.error(error);
toast.error("Connection failed");
}

// destroy Tatum SDK - needed for stopping background jobs
tatum.destroy();
};

const handleMonitoring = async (address: string) => {
setLoading(LoadingStatus.SUB);

const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
});

if (subscription) {
try {
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
});

/* https://docs.tatum.com/docs/notifications/notification-workflow/stop-monitoring-of-the-address */
await tatum.notification.unsubscribe(subscription);

Expand All @@ -86,10 +89,6 @@ const Metamask = (): JSX.Element => {
}
} else {
try {
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
});

/* https://docs.tatum.com/docs/notifications/notification-workflow/get-all-existing-monitoring-subscriptions */
const existing = await tatum.notification.getAll({ address });

Expand Down Expand Up @@ -119,6 +118,9 @@ const Metamask = (): JSX.Element => {
console.error(error);
toast.error("Subscription creation failed");
}

// destroy Tatum SDK - needed for stopping background jobs
tatum.destroy();
}

setLoading(LoadingStatus.NONE);
Expand All @@ -127,11 +129,11 @@ const Metamask = (): JSX.Element => {
const executeTestTransaction = async () => {
setLoading(LoadingStatus.TX);

try {
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
});
const tatum = await TatumSDK.init<Ethereum>({
network: Network.ETHEREUM_SEPOLIA,
});

try {
/* https://docs.tatum.com/docs/wallet-provider/metamask/transfer-native-assets */
const tx = await tatum.walletProvider.metaMask.transferNative(
receiver,
Expand All @@ -145,6 +147,9 @@ const Metamask = (): JSX.Element => {
toast.error("Transfer failed");
}

// destroy Tatum SDK - needed for stopping background jobs
tatum.destroy();

setLoading(LoadingStatus.NONE);
};

Expand Down
2 changes: 1 addition & 1 deletion Metamask/notifications/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddressBalance, AddressTransaction } from "@tatumcom/js";
import { AddressBalance, AddressTransaction } from "@tatumio/tatum";
import clsx, { ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import BN from "bignumber.js";
Expand Down
2 changes: 1 addition & 1 deletion Metamask/notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@heroicons/react": "^2.0.18",
"@tatumcom/js": "^1.4.23",
"@tatumio/tatum": "^3.0.6",
"@types/node": "20.2.5",
"@types/react": "18.2.9",
"@types/react-dom": "18.2.4",
Expand Down
Loading