Thanks for your interest in contributing to WalletKit! Please take a moment to review this document before submitting a pull request.
This project relies on nodejs, and uses pnpm
as a
package manager, make sure you have them installed:
Then simply clone the repository and enter the directory:
git clone https://github.com/node-real/walletkit.git
git cd walletkit
Install the dependencies and start the local development environment:
pnpm install
pnpm dev
In default, this will run a test example under walletkit package, you can use this example for development and debugging. Any changes in packages/walletkit
will trigger a refresh.
We use eslint
and our code formatting rules are defined in .eslintrc.cjs, you
can check your code by running:
pnpm lint
Besides, before committing, git hook will automatically run eslint to check and fix errors.
Any changes need a test, please make sure all your changes are tested before committing.
Just submit an issue though github issue page.
Before adding a new wallet, you need to collect some information:
item | description | e.g. | required |
---|---|---|---|
wallet name | - | Trust Wallet | ✔️ |
short name | If display space is insufficient, the short name will be displayed. | Trust | optional |
wallet logo | Logo in svg format. It should be noted that WalletKit supports both dark and light modes, for better presentation, you can provide logos in the two modes respectively. | - | ✔️ |
download url | - | https://trustwallet.com/download | ✔️ |
deeplink | After clicking deeplink in the system browser, we can directly open dApp in the app's dApp browser. | trust://open_url?coin_id=60&url=xxx | ✔️ |
WalletConnect uri | If your app supports WalletConnect, please provides the WalletConnect uri. | trust://wc?uri=xxx | optional |
Then you can add it to project by following steps:
- Create a new folder named with wallet name to the
src/wallets
directory, e.g. trustWallet - Create an icon file
icon.tsx
:
export const TrustWalletLightIcon = (props: SVGIconProps) => {
return (
<svg width="52" height="52" viewBox="0 0 52 52" {...props}>
...
</svg>
)
- Create wallet configuration file
index.tsx
:
import { Chain } from 'wagmi';
import {
TrustWalletDarkIcon,
TrustWalletLightIcon,
TrustWalletTransparentDarkIcon,
TrustWalletTransparentLightIcon,
} from './icon';
import { PartialWalletProps, WalletProps } from '../types';
import { TrustWalletConnector, TrustWalletConnectorOptions } from '../trustWallet/connector';
import { hasInjectedProvider } from '../utils';
export const TRUST_WALLET_ID = 'trust';
export interface TrustWalletProps extends PartialWalletProps {
connectorOptions?: TrustWalletConnectorOptions;
}
export function trustWallet(props: TrustWalletProps = {}): WalletProps {
const { connectorOptions, ...restProps } = props;
return {
id: TRUST_WALLET_ID,
name: 'Trust Wallet',
logos: {
default: {
light: <TrustWalletLightIcon />,
dark: <TrustWalletDarkIcon />,
},
mobile: {
light: <TrustWalletMobileLightIcon />,
dark: <TrustWalletMobileDarkIcon />,
},
},
downloadUrls: {
default: 'https://trustwallet.com/',
},
spinnerColor: '#1098FC',
isInstalled: isTrustWallet,
createConnector: (chains: Chain[]) => {
return new TrustWalletConnector({
chains,
options: {
shimDisconnect: true,
...connectorOptions,
},
});
},
getDeepLink: () => {
const dappPath = `https://link.trustwallet.com/open_url?coin_id=60&url=${encodeURIComponent(
window.location.href,
)}`;
return dappPath;
},
getUri(uri) {
return `trust://wc?uri=${encodeURIComponent(uri)}`;
},
...restProps,
};
}
export function isTrustWallet() {
if (typeof window === 'undefined') return false;
return !!(
hasInjectedProvider('isTrust') ||
window?.trustwallet?.isTrust ||
window?.trustWallet?.isTrust
);
}
and the configuration type definition as follow, have a look:
export interface WalletProps {
id: string;
name: string;
logos: {
default: ReactElement | { [x in ColorMode]: ReactElement };
transparent?: ReactElement | { [x in ColorMode]: ReactElement };
};
downloadUrls: {
default: string | undefined;
};
spinnerColor?: string;
showQRCode?: boolean;
isInstalled: () => boolean | undefined;
createConnector: (chains: Chain[]) => Connector;
getDeepLink: () => string | undefined;
getQRCodeUri?: (uri: string) => string;
}
- Export the new wallet in
src/wallets/index.ts
export * from './trustWallet';
- Open
packages/walletkit/test/App.tsx
to test the new wallet
import {
trustWallet, // import new wallet
metaMask,
walletConnect,
} from '@/wallets';
import { useState } from 'react';
const config = createConfig(
getDefaultConfig({
autoConnect: false,
appName: 'WalletKit',
// WalletConnect 2.0 requires a projectId which you can create quickly
// and easily for free over at WalletConnect Cloud https://cloud.walletconnect.com/sign-in
walletConnectProjectId: 'xxx',
chains,
connectors: [
trustWallet(), // Add to wallet list
metaMask(),
walletConnect(),
],
}),
);
- Once the tests pass, the code can be merged into the
alpha
branch
Before merging the PR to main branch, we hope you complete the following tests, and fill the test results into the PR template, otherwise the PR may not be approved.
In general, wallet is available at several different platforms, such as PC browser extension, Android, iOS and WalletConnect. If your wallet supports the corresponding platform, please make sure your wallet is worked.
test case | steps | Does the wallet support connecting by this way? | Does the wallet support switching networks? | Does the wallet support testnet? |
---|---|---|---|---|
PC, browser extension |
|
✔️ | ✔️ | ✔️ |
Android, in system browser |
|
✔️ | ❌ | ✔️ |
Android, in wallet dApp browser |
|
✔️ | ✔️ | ✔️ |
iOS, in system browser |
|
✔️ | ✔️ | ❌ |
iOS, in wallet dApp browser |
|
✔️ | ✔️ | ❌ |
WalletConnect, PC |
|
✔️ | ✔️ | ✔️ |
WalletConnect, Android, in system browser |
|
✔️ | ✔️ | ✔️ |
WalletConnect, Android, in wallet dApp browser |
|
✔️ | ✔️ | ✔️ |
WalletConnect, iOS, in system browser |
|
✔️ | ✔️ | ✔️ |
WalletConnect, iOS, in wallet dApp browser |
|
✔️ | ✔️ | ✔️ |
A complete development workflow like following:
- Create a new branch out of
main
branch - Make some changes, fix bugs or add new features
- Run
pnpm changeset
to create a new changeset - Commit the code, code review is required, after code review, we can merge the code to
alpha
branch - Then github action will automatically execute and create a new release PR, merge this PR, a new version will be released