Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Safe Wallet to wallet management #100

Merged
merged 40 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5ce3de6
feat: adding safe wallet in wallet management
Abhikumar98 Jun 12, 2023
70bd855
fix: added sdk property
Abhikumar98 Jun 12, 2023
f70abeb
fix: made installed func async
Abhikumar98 Jun 15, 2023
204dc54
Merge branch 'main' into lf-3288-safe-wallet
Abhikumar98 Jun 19, 2023
ad4b117
fix: type changes for safe integration
Abhikumar98 Jun 21, 2023
029436d
fix: added safe related events
Abhikumar98 Jun 22, 2023
2b7ff1e
fix: typo fix for sdk property
Abhikumar98 Jun 23, 2023
2da0c9f
fix: review based changes
Abhikumar98 Jun 23, 2023
4743041
fix: UI changes for alert
Abhikumar98 Jun 27, 2023
2249b8d
fix: wrapping safe wallet check in try...catch
Abhikumar98 Jun 28, 2023
4396f76
fix: minor event rename
Abhikumar98 Jun 28, 2023
a490577
Merge branch 'main' into lf-3288-safe-wallet
Abhikumar98 Jun 28, 2023
41aef23
chore: removed alert header
Abhikumar98 Jun 28, 2023
d4d8c79
Merge branch 'main' into lf-3288-safe-wallet
Abhikumar98 Jun 30, 2023
31fef58
fix: review based changes
Abhikumar98 Jul 3, 2023
6c3c74c
fix: removing multisig event
Abhikumar98 Jul 3, 2023
0a8d878
Merge branch 'lf-3288-safe-wallet' of personal:lifinance/widget into …
Abhikumar98 Jul 3, 2023
4c824e4
Merge branch 'main' into lf-3288-safe-wallet
chybisov Jul 4, 2023
57ea843
fix: avoid insufficient gas for safe
Abhikumar98 Jul 4, 2023
6851f29
fix: resolve safe wallet integration pitfalls
chybisov Jul 4, 2023
9c99c81
chore: skip changelog
chybisov Jul 4, 2023
1fdc9c3
chore: bump sdk
chybisov Jul 4, 2023
f58909c
chore(release): 2.2.0-beta.0
chybisov Jul 4, 2023
a7a776d
fix: autoconnect safe wallet
Abhikumar98 Jul 5, 2023
a1cb318
Merge branch 'lf-3288-safe-wallet' of personal:lifinance/widget into …
Abhikumar98 Jul 5, 2023
db1e965
chore: organize imports
chybisov Jul 6, 2023
b906bdf
chore: bump packages
chybisov Jul 6, 2023
450c104
chore(release): 2.2.0-beta.1
chybisov Jul 6, 2023
8b8fa00
fix: added installed + disconnect method
Abhikumar98 Jul 6, 2023
48fb55c
Merge branch 'lf-3288-safe-wallet' of personal:lifinance/widget into …
Abhikumar98 Jul 6, 2023
1c94d71
Merge branch 'main' into lf-3288-safe-wallet
Abhikumar98 Jul 7, 2023
8eacc93
Merge branch 'main' into lf-3288-safe-wallet
chybisov Jul 7, 2023
3b8aba8
chore: bump sdk
chybisov Jul 7, 2023
ee82954
chore(release): 2.2.0-beta.2
chybisov Jul 7, 2023
a69573e
fix: emit route path change event
Abhikumar98 Jul 10, 2023
bf7895e
Merge branch 'lf-3288-safe-wallet' of personal:lifinance/widget into …
Abhikumar98 Jul 10, 2023
2d0e342
fix: handle chain change with separate events
Abhikumar98 Jul 10, 2023
cf2eb56
fix: review commetns
Abhikumar98 Jul 11, 2023
32a3484
Merge branch 'main' into lf-3288-safe-wallet
Abhikumar98 Jul 11, 2023
ef484da
fix: review comments
Abhikumar98 Jul 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.1.4",
"version": "2.2.0-beta.2",
"private": true,
"sideEffects": false,
"packageManager": "[email protected]",
Expand All @@ -10,7 +10,7 @@
"start": "lerna run start",
"build": "lerna run build",
"release": "yarn release:version:before && yarn release:version && yarn release:version:after && yarn standard-version -a",
"release:beta": "yarn release:version:before && yarn release:version && yarn release:version:after && yarn standard-version -a --prerelease beta",
"release:beta": "yarn release:version:before && yarn release:version && yarn release:version:after && yarn standard-version -a --prerelease beta --skip.changelog",
"release:version": "lerna version --preid beta --no-changelog --no-push --no-git-tag-version --no-private",
"release:version:before": "node scripts/private-version before",
"release:version:after": "yarn release:build && node scripts/private-version after",
Expand Down
6 changes: 4 additions & 2 deletions packages/wallet-management/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lifi/wallet-management",
"version": "2.1.4",
"version": "2.2.0-beta.2",
"description": "LI.FI Wallet Management solution.",
"sideEffects": false,
"main": "./src/index.ts",
Expand Down Expand Up @@ -52,7 +52,9 @@
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/experimental": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@lifi/sdk": "^2.1.2",
"@lifi/sdk": "^2.2.0-beta.0",
"@safe-global/safe-apps-provider": "^0.17.1",
"@safe-global/safe-apps-sdk": "^8.0.0",
"@walletconnect/ethereum-provider": "^2.9.0",
"@walletconnect/modal": "^2.5.9",
"events": "^3.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Web3Provider } from '@ethersproject/providers';
import type { StaticToken } from '@lifi/sdk';
import { ethers } from 'ethers';
import events from 'events';
import type {
AccountData,
Expand All @@ -22,7 +22,7 @@ export class InjectedConnector extends events.EventEmitter implements Wallet {
public account: AccountData | undefined;
public name: string;
public icon: string;
public installed: () => boolean;
public installed: () => Promise<boolean>;

constructor(
constructorArgs: InjectedConnectorArgs,
Expand Down Expand Up @@ -169,10 +169,7 @@ export class InjectedConnector extends events.EventEmitter implements Wallet {
throw new Error('provider is not defined.');
}

const provider = new ethers.providers.Web3Provider(
this.windowProvider,
'any',
);
const provider = new Web3Provider(this.windowProvider, 'any');
const accounts = await provider.listAccounts();

if (!accounts.length) {
Expand Down
81 changes: 81 additions & 0 deletions packages/wallet-management/src/connectors/safeWalletConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Web3Provider } from '@ethersproject/providers';
import { SafeAppProvider } from '@safe-global/safe-apps-provider';
import type { SafeInfo } from '@safe-global/safe-apps-sdk';
import SafeAppsSDK from '@safe-global/safe-apps-sdk';
import events from 'events';
import type { AccountData, InjectedConnectorArgs, Wallet } from '../types';

export class SafeWalletConnector extends events.EventEmitter implements Wallet {
public provider: Web3Provider | undefined;

public isActivationInProgress: boolean = false;
public account: AccountData | undefined;

public name: string;
public icon: string;

constructor(args: InjectedConnectorArgs) {
super();
this.name = args.name;
this.icon = args.icon;

this.calcAccountData();
}

public installed = async () => {
const sdk = new SafeAppsSDK();
const accountInfo = await sdk.safe.getInfo();
return !!accountInfo;
};
public autoConnect = async () => {
await this.calcAccountData();
};

public disconnect = () => {
this.account = undefined;
};

public connect = async () => {
await this.calcAccountData();
};

private async calcAccountData() {
const sdk = new SafeAppsSDK();
const accountInfo = await sdk.safe.getInfo();

const safe: SafeInfo = {
safeAddress: accountInfo.safeAddress,
chainId: accountInfo.chainId,
threshold: accountInfo.threshold,
owners: accountInfo.owners,
isReadOnly: accountInfo.isReadOnly,
};

const safeInstance = new SafeAppProvider(safe, sdk);

const provider = new Web3Provider(safeInstance);
const signer = provider.getSigner();

this.account = {
chainId: accountInfo.chainId,
address: accountInfo.safeAddress,
signer,
provider,
isMultisigWallet: true,
};
this.emit('walletAccountChanged', this);
}

public switchChain = (): any => {
console.warn('Method switchChain not allowed');
return null;
};
public addChain = (): any => {
console.warn('Method addChain not allowed');
return null;
};
public addToken = (): any => {
console.warn('Method addToken not allowed');
return null;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class WalletConnectConnector extends EventEmitter implements Wallet {
public account?: AccountData;
public name: string;
public icon: string;
public installed: () => boolean;
public installed: () => Promise<boolean>;

constructor(args: WalletConnectConnectorArgs) {
super();
Expand Down
7 changes: 4 additions & 3 deletions packages/wallet-management/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ export interface AccountData {
address: string;
signer: Signer;
provider: Web3Provider;
isMultisigWallet?: boolean;
}

export interface InjectedConnectorArgs {
name: string;
icon: string;
installed: () => boolean;
installed: () => Promise<boolean>;
}

export interface WalletConnectConnectorArgs {
name: string;
icon: string;
installed: () => boolean;
installed: () => Promise<boolean>;
options: EthereumProviderOptions;
}

Expand All @@ -50,7 +51,7 @@ export interface Wallet extends EventEmitter {
icon: string;
isActivationInProgress: boolean;
account?: AccountData;
installed: () => boolean;
installed: () => Promise<boolean>;
connect: () => Promise<void>;
autoConnect?: () => Promise<void>;
disconnect: () => void;
Expand Down
2 changes: 2 additions & 0 deletions packages/wallet-management/src/walletIcons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import xdefi from './xdefi.svg';
import frontier from './frontier.svg';
import placeholder from './placeholder.svg';
import exodus from './exodus.svg';
import safe from './safe.svg';

export const walletIcons = {
mathwallet,
Expand Down Expand Up @@ -62,4 +63,5 @@ export const walletIcons = {
walletio,
xdefi,
exodus,
safe,
};
12 changes: 12 additions & 0 deletions packages/wallet-management/src/walletIcons/safe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading