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

Capsule integration final #883

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
80de7e4
initial commit - basic capsule int
storywithoutend Jun 10, 2024
2b8d819
Merge branch 'main' into capsule-integration
jlm0 Jul 30, 2024
197987c
chore: pnpm update
jlm0 Jul 30, 2024
d0c5b9d
fix capsule
jlm0 Jul 31, 2024
2e9d342
Merge branch 'main' into pr/786
LeonmanRolls Aug 23, 2024
95a1785
onramp
LeonmanRolls Aug 25, 2024
c25c67f
Update capsule rainbow
LeonmanRolls Sep 2, 2024
abce894
Merge branch 'main' of https://github.com/ensdomains/ens-app-v3 into …
LeonmanRolls Sep 2, 2024
fc317e9
Theme fix
LeonmanRolls Sep 23, 2024
6cd4116
dynamically load capsule wallet
LeonmanRolls Sep 25, 2024
0d36cef
fixes
TateB Sep 25, 2024
df18ce8
disable worker
TateB Sep 25, 2024
d1264aa
update deps
LeonmanRolls Oct 7, 2024
6f4228d
Merge branch 'main' of https://github.com/ensdomains/ens-app-v3 into …
LeonmanRolls Oct 20, 2024
03c25d6
check if wallet is capsule
LeonmanRolls Oct 21, 2024
c5d303e
Link to capsule wallet when connected with capsule
LeonmanRolls Oct 22, 2024
a6d1653
Update Pricing.tsx
LeonmanRolls Oct 22, 2024
26cbe06
Merge branch 'main' of https://github.com/ensdomains/ens-app-v3 into …
LeonmanRolls Oct 22, 2024
b183869
Remove hotfix
LeonmanRolls Oct 22, 2024
876dfe5
load capsule tests
LeonmanRolls Oct 23, 2024
372d4a8
Mock capsule rainbowkit
LeonmanRolls Oct 23, 2024
c2e6188
Fix types
LeonmanRolls Oct 24, 2024
cfc8c2d
Review fixes
LeonmanRolls Oct 24, 2024
fd240fd
Merge branch 'main' of https://github.com/ensdomains/ens-app-v3 into …
LeonmanRolls Oct 28, 2024
1e5bb32
bump versions
LeonmanRolls Oct 29, 2024
29dbece
Add api keys
LeonmanRolls Oct 29, 2024
8521a2a
bump version
LeonmanRolls Oct 29, 2024
1de130a
wip
LeonmanRolls Nov 1, 2024
de0f4f9
merge main
LeonmanRolls Dec 3, 2024
32101ea
grab network from subdomain
LeonmanRolls Dec 3, 2024
c4ec941
getChainFromUrl
LeonmanRolls Dec 3, 2024
1535ceb
Switch account action
LeonmanRolls Dec 5, 2024
356293c
handleSendTransaction
LeonmanRolls Dec 7, 2024
adedc98
Network notifications
LeonmanRolls Dec 13, 2024
ab4dc6f
Capsule priority fee
LeonmanRolls Dec 13, 2024
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
11 changes: 11 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ const babelIncludeRegexes = [
* @type {import('next').NextConfig}
* */
const nextConfig = {
transpilePackages: [
'@usecapsule/rainbowkit',
'@usecapsule/rainbowkit-wallet',
'@usecapsule/core-components',
'@usecapsule/react-components',
'@usecapsule/react-sdk',
'@usecapsule/core-sdk',
'@usecapsule/web-sdk',
'@usecapsule/wagmi-v2-integration',
'@usecapsule/viem-v2-integration',
],
reactStrictMode: true,
compiler: {
styledComponents: true,
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,21 @@
"@metamask/post-message-stream": "^6.1.2",
"@metamask/providers": "^14.0.2",
"@noble/hashes": "^1.3.2",
"@rainbow-me/rainbowkit": "2.1.2",
"@sentry/nextjs": "7.43.x",
"@sentry/nextjs": "^7.43.0",
"@svgr/webpack": "^8.1.0",
"@tanstack/query-persist-client-core": "5.22.2",
"@tanstack/query-sync-storage-persister": "5.22.2",
"@tanstack/react-query": "5.22.2",
"@tanstack/react-query-persist-client": "5.22.2",
"@usecapsule/rainbowkit": "3.1.0",
"@usecapsule/rainbowkit-wallet": "1.1.0",
"@wagmi/core": "2.13.3",
"@walletconnect/ethereum-provider": "^2.11.1",
"@walletconnect/modal": "^2.6.2",
"calendar-link": "^2.2.0",
"dns-packet": "^5.4.0",
"form-data": "^4.0.0",
"glob": "^8.0.3",
"graphql-request": "5.1.0",
"i18next": "^21.9.1",
"i18next-browser-languagedetector": "^6.1.5",
Expand All @@ -82,6 +85,7 @@
"lodash": "^4.17.21",
"markdown-to-jsx": "^7.1.7",
"next": "13.5.6",
"node-forge": "1.3.1",
"node-fetch": "^3.3.2",
"react": "^18.2.0",
"react-confetti": "^6.1.0",
Expand Down Expand Up @@ -202,7 +206,8 @@
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
},
"packageManager": "[email protected]"
Expand Down
36 changes: 36 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 27d0e3a0073c20adff764c71575e200d6ac23432..0000000000000000000000000000000000000000
diff --git a/flash/README.md b/flash/README.md
deleted file mode 100644
index 1576ebf1a99dab1462caa81c14240864ed1454cb..0000000000000000000000000000000000000000
diff --git a/flash/package.json b/flash/package.json
deleted file mode 100644
index 92689fa9b24e93a631d2b52572030d7e17ccb10f..0000000000000000000000000000000000000000
diff --git a/lib/rsa.js b/lib/rsa.js
index 5c73209f9a1c97c8f1e58bc2930426c4f580776a..fb4cdad07208d23c10dedbc1f39b1435a4539d65 100644
--- a/lib/rsa.js
+++ b/lib/rsa.js
@@ -1717,13 +1717,15 @@ function _generateKeyPair(state, options, callback) {

var opts = {
algorithm: {
- name: options.algorithm || 'PRIMEINC',
- options: {
- workers: options.workers || 2,
- workLoad: options.workLoad || 100,
- workerScript: options.workerScript
- }
- }
+ name: options.algorithm || "PRIMEINC",
+ options: options.workerScript
+ ? {
+ workers: options.workers || 2,
+ workLoad: options.workLoad || 100,
+ workerScript: options.workerScript,
+ }
+ : {},
+ },
};
if('prng' in options) {
opts.prng = options.prng;
2,565 changes: 1,377 additions & 1,188 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"noPrimaryName": "No Primary Name",
"viewProfile": "View Profile",
"viewDetails": "View Details",
"register": "Register"
"register": "Register",
"myWallet": "My Wallet"
},
"name": {
"registered": "Registered",
Expand Down
29 changes: 26 additions & 3 deletions src/components/ConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useConnectModal } from '@usecapsule/rainbowkit'
import { Key, ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
import type { Address } from 'viem'
import { useDisconnect, useEnsAvatar } from 'wagmi'
import { Config, useDisconnect, useEnsAvatar } from 'wagmi'

import {
Button,
Expand All @@ -14,6 +14,7 @@ import {
mq,
PersonSVG,
Profile,
WalletSVG,
} from '@ensdomains/thorin'
import { DropdownItem } from '@ensdomains/thorin/dist/types/components/molecules/Dropdown/Dropdown'

Expand All @@ -25,6 +26,7 @@ import { useRouterWithHistory } from '@app/hooks/useRouterWithHistory'
import { useZorb } from '@app/hooks/useZorb'
import { useBreakpoint } from '@app/utils/BreakpointProvider'
import { ensAvatarConfig } from '@app/utils/query/ipfsGateway'
import { wagmiConfig } from '@app/utils/query/wagmi'
import { shortenAddress } from '@app/utils/utils'

import BaseLink from './@atoms/BaseLink'
Expand Down Expand Up @@ -106,6 +108,13 @@ const calculateTestId = (isTabBar: boolean | undefined, inHeader: boolean | unde
return 'connect-button'
}

const getIsCapsuleConnected = (wagmiState: Config['state']) => {
const capsuleIntegratedConnection = Array.from(wagmiState.connections.values()).find(
(connection) => connection?.connector?.id === 'capsule-integrated',
)
return !!capsuleIntegratedConnection
}

export const ConnectButton = ({ isTabBar, large, inHeader }: Props) => {
const { t } = useTranslation('common')
const breakpoints = useBreakpoint()
Expand Down Expand Up @@ -145,6 +154,8 @@ const HeaderProfile = ({ address }: { address: Address }) => {
const { copy, copied } = useCopied(300)
const hasPendingTransactions = useHasPendingTransactions()

const isCapsuleConnected = getIsCapsuleConnected(wagmiConfig.state)

return (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this be better suited to use with wagmi's useConnections?

<Profile
address={address}
Expand Down Expand Up @@ -185,13 +196,25 @@ const HeaderProfile = ({ address }: { address: Address }) => {
onClick: () => copy(address),
icon: copied ? <CheckSVG /> : <CopySVG />,
},
isCapsuleConnected
? {
label: t('wallet.myWallet'),
color: 'text',
icon: <WalletSVG />,
wrapper: (children: ReactNode, key: Key) => (
<BaseLink href="https://connect.usecapsule.com/" key={key}>
{children}
</BaseLink>
),
}
: null,
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use ...[isCapsuleConnected ? [...] : []] you can avoid filtering

label: t('wallet.disconnect'),
color: 'red',
onClick: () => disconnect(),
icon: <ExitSVG />,
},
] as DropdownItem[]
].filter((dropdownItem) => !!dropdownItem) as DropdownItem[]
}
avatar={{
src: avatar || zorb,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useConnectModal } from '@usecapsule/rainbowkit'
import { Dispatch, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useConnectModal } from '@rainbow-me/rainbowkit'
import { useConnectModal } from '@usecapsule/rainbowkit'
import { Dispatch, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('ActionButton', () => {
ethPrice: 1n,
durationType: 'years',
}

it('should have disabled "Next" button if no choice has been made', () => {
render(<ActionButton {...baseMockData} />)
expect(screen.getByText('action.next')).toBeInTheDocument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ const Pricing = ({
const previousMoonpayTransactionStatus = usePrevious(moonpayTransactionStatus)

const [paymentMethodChoice, setPaymentMethodChoice] = useState<PaymentMethod>(
hasPendingMoonpayTransaction ? PaymentMethod.moonpay : PaymentMethod.ethereum,
hasPendingMoonpayTransaction || balance?.value === 0n
? PaymentMethod.moonpay
: PaymentMethod.ethereum,
)

// Keep radio button choice up to date
Expand Down
22 changes: 6 additions & 16 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { lightTheme, RainbowKitProvider, Theme } from '@rainbow-me/rainbowkit'

import '@rainbow-me/rainbowkit/styles.css'

// prettier-ignore-file
import { NextPage } from 'next'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

import type { AppProps } from 'next/app'
import { ReactElement, ReactNode } from 'react'
Expand All @@ -19,25 +16,18 @@ import { TransactionFlowProvider } from '@app/transaction-flow/TransactionFlowPr
import { setupAnalytics } from '@app/utils/analytics'
import { BreakpointProvider } from '@app/utils/BreakpointProvider'
import { QueryProviders } from '@app/utils/query/providers'
import { RainbowKitWithCapsuleProvider } from '@app/utils/query/RainbowKitWithCapsuleProvider'
import { SyncDroppedTransaction } from '@app/utils/SyncProvider/SyncDroppedTransaction'
import { SyncProvider } from '@app/utils/SyncProvider/SyncProvider'

import '@usecapsule/rainbowkit/styles.css'

import i18n from '../i18n'

import '../styles.css'

const INTERCOM_ID = process.env.NEXT_PUBLIC_INTERCOM_ID || 'eotmigir'

const rainbowKitTheme: Theme = {
...lightTheme({
accentColor: thorinLightTheme.colors.accent,
borderRadius: 'medium',
}),
fonts: {
body: 'Satoshi, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif',
},
}

const anim = keyframes`
0% {
opacity: 1;
Expand Down Expand Up @@ -144,7 +134,7 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
return (
<I18nextProvider i18n={i18n}>
<QueryProviders>
<RainbowKitProvider theme={rainbowKitTheme}>
<RainbowKitWithCapsuleProvider>
<TransactionStoreProvider>
<ThemeProvider theme={thorinLightTheme}>
<BreakpointProvider queries={breakpoints}>
Expand All @@ -164,7 +154,7 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
</BreakpointProvider>
</ThemeProvider>
</TransactionStoreProvider>
</RainbowKitProvider>
</RainbowKitWithCapsuleProvider>
</QueryProviders>
</I18nextProvider>
)
Expand Down
7 changes: 7 additions & 0 deletions src/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ vi.mock('@app/hooks/useRegistrationReducer', () => vi.fn(() => ({ item: { stepIn

export const mockUseAccountReturnValue = { address: '0x123' }

vi.mock('@usecapsule/rainbowkit', () => ({
useConnectModal: () => ({
openConnectModal: vi.fn(),
}),
connectorsForWallets: () => [() => {}],
}))

vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (value: string, opts: any) => {
Expand Down
51 changes: 0 additions & 51 deletions src/utils/getDefaultWallets.ts

This file was deleted.

33 changes: 33 additions & 0 deletions src/utils/query/RainbowKitWithCapsuleProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { lightTheme, RainbowKitProvider, Theme } from '@usecapsule/rainbowkit'
import { ComponentProps, useEffect, useState } from 'react'

import { loadCapsule } from './loadCapsule'

type RainbowKitProviderProps = ComponentProps<typeof RainbowKitProvider>

const rainbowKitTheme: Theme = {
...lightTheme({
// accentColor: thorinLightTheme.colors.accent, // requires a hex string color but thorinLightTheme returns a hsl string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

borderRadius: 'medium',
}),
fonts: {
body: 'Satoshi, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif',
},
}

export const RainbowKitWithCapsuleProvider = (props: RainbowKitProviderProps) => {
const [capsuleData, setCapsule] = useState<Awaited<ReturnType<typeof loadCapsule>> | null>(null)

useEffect(() => {
loadCapsule().then(setCapsule)
}, [])

return (
<RainbowKitProvider
theme={rainbowKitTheme}
{...props}
capsule={capsuleData?.capsuleClient}
capsuleIntegratedProps={capsuleData?.capsuleModalProps}
/>
)
}
Loading
Loading