This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed deprecated package. Updated magic-sdk package to latest version
- Loading branch information
1 parent
54b64e5
commit 6abf6a3
Showing
6 changed files
with
95 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 43 additions & 59 deletions
102
scaffolds/nextjs-flow-dedicated-wallet/template/src/components/magic/MagicProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 47 additions & 63 deletions
110
scaffolds/nextjs-solana-dedicated-wallet/template/src/components/magic/MagicProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |