-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add support for XDEFI Wallet * fix: review comments * chore: update svg and add example * chore: minify svg * chore: amend changeset --------- Co-authored-by: Amin Limbada <aminlimbada94@gmail.com> Co-authored-by: Amin Limbada <amin@xdefi.io>
- Loading branch information
1 parent
e30f264
commit 0127559
Showing
5 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
'@rainbow-me/rainbowkit': patch | ||
--- | ||
|
||
XDEFI Wallet Support | ||
|
||
**Example usage** | ||
|
||
```tsx | ||
import { | ||
getDefaultWallets, | ||
connectorsForWallets, | ||
} from '@rainbow-me/rainbowkit'; | ||
import { xdefiWallet } from '@rainbow-me/rainbowkit/wallets'; | ||
const { wallets } = getDefaultWallets({ appName, projectId, chains }); | ||
const connectors = connectorsForWallets([ | ||
...wallets, | ||
{ | ||
groupName: 'Other', | ||
wallets: [xdefiWallet({ chains })], | ||
}, | ||
]); | ||
``` |
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
1 change: 1 addition & 0 deletions
1
packages/rainbowkit/src/wallets/walletConnectors/xdefiWallet/xdefiWallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions
46
packages/rainbowkit/src/wallets/walletConnectors/xdefiWallet/xdefiWallet.ts
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | ||
import type { InjectedConnectorOptions } from '@wagmi/core/dist/connectors/injected'; | ||
import { InjectedConnector } from 'wagmi/connectors/injected'; | ||
import { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext'; | ||
import { Wallet } from '../../Wallet'; | ||
|
||
declare global { | ||
interface Window { | ||
xfi: any; | ||
} | ||
} | ||
|
||
export interface XDEFIWalletOptions { | ||
chains: Chain[]; | ||
} | ||
|
||
export const xdefiWallet = ({ | ||
chains, | ||
...options | ||
}: XDEFIWalletOptions & InjectedConnectorOptions): Wallet => { | ||
const isInstalled = | ||
typeof window !== 'undefined' && typeof window?.xfi !== 'undefined'; | ||
return { | ||
id: 'xdefi', | ||
name: 'XDEFI Wallet', | ||
installed: isInstalled, | ||
iconUrl: async () => (await import('./xdefiWallet.svg')).default, | ||
iconBackground: '#fff', | ||
downloadUrls: { | ||
browserExtension: | ||
'https://chrome.google.com/webstore/detail/xdefi-wallet/hmeobnfnfcmdkdcmlblgagmfpfboieaf', | ||
}, | ||
createConnector: () => ({ | ||
connector: new InjectedConnector({ | ||
chains, | ||
options: { | ||
//@ts-ignore | ||
getProvider: () => { | ||
return isInstalled ? (window.xfi?.ethereum as any) : undefined; | ||
}, | ||
...options, | ||
}, | ||
}), | ||
}), | ||
}; | ||
}; |