-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add Gnosis Safe connector #94
Conversation
✅ Deploy Preview for vue-dapp-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for vue-dapp ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@re2005 Please help me review the code and feel free to give me any advice to improve it, thanks |
src/connectors/safe.ts
Outdated
} from './errors' | ||
|
||
const __IS_SERVER__ = typeof window === 'undefined' | ||
const __IS_IFRAME__ = !__IS_SERVER__ && window?.parent !== window |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to export these flags, so users can use it on their apps to conditionally include the connector or NOT.
Like inside GnosisSafe, the only
connector you should use if the Safe, the other won't work.
For example in my dapo I'm doing this:
const isServer = typeof window === 'undefined';
const isIframe = !isServer && window?.parent !== window;
const connectors: any = [
new MetaMaskConnector({
appUrl: window.location.href,
}),
new WalletConnectConnector({
qrcode: true,
rpc: Object.values(supportedChains).reduce((acc, cur) => ({ ...acc, [cur.chainId]: cur.rpcUrls[0] }), {}),
}),
];
if (isIframe) {
connectors.push(new SafeConnector({}));
}
Maybe is nice if I can import from 'vue-dapp`
import {isGnosisSafe} from 'vue-dapp'
I believe users shouldn't show other connectors in here, only GnosisSafe
Overall it's looking good. Very nice feature to have. Later this weekend I'll test within my own dapps and post here more feedbacks. Nice work @chnejohnson! |
…ionally include the connector or not
Thanks @re2005 for your feedback! In the commit 59d5e26, if (!isNotSafeApp()) {
const safe = new SafeConnector()
connectors = [safe, connectors[0]]
} A strict way is to use const safe = new SafeConnector()
const isSafeApp = await safe.isSafeApp()
if (isSafeApp) {
connectors = [safe, connectors[0]]
} At the moment, I haven't found a good solution to solve this. So just implement the first one for the feature of conditional connector inclusion. |
Hi @chnejohnson thanks for the update. I've tested not only the demo, but also on my application. It all looks good, including the metadata. I believe you can move on and merge it. Great job! |
🎉 This PR is included in version 0.6.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@re2005 glad to hear that, thanks for your review! |
I found a solution to detect the Safe app in a strict way. const connectorsCreated = ref(false)
onMounted(async () => {
const safe = new SafeConnector()
if (await safe.isSafeApp()) {
connectors = [safe]
}
connectorsCreated.value = true
}) <vd-board v-if="connectorsCreated" :connectors="connectors" dark> |
Issues
Reference
Test
yarn build:demo
andyarn serve:demo
http://localhost:4173
in the Safe app (Safe App > Apps > Add custom app)