Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Removed deprecated package. Updated magic-sdk package to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaKulkarni committed Jan 15, 2024
1 parent 54b64e5 commit 6abf6a3
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 131 deletions.
3 changes: 1 addition & 2 deletions scaffolds/nextjs-dedicated-wallet/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
"lint": "next lint --fix"
},
"dependencies": {
"@magic-ext/auth": "^4.0.0",
"@magic-ext/oauth": "^15.0.0",
"@types/node": "20.3.3",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"autoprefixer": "10.4.14",
"classnames": "^2.3.2",
"magic-sdk": "^21.0.0",
"magic-sdk": "^21.5.0",
"next": "13.4.7",
"postcss": "8.4.24",
"react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { getChainId, getNetworkUrl } from '@/utils/network';
import { OAuthExtension } from '@magic-ext/oauth';
import { AuthExtension } from '@magic-ext/auth';
import { Magic as MagicBase } from 'magic-sdk';
import { ReactNode, createContext, useContext, useEffect, useMemo, useState } from 'react';
const { Web3 } = require('web3');

export type Magic = MagicBase<AuthExtension & OAuthExtension[]>;
export type Magic = MagicBase<OAuthExtension[]>;

type MagicContextType = {
magic: Magic | null;
Expand All @@ -30,7 +29,7 @@ const MagicProvider = ({ children }: { children: ReactNode }) => {
rpcUrl: getNetworkUrl(),
chainId: getChainId(),
},
extensions: [new AuthExtension(), new OAuthExtension()],
extensions: [new OAuthExtension()],
});

setMagic(magic);
Expand Down
3 changes: 1 addition & 2 deletions scaffolds/nextjs-flow-dedicated-wallet/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint": "next lint --fix"
},
"dependencies": {
"@magic-ext/auth": "^4.0.0",
"@magic-ext/flow": "^16.0.0",
"@magic-ext/oauth": "^15.0.0",
"@onflow/fcl": "^1.6.0",
Expand All @@ -18,7 +17,7 @@
"@types/react-dom": "18.2.6",
"autoprefixer": "10.4.14",
"classnames": "^2.3.2",
"magic-sdk": "^21.0.0",
"magic-sdk": "^21.5.0",
"next": "13.4.7",
"postcss": "8.4.24",
"react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,48 @@
import {getNetwork, getNetworkUrl} from '@/utils/network'
import {OAuthExtension} from '@magic-ext/oauth'
import {AuthExtension} from '@magic-ext/auth'
import {Magic as MagicBase} from 'magic-sdk'
import {
ReactNode,
createContext,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import {FlowExtension} from '@magic-ext/flow'
import * as fcl from '@onflow/fcl'
import { getNetwork, getNetworkUrl } from '@/utils/network';
import { OAuthExtension } from '@magic-ext/oauth';
import { Magic as MagicBase } from 'magic-sdk';
import { ReactNode, createContext, useContext, useEffect, useMemo, useState } from 'react';
import { FlowExtension } from '@magic-ext/flow';
import * as fcl from '@onflow/fcl';

export type Magic = MagicBase<
AuthExtension & OAuthExtension[] & FlowExtension[]
>
export type Magic = MagicBase<OAuthExtension[] & FlowExtension[]>;

type MagicContextType = {
magic: Magic | null
}
magic: Magic | null;
};

const MagicContext = createContext<MagicContextType>({
magic: null,
})

export const useMagic = () => useContext(MagicContext)

const MagicProvider = ({children}: {children: ReactNode}) => {
const [magic, setMagic] = useState<Magic | null>(null)

useEffect(() => {
if (process.env.NEXT_PUBLIC_MAGIC_API_KEY) {
const magic = new MagicBase(
process.env.NEXT_PUBLIC_MAGIC_API_KEY as string,
{
extensions: [
new AuthExtension(),
new OAuthExtension(),
new FlowExtension({
rpcUrl: getNetworkUrl(),
network: getNetwork() as string,
}),
],
}
)
setMagic(magic)
fcl.config().put('accessNode.api', getNetworkUrl())
}
}, [])

const value = useMemo(() => {
return {
magic,
}
}, [magic])

return (
<MagicContext.Provider value={value}>{children}</MagicContext.Provider>
)
}

export default MagicProvider
magic: null,
});

export const useMagic = () => useContext(MagicContext);

const MagicProvider = ({ children }: { children: ReactNode }) => {
const [magic, setMagic] = useState<Magic | null>(null);

useEffect(() => {
if (process.env.NEXT_PUBLIC_MAGIC_API_KEY) {
const magic = new MagicBase(process.env.NEXT_PUBLIC_MAGIC_API_KEY as string, {
extensions: [
new OAuthExtension(),
new FlowExtension({
rpcUrl: getNetworkUrl(),
network: getNetwork() as string,
}),
],
});
setMagic(magic);
fcl.config().put('accessNode.api', getNetworkUrl());
}
}, []);

const value = useMemo(() => {
return {
magic,
};
}, [magic]);

return <MagicContext.Provider value={value}>{children}</MagicContext.Provider>;
};

export default MagicProvider;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint": "next lint --fix"
},
"dependencies": {
"@magic-ext/auth": "^4.0.0",
"@magic-ext/oauth": "^15.0.0",
"@magic-ext/solana": "^17.0.0",
"@solana/web3.js": "^1.87.1",
Expand All @@ -18,7 +17,7 @@
"@types/react-dom": "18.2.6",
"autoprefixer": "10.4.14",
"classnames": "^2.3.2",
"magic-sdk": "^21.0.0",
"magic-sdk": "^21.5.0",
"next": "13.4.7",
"postcss": "8.4.24",
"react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,52 @@
import {getNetworkUrl} from '@/utils/network'
import {OAuthExtension} from '@magic-ext/oauth'
import {AuthExtension} from '@magic-ext/auth'
import {Magic as MagicBase} from 'magic-sdk'
import {
ReactNode,
createContext,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import {SolanaExtension} from '@magic-ext/solana'
import {Connection} from '@solana/web3.js'
import { getNetworkUrl } from '@/utils/network';
import { OAuthExtension } from '@magic-ext/oauth';
import { Magic as MagicBase } from 'magic-sdk';
import { ReactNode, createContext, useContext, useEffect, useMemo, useState } from 'react';
import { SolanaExtension } from '@magic-ext/solana';
import { Connection } from '@solana/web3.js';

export type Magic = MagicBase<
AuthExtension & OAuthExtension[] & SolanaExtension[]
>
export type Magic = MagicBase<OAuthExtension[] & SolanaExtension[]>;

type MagicContextType = {
magic: Magic | null
connection: Connection | null
}
magic: Magic | null;
connection: Connection | null;
};

const MagicContext = createContext<MagicContextType>({
magic: null,
connection: null,
})

export const useMagic = () => useContext(MagicContext)

const MagicProvider = ({children}: {children: ReactNode}) => {
const [magic, setMagic] = useState<Magic | null>(null)
const [connection, setConnection] = useState<Connection | null>(null)

useEffect(() => {
if (process.env.NEXT_PUBLIC_MAGIC_API_KEY) {
const magic = new MagicBase(
process.env.NEXT_PUBLIC_MAGIC_API_KEY as string,
{
extensions: [
new AuthExtension(),
new OAuthExtension(),
new SolanaExtension({
rpcUrl: getNetworkUrl(),
}),
],
}
)
const connection = new Connection(getNetworkUrl())
setMagic(magic)
setConnection(connection)
}
}, [])

const value = useMemo(() => {
return {
magic,
connection,
}
}, [magic, connection])

return (
<MagicContext.Provider value={value}>{children}</MagicContext.Provider>
)
}

export default MagicProvider
magic: null,
connection: null,
});

export const useMagic = () => useContext(MagicContext);

const MagicProvider = ({ children }: { children: ReactNode }) => {
const [magic, setMagic] = useState<Magic | null>(null);
const [connection, setConnection] = useState<Connection | null>(null);

useEffect(() => {
if (process.env.NEXT_PUBLIC_MAGIC_API_KEY) {
const magic = new MagicBase(process.env.NEXT_PUBLIC_MAGIC_API_KEY as string, {
extensions: [
new OAuthExtension(),
new SolanaExtension({
rpcUrl: getNetworkUrl(),
}),
],
});
const connection = new Connection(getNetworkUrl());
setMagic(magic);
setConnection(connection);
}
}, []);

const value = useMemo(() => {
return {
magic,
connection,
};
}, [magic, connection]);

return <MagicContext.Provider value={value}>{children}</MagicContext.Provider>;
};

export default MagicProvider;

0 comments on commit 6abf6a3

Please sign in to comment.