-
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.
Merge pull request #953 from IntersectMBO/develop
Fix slow delegation issue and usePendingTransaction fixes
- Loading branch information
Showing
71 changed files
with
8,471 additions
and
74 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
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
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
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,56 @@ | ||
# Wallet Service | ||
|
||
The WalletService.ts file contains the implementation of a wallet service, designed to manage wallet. It includes the enableWallet function responsible for enabling the wallet connection and allows get cip95 functions. | ||
|
||
1. Install wallet-connector package. | ||
|
||
```sh | ||
yarn add wallet-connector | ||
``` | ||
|
||
2. Import service from wallet-connector. | ||
|
||
```javascript | ||
import { WalletService } from "@wallet-connector"; | ||
``` | ||
|
||
3. Usage - for enable your browser wallet extension. | ||
EXAMPLE: | ||
|
||
```javascript | ||
const newWalletAPI = await WalletService.enableWallet("%WALLET_NAME%"); | ||
``` | ||
|
||
# Wallet Provider | ||
|
||
WalletProvider component which serves as a React Context Provider to facilitate wallet integration across components. | ||
|
||
1. Install wallet-connector package | ||
|
||
```sh | ||
yarn add wallet-connector | ||
``` | ||
|
||
2. Import WalletProvider from wallet-connector and wrap your app. | ||
|
||
```javascript | ||
import { WalletProvider } from "@wallet-connector"; | ||
|
||
<WalletProvider> | ||
<App /> | ||
</WalletProvider>; | ||
``` | ||
|
||
3. Usage | ||
|
||
```javascript | ||
import { useWalletContext } from "@wallet-connector"; | ||
|
||
const { | ||
disconnectWallet, | ||
enableError, | ||
enableWallet, | ||
isEnableLoading, | ||
walletAPI, | ||
} = useWalletContext(); | ||
``` |
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,63 @@ | ||
import React, { createContext, useContext, useMemo, useState } from "react"; | ||
|
||
import { WalletService } from "./WalletService"; | ||
import { | ||
TWalletAPI, | ||
WalletContextProviderProps, | ||
WalletConnectorErrors, | ||
WalletContextValues, | ||
} from "./types"; | ||
|
||
const WalletContext = createContext<WalletContextValues | null>(null); | ||
|
||
const WalletProvider = ({ children }: WalletContextProviderProps) => { | ||
const [isEnableLoading, setIsEnableLoading] = useState<boolean>(false); | ||
const [enableError, setEnableError] = useState<string | null>(null); | ||
const [walletAPI, setWalletAPI] = useState<TWalletAPI | null>(null); | ||
|
||
const enableWallet = async (walletName: string): Promise<void> => { | ||
setEnableError(null); | ||
setIsEnableLoading(true); | ||
try { | ||
const newWalletAPI = await WalletService.enableWallet(walletName); | ||
|
||
if (newWalletAPI) setWalletAPI(newWalletAPI); | ||
} catch (e) { | ||
setEnableError(e); | ||
throw e; | ||
} finally { | ||
setIsEnableLoading(false); | ||
} | ||
}; | ||
|
||
const disableWallet = () => { | ||
setWalletAPI(null); | ||
}; | ||
|
||
const value = useMemo( | ||
() => ({ | ||
disableWallet, | ||
enableError, | ||
enableWallet, | ||
isEnableLoading, | ||
walletAPI, | ||
}), | ||
[disableWallet, enableError, enableWallet, isEnableLoading, walletAPI] | ||
); | ||
|
||
return ( | ||
<WalletContext.Provider value={value}>{children}</WalletContext.Provider> | ||
); | ||
}; | ||
|
||
const useWalletContext = (): WalletContextValues => { | ||
const context = useContext(WalletContext); | ||
if (!context) | ||
throw new Error( | ||
WalletConnectorErrors.USE_WALLET_CONTEXT_USED_WITHOUT_PROVIDER | ||
); | ||
|
||
return context; | ||
}; | ||
|
||
export default { useWalletContext, WalletProvider }; |
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,37 @@ | ||
import { TWalletAPI, WalletConnectorErrors } from "./types"; | ||
|
||
export namespace WalletService { | ||
export const enableWallet = async ( | ||
walletName: string | ||
): Promise<TWalletAPI> => { | ||
try { | ||
if (!window.cardano[walletName].supportedExtensions) | ||
throw new Error( | ||
WalletConnectorErrors.NO_CIP30_SUPPORT.replace( | ||
"%WALLET_NAME%", | ||
walletName | ||
) | ||
); | ||
|
||
if ( | ||
!window.cardano[walletName].supportedExtensions.some( | ||
(item) => item.cip === 95 | ||
) | ||
) | ||
throw new Error( | ||
WalletConnectorErrors.NO_CIP95_SUPPORT.replace( | ||
"%WALLET_NAME%", | ||
walletName | ||
) | ||
); | ||
|
||
const walletApi = await window.cardano[walletName].enable({ | ||
extensions: [{ cip: 95 }], | ||
}); | ||
|
||
return walletApi; | ||
} catch (e) { | ||
throw e; | ||
} | ||
}; | ||
} |
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,3 @@ | ||
export * from "./WalletProvider"; | ||
export * from "./WalletService"; | ||
export * from "./types"; |
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,12 @@ | ||
{ | ||
"name": "wallet-connector", | ||
"version": "1.0.0", | ||
"main": "index.ts", | ||
"license": "MIT", | ||
"dependencies": { | ||
"react": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.3.1" | ||
} | ||
} |
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,69 @@ | ||
import { ReactNode } from "react"; | ||
|
||
export type WalletContextProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export type WalletContextValues = { | ||
disableWallet: () => void; | ||
enableError: string | null; | ||
enableWallet: (walletName: string) => Promise<void>; | ||
isEnableLoading: boolean; | ||
walletAPI: TWalletAPI | null; | ||
}; | ||
|
||
export type Extension = { | ||
cip: number; | ||
}; | ||
|
||
export type TWalletAPI = { | ||
cip95: { | ||
getPubDRepKey(): Promise<string>; | ||
getRegisteredPubStakeKeys(): Promise<string[]>; | ||
getUnregisteredPubStakeKeys(): Promise<string[]>; | ||
signData(arg0: any, arg1: any): Promise<any>; | ||
}; | ||
experimantal: { | ||
on(arg0: any, arg1: any): any; | ||
off(arg0: any, arg1: any): any; | ||
getCollateral(): any; | ||
}; | ||
getBalance(): Promise<string>; | ||
getChangeAddress(): Promise<string>; | ||
getExtensions(): Promise<Extension[]>; | ||
getNetworkId(): Promise<number>; | ||
getRewardAddresses(): Promise<string[]>; | ||
getUnusedAddresses(): Promise<string[]>; | ||
getUsedAddresses(): Promise<string[]>; | ||
getUtxos(): Promise<string[]>; | ||
signData(arg0: any, arg1?: any): Promise<any>; | ||
signTx(arg0: any, arg1?: any): Promise<any>; | ||
submitTx(arg0: any): Promise<any>; | ||
}; | ||
|
||
export type EnableExtensionPayload = { | ||
extensions: Extension[]; | ||
}; | ||
|
||
export type CardanoBrowserWallet = { | ||
apiVersion: string; | ||
enable(extensions?: EnableExtensionPayload): Promise<TWalletAPI>; | ||
icon: string; | ||
isEnabled(): Promise<boolean>; | ||
name: string; | ||
supportedExtensions: Extension[]; | ||
}; | ||
|
||
declare global { | ||
interface Window { | ||
cardano: { | ||
[key: string]: CardanoBrowserWallet; | ||
}; | ||
} | ||
} | ||
|
||
export enum WalletConnectorErrors { | ||
NO_CIP30_SUPPORT = "%WALLET_NAME% wallet doesn't support CIP 30 extension.", | ||
NO_CIP95_SUPPORT = "%WALLET_NAME% wallet doesn't support CIP 95 extension.", | ||
USE_WALLET_CONTEXT_USED_WITHOUT_PROVIDER = "useWalletContext must be used in the WalletProvider.", | ||
} |
Oops, something went wrong.