Skip to content

Commit

Permalink
Merge pull request #6 from magiclabs/josh-sc-87804-product-name-updates
Browse files Browse the repository at this point in the history
Josh sc 87804 product name updates
  • Loading branch information
joshuascan committed Sep 27, 2023
2 parents 795ecb3 + e381c54 commit 76b8d84
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-mugs-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@magiclabs/wagmi-connector": patch
---

Updates package to use new Magic product names (Dedicated and Universal Wallet)
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,31 @@ yarn add @magiclabs/wagmi-connector

# 🔎 Package TL;DR

The package contains two main connector classes: `MagicAuthConnector` & `MagicConnectConnector`
The package contains two main connector classes: `DedicatedWalletConnector` & `UniversalWalletConnector`

`MagicAuthConnector` is a connector integrated to the [Magic Auth](https://magic.link/docs/auth/overview)
`DedicatedWalletConnector` is a connector integrated to the [Dedicated Wallet](https://magic.link/docs/dedicated/overview)
product. It is useful if you need to assign an address to your user.

`MagicConnectConnector` is a connector integrated to the [Magic Connect](https://magic.link/docs/connect/overview)
`UniversalWalletConnector` is a connector integrated to the [Universal Wallet](https://magic.link/docs/universal/overview)
product. It can be used to assign a read-write wallet to your user.

DEPRECATED: `MagicAuthConnector` and `MagicConnectConnector` have been replaced by `DedicatedWalletConnector` and `UniversalWalletConnector` in order to line up with Magic's [product names changes](https://magic.link/docs/universal/resources/faqs#why-were-magic-product-names-changed-from-magic-connect-and-magic-auth). However, they are still usable and will function as they did before.

# ⭐ Usage

```javascript
import { MagicAuthConnector, MagicConnectConnector } from '@magiclabs/wagmi-connector';
import { DedicatedWalletConnector, UniversalWalletConnector } from '@magiclabs/wagmi-connector';

// Magic Auth integration
const connector = new MagicAuthConnector({
// Dedicated Wallet integration
const connector = new DedicatedWalletConnector({
options: {
apiKey: YOUR_MAGIC_LINK_API_KEY, //required
//...Other options
},
});

// Magic Connect integration
const connector = new MagicConnectConnector({
// Universal Wallet integration
const connector = new UniversalWalletConnector({
options: {
apiKey: YOUR_MAGIC_LINK_API_KEY, //required
//...Other options
Expand All @@ -79,7 +80,7 @@ const connector = new MagicConnectConnector({

The following can be passed to connector options object:

| Key | Value | `MagicAuthConnector` support | `MagicConnectConnector` support | Description |
| Key | Value | `DedicatedWalletConnector` support | `UniversalWalletConnector` support | Description |
|-----------------------|----------------------------|------------------------------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| accentColor | css color (hex/rgb/etc...) | ✔️ | ✔️ | 🎨 (Optional) Makes modal to use the custom accentColor instead of default purple |
| isDarkMode | true / false | ✔️ | ✔️ | 🎨 (Optional) Makes modal dark mode if true. Default value is false |
Expand All @@ -95,9 +96,9 @@ The following can be passed to connector options object:

The following can be passed to options.OAuthOptions object to configure OAuth login:

| Key | Vvalue | Description |
| Key | Value | Description |
|-------------|------------------|-----------------------------------------------------------------------------------------------------------|
| providers | array of strings | 🌟 (Required) List of providers to enable. check out all possible providers in OauthOptions section above |
| providers | array of strings | 🌟 (Required) List of providers to enable. check out all possible providers in OAuthOptions section above |
| callbackUrl | string | 🌟 (Optional) Callback URL to redirect to after authentication. Default value is current URL. |

### Providers
Expand All @@ -122,7 +123,7 @@ You can provide a callback URL to redirect the user to after authentication. the

# 🍀 Supported Logins

| Key | `MagicAuthConnector` support | `MagicConnectConnector` support |
| Key | `DedicatedWalletConnector` support | `UniversalWalletConnector` support |
|----------------------------|------------------------------|---------------------------------|
| Email | ✔️ | ✔️ |
| SMS | ✔️ ||
Expand All @@ -137,7 +138,7 @@ You can provide a callback URL to redirect the user to after authentication. the
You configure OAuth with magic by adding the following options to the connector:

```javascript
const connector = new MagicAuthConnector({
const connector = new DedicatedWalletConnector({
options: {
apiKey: YOUR_MAGIC_LINK_API_KEY, //required
oauthOptions : {
Expand All @@ -154,7 +155,7 @@ const connector = new MagicAuthConnector({
You can enable SMS authentication by adding the following options to the connector:

```javascript
const connector = new MagicAuthConnector({
const connector = new DedicatedWalletConnector({
options: {
apiKey: YOUR_MAGIC_LINK_API_KEY, //required
enableSMSLogin: true, //optional (default: false)
Expand All @@ -170,7 +171,7 @@ You have to enable SMS authentication in your Magic Link account first to make i
By default Email Authentication is set to true as default. if you wish to remove sending magic links via emails, pass ```enableEmailLogin: false``` in options object as follows :

```javascript
const connector = new MagicAuthConnector({
const connector = new DedicatedWalletConnector({
options: {
apiKey: YOUR_MAGIC_LINK_API_KEY, //required
enableEmailLogin: false, //optional (default: true)
Expand All @@ -185,9 +186,9 @@ const connector = new MagicAuthConnector({
You can customize the modal's theme, default accent color, logo and header text.

```javascript
import { MagicAuthConnector } from '@magiclabs/wagmi-connector';
import { DedicatedWalletConnector } from '@magiclabs/wagmi-connector';

const connector = new MagicAuthConnector({
const connector = new DedicatedWalletConnector({
options: {
apiKey: YOUR_MAGIC_LINK_API_KEY,
accentColor: '#ff0000',
Expand All @@ -210,15 +211,15 @@ To use the connector with Rainbow kit, create a new file `RainbowMagicConnector.
```javascript
// RainbowMagicConnector.ts

import { MagicConnectConnector } from '@magiclabs/wagmi-connector';
import { UniversalWalletConnector } from '@magiclabs/wagmi-connector';

export const rainbowMagicConnector = ({ chains }: any) => ({
id: 'magic',
name: 'Magic',
iconUrl: 'https://svgshare.com/i/iJK.svg',
iconBackground: '#fff',
createConnector: () => {
const connector = new MagicConnectConnector({
const connector = new UniversalWalletConnector({
chains: chains,
options: {
apiKey: 'YOUR_MAGIC_CONNECT_API_KEY',
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './lib/connectors/magicAuthConnector'
export * from './lib/connectors/magicConnectConnector'
export * from './lib/connectors/dedicatedWalletConnector'
export * from './lib/connectors/universalWalletConnector'
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface UserDetails {
oauthProvider: OAuthProvider
}

interface MagicAuthOptions extends MagicOptions {
interface DedicatedWalletOptions extends MagicOptions {
enableEmailLogin?: boolean
enableSMSLogin?: boolean
oauthOptions?: {
Expand All @@ -31,25 +31,25 @@ interface MagicAuthOptions extends MagicOptions {
}

/**
* Magic Auth Connector class used to connect to wallet using Magic Auth.
* Dedicated Wallet Connector class used to connect to wallet using Dedicated Wallet.
* It uses modal UI defined in our package which also takes in various styling options
* for custom experience.
*
* @example
* ```typescript
* import { MagicConnectConnector } from '@magiclabs/wagmi-connector';
* const connector = new MagicConnectConnector({
* import { DedicatedWalletConnector } from '@magiclabs/wagmi-connector';
* const connector = new DedicatedWalletConnector({
* options: {
* apiKey: YOUR_MAGIC_LINK_API_KEY, //required
* //...Other options
* },
* });
* ```
* @see https://github.com/magiclabs/wagmi-magic-connector#-usage
* @see https://magic.link/docs/connect/overview
* @see https://magic.link/docs/dedicated/overview
*/

export class MagicAuthConnector extends MagicConnector {
export class DedicatedWalletConnector extends MagicConnector {
magicSDK?: InstanceWithExtensions<SDKBase, OAuthExtension[]>
magicSdkConfiguration?: MagicSDKAdditionalConfiguration<
string,
Expand All @@ -61,7 +61,7 @@ export class MagicAuthConnector extends MagicConnector {
oauthCallbackUrl?: string
magicOptions: MagicOptions

constructor(config: { chains?: Chain[]; options: MagicAuthOptions }) {
constructor(config: { chains?: Chain[]; options: DedicatedWalletOptions }) {
super(config)
this.magicSdkConfiguration = config.options.magicSdkConfiguration
this.oauthProviders = config.options.oauthOptions?.providers || []
Expand All @@ -86,7 +86,7 @@ export class MagicAuthConnector extends MagicConnector {
}

/**
* Connect method attempts to connects to wallet using Magic Connect modal
* Connect method attempts to connects to wallet using Dedicated Wallet modal
* this will open a modal for the user to select their wallet
*/
async connect() {
Expand Down Expand Up @@ -131,20 +131,20 @@ export class MagicAuthConnector extends MagicConnector {

const magic = this.getMagicSDK()

// LOGIN WITH MAGIC LINK WITH OAUTH PROVIDER
// LOGIN WITH MAGIC USING OAUTH PROVIDER
if (modalOutput.oauthProvider)
await magic.oauth.loginWithRedirect({
provider: modalOutput.oauthProvider,
redirectURI: this.oauthCallbackUrl || window.location.href,
})

// LOGIN WITH MAGIC LINK WITH EMAIL
// LOGIN WITH MAGIC USING EMAIL
if (modalOutput.email)
await magic.auth.loginWithMagicLink({
email: modalOutput.email,
})

// LOGIN WITH MAGIC LINK WITH PHONE NUMBER
// LOGIN WITH MAGIC USING PHONE NUMBER
if (modalOutput.phoneNumber)
await magic.auth.loginWithSMS({
phoneNumber: modalOutput.phoneNumber,
Expand Down Expand Up @@ -206,3 +206,5 @@ export class MagicAuthConnector extends MagicConnector {
return output
}
}

export class MagicAuthConnector extends DedicatedWalletConnector {}
4 changes: 2 additions & 2 deletions src/lib/connectors/magicConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export interface MagicOptions {
}

/**
* Magic Connector class is a base class for Magic Auth and Magic Connect Connectors
* Magic Connector class is a base class for Dedicated Wallet and Universal Wallet Connectors
* It implements the common functionality of both the connectors
*
* Magic Auth Connector and Magic Connect Connector are the two connectors provided by this library
* Dedicated Wallet Connector and Universal Wallet Connector are the two connectors provided by this library
* And both of them extend this class.
*/
export abstract class MagicConnector extends Connector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,38 @@ import { Magic } from 'magic-sdk'
import { normalizeChainId } from '../utils'
import { MagicConnector } from './magicConnector'

export interface MagicConnectorOptions {
export interface UniversalWalletOptions {
apiKey: string
magicSdkConfiguration?: MagicSDKAdditionalConfiguration
networks?: EthNetworkConfiguration[]
}

/**
* Magic Connect Connector class used to connect to wallet using Magic Connect modal
* Universal Wallet Connector class used to connect to wallet using Universal Wallet modal
* This uses the modal UI from Magic itself and styles for it can be configured using
* magic dashboard.
*
* @example
* ```typescript
* import { MagicConnectConnector } from '@magiclabs/wagmi-connector';
* const connector = new MagicConnectConnector({
* import { UniversalWalletConnector } from '@magiclabs/wagmi-connector';
* const connector = new UniversalWalletConnector({
* options: {
* apiKey: YOUR_MAGIC_LINK_API_KEY, //required
* //...Other options
* },
* });
* ```
* @see https://github.com/magiclabs/wagmi-magic-connector#-usage
* @see https://magic.link/docs/connect/overview
* @see https://magic.link/docs/universal/overview
*/

export class MagicConnectConnector extends MagicConnector {
export class UniversalWalletConnector extends MagicConnector {
magic: InstanceWithExtensions<
SDKBase,
MagicSDKExtensionsOption<string>
> | null

constructor(config: { chains?: Chain[]; options: MagicConnectorOptions }) {
constructor(config: { chains?: Chain[]; options: UniversalWalletOptions }) {
super(config)
this.magic = this.getMagicSDK()
}
Expand All @@ -65,7 +65,7 @@ export class MagicConnectConnector extends MagicConnector {
}

/**
* Connect method attempts to connects to wallet using Magic Connect modal
* Connect method attempts to connects to wallet using Universal Wallet modal
* this will open a modal for the user to select their wallet
*/
async connect() {
Expand Down Expand Up @@ -100,7 +100,7 @@ export class MagicConnectConnector extends MagicConnector {
}

/**
* checks if user is authorized with Magic Connect
* checks if user is authorized with Universal Wallet
*/
async isAuthorized() {
try {
Expand Down Expand Up @@ -158,3 +158,5 @@ export class MagicConnectConnector extends MagicConnector {
return chain
}
}

export class MagicConnectConnector extends UniversalWalletConnector {}

0 comments on commit 76b8d84

Please sign in to comment.