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 2 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.0-beta.11",
"@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",
"react": "^18.2.0"
Expand Down
88 changes: 88 additions & 0 deletions packages/wallet-management/src/connectors/safeWalletConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 Partial<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 = () => {
Abhikumar98 marked this conversation as resolved.
Show resolved Hide resolved
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,
};
}
}
9 changes: 5 additions & 4 deletions packages/wallet-management/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Signer } from '@ethersproject/abstract-signer';
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';
Expand Down Expand Up @@ -29,16 +30,16 @@ export interface AccountData {
address: string;
signer: Signer;
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;
}
export interface WalletConnectConnectorConstructorArgs {
name: string;
icon: string;
installed: () => boolean;
export interface WalletConnectConnectorConstructorArgs
extends InjectedConnectorConstructorArgs {
rpc: {
[chainId: number]: string;
};
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.
8 changes: 8 additions & 0 deletions packages/wallet-management/src/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { WalletConnectConnector } from './connectors/walletConnectConnector';
import type { Wallet } from './types';
import { ProviderIdentityFlag } from './types';
import { walletIcons } from './walletIcons';
import { SafeWalletConnector } from './connectors/safeWalletConnector';

const defaultWallet: Wallet = new InjectedConnector({
// unknown Default wallet that injects as metamask but is not metamask
Expand Down Expand Up @@ -228,6 +229,12 @@ const exodus: Wallet = new InjectedConnector(
(window as any).exodus?.ethereum,
);

const safe: Wallet = new SafeWalletConnector({
name: 'Safe',
installed: () => false,
Abhikumar98 marked this conversation as resolved.
Show resolved Hide resolved
icon: walletIcons.safe,
});

export const supportedWallets = [
defaultWallet,
metamask,
Expand Down Expand Up @@ -259,4 +266,5 @@ export const supportedWallets = [
oneInch,
tokenary,
mathWallet,
safe,
];
70 changes: 62 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2764,25 +2764,25 @@ __metadata:
linkType: hard

"@lifi/sdk@npm:^2.0.0-beta.11":
version: 2.0.0-beta.11
resolution: "@lifi/sdk@npm:2.0.0-beta.11"
version: 2.0.0-beta.15
resolution: "@lifi/sdk@npm:2.0.0-beta.15"
dependencies:
"@ethersproject/abi": ^5.7.0
"@ethersproject/contracts": ^5.7.0
"@lifi/types": ^5.0.0
"@lifi/types": ^6.0.0
bignumber.js: ^9.1.1
eth-rpc-errors: ^4.0.3
ethers: ^5.7.2
checksum: d3a43ba17aa4181692cd8e855b0be6b05e2a6d62f2d9ab9554e87a71b6b023d75538a385c50dcebecc4b99e995d5e8ba0d24e0186c73e71c51abf35e09b388e8
checksum: 48e08dd7d9eb1cc0c03f4ce9e51debec8f83a9749b83af2726750da89c124ed9d2f20dba75bd64455ad1c462cf734c0e05ebb3d91fd5454a989c67cf5a022782
languageName: node
linkType: hard

"@lifi/types@npm:^5.0.0":
version: 5.0.0
resolution: "@lifi/types@npm:5.0.0"
"@lifi/types@npm:^6.0.0":
version: 6.0.0
resolution: "@lifi/types@npm:6.0.0"
dependencies:
ethers: ^5.7.2
checksum: f9d1c64c666a52c81fb53c5ffefa0460ba7904fe86d9b1d4666ffc2a1e40e87d8e86df73c1639f9e08068a70039f6373117df51e4c6f32b3e26e0f267291ea5a
checksum: 297f0fc0c90d7d56ab76059e505b0f6aebcdaab25baf2bb8ec4982871591288d1b300e7f998f0b13562cb727b388d3eb7c909434072dde2b4f4741d97add4942
languageName: node
linkType: hard

Expand All @@ -2795,6 +2795,8 @@ __metadata:
"@ethersproject/experimental": ^5.7.0
"@ethersproject/providers": ^5.7.2
"@lifi/sdk": ^2.0.0-beta.11
"@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
cpy-cli: ^4.2.0
Expand Down Expand Up @@ -3737,6 +3739,35 @@ __metadata:
languageName: node
linkType: hard

"@safe-global/safe-apps-provider@npm:^0.17.0":
version: 0.17.0
resolution: "@safe-global/safe-apps-provider@npm:0.17.0"
dependencies:
"@safe-global/safe-apps-sdk": 7.11.0
events: ^3.3.0
checksum: b8e3056e32f30ca4d46543cfd5b48da44bd6401f5359260ba771ad02449cfc8c8b46df14bb741b73d47936cd3db7c6f59f3701274950f6cd7b530dea3c10162f
languageName: node
linkType: hard

"@safe-global/safe-apps-sdk@npm:7.11.0, @safe-global/safe-apps-sdk@npm:^7.11.0":
version: 7.11.0
resolution: "@safe-global/safe-apps-sdk@npm:7.11.0"
dependencies:
"@safe-global/safe-gateway-typescript-sdk": ^3.5.3
ethers: ^5.7.2
checksum: 8ada9c238fa485a12f0ecac14aa0c0497635f118c03537980e4ab32da7e8bfd7f01e25cfa1aaac28842e9e27d0d12598aaca943e342d94db305d2b6b9a65df9e
languageName: node
linkType: hard

"@safe-global/safe-gateway-typescript-sdk@npm:^3.5.3":
version: 3.7.3
resolution: "@safe-global/safe-gateway-typescript-sdk@npm:3.7.3"
dependencies:
cross-fetch: ^3.1.5
checksum: 5ee57fe228ff107cc7f08db231e52e8ac217894d1a34189374a01ac3ef18a69ef0ae802a5b21d2d2de11654b96e0117deea007d814eef4dfb9b8c7b82e36ae63
languageName: node
linkType: hard

"@sigstore/protobuf-specs@npm:^0.1.0":
version: 0.1.0
resolution: "@sigstore/protobuf-specs@npm:0.1.0"
Expand Down Expand Up @@ -6842,6 +6873,15 @@ __metadata:
languageName: node
linkType: hard

"cross-fetch@npm:^3.1.5":
version: 3.1.6
resolution: "cross-fetch@npm:3.1.6"
dependencies:
node-fetch: ^2.6.11
checksum: 704b3519ab7de488328cc49a52cf1aa14132ec748382be5b9557b22398c33ffa7f8c2530e8a97ed8cb55da52b0a9740a9791d361271c4591910501682d981d9c
languageName: node
linkType: hard

"cross-spawn@npm:^7.0.2, cross-spawn@npm:^7.0.3":
version: 7.0.3
resolution: "cross-spawn@npm:7.0.3"
Expand Down Expand Up @@ -12078,6 +12118,20 @@ __metadata:
languageName: node
linkType: hard

"node-fetch@npm:^2.6.11":
version: 2.6.11
resolution: "node-fetch@npm:2.6.11"
dependencies:
whatwg-url: ^5.0.0
peerDependencies:
encoding: ^0.1.0
peerDependenciesMeta:
encoding:
optional: true
checksum: 249d0666a9497553384d46b5ab296ba223521ac88fed4d8a17d6ee6c2efb0fc890f3e8091cafe7f9fba8151a5b8d925db2671543b3409a56c3cd522b468b47b3
languageName: node
linkType: hard

"node-gyp-build@npm:^4.2.0, node-gyp-build@npm:^4.3.0":
version: 4.6.0
resolution: "node-gyp-build@npm:4.6.0"
Expand Down