-
Notifications
You must be signed in to change notification settings - Fork 7
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 #58 from lidofinance/fix/reduce-wc-connectors-amount
Fix: reduce WC connectors amount, reef-knot 1.4.2
- Loading branch information
Showing
30 changed files
with
236 additions
and
1,538 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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './walletConnectConnector'; | ||
export * from './walletConnectMobileLinks'; |
79 changes: 25 additions & 54 deletions
79
packages/wallets-helpers/src/factories/walletConnectConnector.ts
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 |
---|---|---|
@@ -1,72 +1,43 @@ | ||
import { WalletConnectLegacyConnector } from 'wagmi/connectors/walletConnectLegacy'; | ||
import { WalletConnectConnector } from 'wagmi/connectors/walletConnect'; | ||
import { Chain } from 'wagmi/chains'; | ||
import { isValidHttpUrl } from '../utils'; | ||
import { walletConnectMobileLinks } from './walletConnectMobileLinks'; | ||
|
||
export const prepareWalletConnectRPC = (rpc: Record<number, string> = {}) => { | ||
const BASE_URL = typeof window === 'undefined' ? '' : window.location.origin; | ||
// adds BASE_URL to `rpc` object's string values | ||
return Object.entries(rpc).reduce( | ||
(result, [key, value]) => ({ | ||
...result, | ||
[key]: isValidHttpUrl(value) ? value : BASE_URL + value, | ||
}), | ||
{} as typeof rpc, | ||
); | ||
}; | ||
let walletconnectConnector: WalletConnectConnector; | ||
let walletconnectConnectorNoQR: WalletConnectConnector; | ||
|
||
export const getWalletConnectConnector = ({ | ||
rpc, | ||
projectId = '', | ||
noMobileLinks = false, | ||
qrcode = true, | ||
v2: _v2 = false, | ||
chains, | ||
}: { | ||
rpc?: Record<number, string>; | ||
projectId?: string; | ||
noMobileLinks?: boolean; | ||
qrcode?: boolean; | ||
v2?: boolean; | ||
chains: Chain[]; | ||
}) => { | ||
let v2EnabledByLS = false; | ||
if (typeof window !== 'undefined') { | ||
v2EnabledByLS = | ||
window.localStorage.getItem('reefknot_wcv2_enable') === 'true'; | ||
} | ||
// WalletConnect v2 will automatically replace legacy v1 after this date: | ||
const v2TransitionDate = new Date('2023-06-24T00:00:00Z'); | ||
const v2 = _v2 || v2EnabledByLS || new Date() > v2TransitionDate; | ||
if (v2) { | ||
return new WalletConnectConnector({ | ||
chains, | ||
options: { | ||
projectId, | ||
showQrModal: qrcode, | ||
qrModalOptions: { | ||
// @walletconnect library currently requires the "chainImages" option, looks like their mistake | ||
chainImages: undefined, | ||
themeVariables: { | ||
'--w3m-z-index': '1000', | ||
// @ts-expect-error walletconnect suddenly renamed w3m to wcm in @walletconnect/modal v2.5 | ||
// It is a breaking change in a minor version update. So now I have to support both options here | ||
'--wcm-z-index': '1000', | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
return new WalletConnectLegacyConnector({ | ||
const params = { | ||
chains, | ||
options: { | ||
rpc: prepareWalletConnectRPC(rpc), | ||
qrcode, | ||
qrcodeModalOptions: { | ||
mobileLinks: noMobileLinks ? [] : walletConnectMobileLinks, | ||
desktopLinks: [], | ||
projectId, | ||
showQrModal: qrcode, | ||
qrModalOptions: { | ||
themeVariables: { | ||
'--w3m-z-index': '1000', | ||
// walletconnect suddenly renamed w3m to wcm in @walletconnect/modal v2.5 | ||
// It is a breaking change in a minor version update. So now I have to support both options here | ||
'--wcm-z-index': '1000', | ||
}, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
if (!qrcode) { | ||
if (!walletconnectConnectorNoQR) { | ||
walletconnectConnectorNoQR = new WalletConnectConnector(params); | ||
} | ||
return walletconnectConnectorNoQR; | ||
} | ||
|
||
if (!walletconnectConnector) { | ||
walletconnectConnector = new WalletConnectConnector(params); | ||
} | ||
return walletconnectConnector; | ||
}; |
45 changes: 0 additions & 45 deletions
45
packages/wallets-helpers/src/factories/walletConnectMobileLinks.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.