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 9 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
2 changes: 2 additions & 0 deletions packages/wallet-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"@ethersproject/experimental": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@lifi/sdk": "^2.0.1",
"@safe-global/safe-apps-provider": "^0.17.0",
"@safe-global/safe-apps-sdk": "^7.11.0",
"@walletconnect/ethereum-provider": "^1.8.0",
"@walletconnect/web3-provider": "^1.8.0",
"events": "^3.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: InjectedConnectorConstructorArgs,
Expand Down
85 changes: 85 additions & 0 deletions packages/wallet-management/src/connectors/safeWalletConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { ethers } from 'ethers';
import events from 'events';
import type {
AccountData,
InjectedConnectorConstructorArgs,
Wallet,
} from '../types';

import type { SafeInfo } from '@safe-global/safe-apps-sdk';
import { SafeAppProvider } from '@safe-global/safe-apps-provider';
import SafeAppsSDK from '@safe-global/safe-apps-sdk/dist/src/sdk';

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

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

public name: string;
public icon: string;

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

this.calcAccountData();
}

public installed = async () => {
return false;
};
public autoConnect = (): any => {
console.warn('Method not allowed');
return null;
};
public disconnect = () => {
console.warn('Method not allowed');
return null;
};
public switchChain = (): any => {
console.warn('Method not allowed');
return null;
};
public addChain = (): any => {
console.warn('Method not allowed');
return null;
};
public addToken = (): any => {
console.warn('Method not allowed');
return null;
};

public connect = (): any => {
console.warn('Method not allowed');
return null;
};

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 ethers.providers.Web3Provider(safeInstance);
const signer = provider.getSigner();

this.account = {
chainId: accountInfo.chainId,
address: accountInfo.safeAddress,
signer,
provider,
isSafeWallet: true,
sdk,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class WalletConnectConnector
public account: AccountData | undefined;
public name: string;
public icon: string;
public installed: () => boolean;
public installed: () => Promise<boolean>;

constructor(constructorArgs: WalletConnectConnectorConstructorArgs) {
super();
Expand Down
17 changes: 10 additions & 7 deletions packages/wallet-management/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Signer } from '@ethersproject/abstract-signer';
import type { Web3Provider } from '@ethersproject/providers';
import type { StaticToken } from '@lifi/sdk';
import type SafeAppsSDK from '@safe-global/safe-apps-sdk/dist/src/sdk';
import type { ethers } from 'ethers';
import type events from 'events';
import type EventEmitter from 'node:events';

export interface ProviderConnectInfo {
Expand All @@ -27,17 +30,17 @@ export interface AccountData {
chainId: number;
address: string;
signer: Signer;
provider: Web3Provider;
provider: ethers.providers.Web3Provider;
isSafeWallet?: boolean;
Abhikumar98 marked this conversation as resolved.
Show resolved Hide resolved
sdk?: SafeAppsSDK;
Abhikumar98 marked this conversation as resolved.
Show resolved Hide resolved
}
export interface InjectedConnectorConstructorArgs {
name: string;
icon: string;
installed: () => boolean;
installed: () => Promise<boolean>;
}
export interface WalletConnectConnectorConstructorArgs {
name: string;
icon: string;
installed: () => boolean;
export interface WalletConnectConnectorConstructorArgs
extends InjectedConnectorConstructorArgs {
rpc: {
[chainId: number]: string;
};
Expand All @@ -48,7 +51,7 @@ export interface Wallet extends EventEmitter {
icon: string;
isActivationInProgress: boolean;
account: AccountData | undefined;
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