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

Update the dApp to work in Ledger Live #708

Merged
merged 180 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
b289c7f
Create ledger live manifest template
kkosiorowska Aug 20, 2024
5a8a5f5
Store the ledger live manifest for all env
kkosiorowska Aug 20, 2024
1a792e0
Add a special parameter for Ledger Live mode
kkosiorowska Aug 20, 2024
968c6b6
Add script for generating all manifest files for ledger live
kkosiorowska Aug 20, 2024
2b57998
Create a special hook to check if the dApp is embedded
kkosiorowska Aug 20, 2024
91ef510
Set a referral for the embedded dApp
kkosiorowska Aug 20, 2024
6b9e75f
Merge branch 'main' into ledger-live-updates
kkosiorowska Sep 4, 2024
9860d3d
Merge branch 'main' of github.com:thesis/acre into ledger-live-updates
kkosiorowska Sep 20, 2024
910e7d8
Create a helper function - `getURLParam`
kkosiorowska Sep 20, 2024
e2339a2
Use only needed connectors when the app is embed
kkosiorowska Sep 20, 2024
b780c3f
Call account selection action when app is embedded dApp
kkosiorowska Sep 20, 2024
109d71c
Define basic information about a ledger wallet
kkosiorowska Sep 20, 2024
678d151
Update texts when app is embedded dApp
kkosiorowska Sep 20, 2024
128cc29
Error handling for ledger live app
kkosiorowska Sep 20, 2024
195ad04
Add Ledger Live connector
r-czajkowski Sep 24, 2024
043d623
Add ledger live manifest for testnet preview
r-czajkowski Sep 24, 2024
cf090d2
Add Ledger Live connector (#733)
r-czajkowski Sep 25, 2024
c8f5f21
DApp integration with ledger live app (#730)
r-czajkowski Sep 25, 2024
dfd921b
Update Ledger live manifest for testnet preview
r-czajkowski Sep 25, 2024
7576045
Update Ledger Live manifest
r-czajkowski Sep 25, 2024
e32336e
Disable signature verification on login
r-czajkowski Sep 25, 2024
dd38e20
Merge branch 'main' of github.com:thesis/acre into ledger-live-updates
kkosiorowska Sep 27, 2024
b09fbeb
Trigger connection action for embed dApp
kkosiorowska Sep 27, 2024
2a12ddb
Triggering the connect wallet flow when application starts
kkosiorowska Sep 27, 2024
c4e698f
Cache the last used account in local storage
kkosiorowska Sep 27, 2024
b003ae2
Bump orangekit package to latest dev version
r-czajkowski Sep 27, 2024
b893911
Fix a bug of incorrect check for the `localStorage` item
kkosiorowska Sep 30, 2024
9aa13a0
Bump `@orangekit/react` dependency
r-czajkowski Sep 30, 2024
9527153
Improve error handling in connect wallet flow
r-czajkowski Oct 1, 2024
1fb905c
Fix refetching data on reconnect
r-czajkowski Oct 2, 2024
c2f723a
Mock session mechanism in dapp
r-czajkowski Oct 2, 2024
f0ac21d
Bump `@orangekit/react` package
r-czajkowski Oct 2, 2024
3e04a2a
Init "0-click connection" flow for the Ledger Live App (#742)
nkuba Oct 2, 2024
dc37b81
Handle Taprrot address validation correctly
r-czajkowski Oct 3, 2024
e50d86d
Update `ConnectWalletButton` component
r-czajkowski Oct 3, 2024
b38296d
Update `testnet` config for ledger live manifest
r-czajkowski Oct 3, 2024
52bfd1a
Update dapp scripts
r-czajkowski Oct 3, 2024
3b8b1b5
Add helper function
r-czajkowski Oct 3, 2024
36be355
Set mobile mode only when the dApp is not embedded
kkosiorowska Oct 8, 2024
87aa016
Add switch account button
r-czajkowski Oct 9, 2024
bcb19ce
Set referral code program based on the embed app
r-czajkowski Oct 9, 2024
baa9013
Set correct referral code for Ledger Live
r-czajkowski Oct 9, 2024
4cd1708
Update the reconnect flow
r-czajkowski Oct 9, 2024
74026fc
Refactor for `Layout` component
kkosiorowska Oct 9, 2024
c64750a
Set page content max width in Layout component
kkosiorowska Oct 9, 2024
ee381ef
Add responsiveness for transaction table row
kkosiorowska Oct 10, 2024
9177195
Add a basic grid for the dashboard view for the embedded dApp
kkosiorowska Oct 10, 2024
16a4d8e
Update design for position details card
kkosiorowska Oct 10, 2024
791ce85
Update maximum width for dApp
kkosiorowska Oct 10, 2024
08d0fec
Update grid template columns for embed dApp
kkosiorowska Oct 10, 2024
f5c1d4a
Change from "Deposit more" to "Deposit"
kkosiorowska Oct 10, 2024
a373330
Disable sidebar for embedded dApp
kkosiorowska Oct 11, 2024
cf93e14
Simplify the referral program code
r-czajkowski Oct 14, 2024
e89bb0f
Update the `aria-label` param for change acc btn
r-czajkowski Oct 14, 2024
85c2152
Fix reconnect function
r-czajkowski Oct 14, 2024
a2b8d73
Keep the same approach of layout for dApp
kkosiorowska Oct 15, 2024
71c79de
Fix the reconnect flow
r-czajkowski Oct 16, 2024
4e9541b
Display correct statuses when reconnecting
r-czajkowski Oct 16, 2024
eb73390
Revert "Simplify the referral program code"
r-czajkowski Oct 16, 2024
cbd881d
Set correct referral code for embeded dapp
r-czajkowski Oct 16, 2024
afe09bb
Merge branch 'add-change-acc-btn' into set-referral
r-czajkowski Oct 16, 2024
908e8ef
Rename the `TEMPLATE_AREAS_LEDGER_LIVE` to `TEMPLATE_AREA`
kkosiorowska Oct 17, 2024
8bfd363
Set the `maxW` based on the embedded app
kkosiorowska Oct 17, 2024
13a4cfc
Set the correct values for the max width of the layout
kkosiorowska Oct 17, 2024
b5de967
Changing the max width for a standalone dAPP
kkosiorowska Oct 17, 2024
f55e76b
Use equal width for the deposit/withdraw buttons
kkosiorowska Oct 17, 2024
a506f31
Set row height to fit content height in CSS Grid
kkosiorowska Oct 18, 2024
cf5a789
Fix responsiveness on small window size (#763)
kpyszkowski Oct 18, 2024
aecbe9a
Update `useWallet` hook
r-czajkowski Oct 21, 2024
a7561d1
Add switch account button (#760)
kkosiorowska Oct 21, 2024
1114fd5
Set referral code for embedded app (#761)
kkosiorowska Oct 21, 2024
2ba62f3
Merge branch 'main' into ledger-live-updates
r-czajkowski Oct 21, 2024
504d590
Bump orangekit package
r-czajkowski Oct 21, 2024
7ee4d06
Update connection modal for embedded apps
r-czajkowski Oct 21, 2024
a757133
Update the Dashboard layout
r-czajkowski Oct 21, 2024
60b474d
Remove unnecessary import
r-czajkowski Oct 21, 2024
2db8296
Update `useTriggerConnectWalletModal` hook
r-czajkowski Oct 21, 2024
6583918
Set the `maxW` based on the embedded app
kkosiorowska Oct 22, 2024
3a87cee
Implement `Footer` component
kpyszkowski Oct 22, 2024
bf9a516
Delete `Header`'s navigation
kpyszkowski Oct 22, 2024
e95acec
Update layout
kpyszkowski Oct 23, 2024
161beb1
Update the BitcoinProvider interface
r-czajkowski Oct 23, 2024
fc64e43
Implement custom bitcoin provider and connector
r-czajkowski Oct 23, 2024
88ae769
Update Ledger Live manifests
r-czajkowski Oct 23, 2024
48e2edf
Improve z indicies order
kpyszkowski Oct 24, 2024
aaa2010
Remove `UsefulLinks` component
kpyszkowski Oct 24, 2024
d684b1a
Update orangekit packages
r-czajkowski Oct 24, 2024
76ae212
Remove workaround for the session mechanism
r-czajkowski Oct 24, 2024
bff809c
Fix linting error
r-czajkowski Oct 24, 2024
b3b63d7
Update the BitcoinProvider interface
r-czajkowski Oct 23, 2024
68f074a
Update Bitcoin lib in SDK
r-czajkowski Oct 24, 2024
0961e5d
Install `@ledgerhq/wallet-api-client` in dapp
r-czajkowski Oct 24, 2024
af55b79
Add Ledger Live connector and provider to dapp
r-czajkowski Oct 24, 2024
e75ec7d
Update permissions list in ledger manifest
r-czajkowski Oct 24, 2024
c5e1be9
Update `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 24, 2024
02be381
Fix redeemer-proxy unit tests
r-czajkowski Oct 24, 2024
be53b58
Remove unnecessary `Network` type
r-czajkowski Oct 24, 2024
945ea09
Remove unnecessary optional chaining
r-czajkowski Oct 24, 2024
821f2b9
Bump orangekit package
r-czajkowski Oct 24, 2024
17fba22
Fix linting error
r-czajkowski Oct 24, 2024
bbddaec
Update `getOrangeKitLedgerLiveConnector`
r-czajkowski Oct 24, 2024
1a9b866
Update Footer font size
kpyszkowski Oct 24, 2024
ab4881a
Define `isExternal` prop inline
kpyszkowski Oct 24, 2024
dc7c746
Remove unused import
kpyszkowski Oct 24, 2024
08496ae
Fix modal z indicies
kpyszkowski Oct 24, 2024
f77df1c
Update footer list rendering
kpyszkowski Oct 24, 2024
0226187
Remove connect wallet button conditional rendering
kpyszkowski Oct 24, 2024
e99cbdd
dApp: Update navigation (#777)
kkosiorowska Oct 25, 2024
fb719ba
Add docs for `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 25, 2024
b46bee0
Add unit tests for `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 25, 2024
8772372
Add unit tests for `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 28, 2024
c0d841e
Update `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 29, 2024
6f45b6d
Set the `maxW` based on the embedded app (#775)
kpyszkowski Oct 29, 2024
ab98bbc
Update the `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 29, 2024
52cbd2c
Rename variables in `ConnectWalletButton`
r-czajkowski Oct 29, 2024
590e226
Update `ConnectWalletModalBase` component
r-czajkowski Oct 29, 2024
fa48081
Update `useWallet` hook
r-czajkowski Oct 29, 2024
e39ed9b
Remove unused imports
r-czajkowski Oct 29, 2024
d91b538
Add more unit tests for `signMessage` fn
r-czajkowski Oct 29, 2024
e1d6276
Fix unit tests
r-czajkowski Oct 29, 2024
3d210b4
Update the `test` script
r-czajkowski Oct 29, 2024
aaee3cc
Update Ledger Live manifests
r-czajkowski Oct 30, 2024
6ba9a9f
Update `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 30, 2024
a3cd8a4
Update `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 30, 2024
57486c0
Update `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 30, 2024
289aa1f
Bump Orangekit packages
r-czajkowski Oct 30, 2024
f118aaf
Add `bignumber.js` package to dapp
r-czajkowski Oct 30, 2024
2aec262
Rename `BitcoinProvider` to `AcreBitcoinProvider`
r-czajkowski Oct 30, 2024
a3d1c41
Fix `AcreLedgerLiveBitcoinProvider` unit tests
r-czajkowski Oct 30, 2024
3044bdc
Remove unnecessary `await` in unit test
r-czajkowski Oct 30, 2024
2d80037
Remove unnecessary `toString()`
r-czajkowski Oct 31, 2024
139efb8
Update `AcreBitcoinProvider` docs
r-czajkowski Oct 31, 2024
f3f4d9a
Update import in `redeemer-proxy` file
r-czajkowski Oct 31, 2024
8350245
Update `mock-orangekit` file
r-czajkowski Oct 31, 2024
7ff32cb
Update `OrangeKitTbtcRedeemerProxy` unit tests
r-czajkowski Oct 31, 2024
893e3de
Update docs for `AcreLedgerLiveBitcoinProvider`
r-czajkowski Oct 31, 2024
aadf666
Merge branch 'main' into ledger-live-updates
r-czajkowski Oct 31, 2024
1f5044a
Merge branch 'ledger-live-updates' into ledger-live-new-api-updates
r-czajkowski Oct 31, 2024
4a7ac74
Update `AcreBitcoinProvider` docs
r-czajkowski Oct 31, 2024
2164f13
Rename type
r-czajkowski Oct 31, 2024
6cde85b
Fix typos in `AcreLedgerLiveBitcoinProvider` docs
r-czajkowski Oct 31, 2024
5de537c
Update the `connect` function
r-czajkowski Oct 31, 2024
5540871
Ledger Live new API updates (#780)
nkuba Oct 31, 2024
be9fa83
Format the docs in AcreBitcoinProvider
r-czajkowski Oct 31, 2024
a1bb763
Update Ledger Live testnet manifest
r-czajkowski Oct 31, 2024
3657727
Display gate modal only for standalone dapp
r-czajkowski Oct 31, 2024
b473827
Merge branch 'ledger-live-updates' into ledger-live-fix-connection-er…
r-czajkowski Oct 31, 2024
8adb0a0
Ledger Live fix connection errors (#797)
nkuba Nov 4, 2024
0822904
Update `BeehiveCard` tooltip
kpyszkowski Nov 4, 2024
b153fb5
Add `AcrePointsCard` tooltip
kpyszkowski Nov 4, 2024
5b24de4
Add conditional `AcrePointsCard` tooltip
kpyszkowski Nov 4, 2024
de3a485
Implement `CurrencyBalance` tooltip
kpyszkowski Nov 4, 2024
30d44b4
Remove unused variables and imports
kpyszkowski Nov 4, 2024
804c095
Remove unused import
kpyszkowski Nov 4, 2024
2667807
Improve gate modal
r-czajkowski Nov 4, 2024
1d75fc9
Update `ConnectWalletModalBase` component
r-czajkowski Nov 4, 2024
3a405d9
Bump `@ledgerhq/wallet-api-acre-module` dependency
r-czajkowski Nov 5, 2024
98e7003
Merge branch 'main' into ledger-live-updates
r-czajkowski Nov 5, 2024
0d137f1
Update `AcreLedgerLiveBitcoinProvider`
r-czajkowski Nov 5, 2024
aeb1cf4
Update copy
r-czajkowski Nov 5, 2024
1f9ca68
Remove unnused variable
r-czajkowski Nov 5, 2024
6e293bd
Update `AcrePointsCard` tooltip
kpyszkowski Nov 5, 2024
8d531a6
Add TODO comment
kpyszkowski Nov 5, 2024
ccf0521
Use existing boolean
kpyszkowski Nov 5, 2024
0fe9988
Fix tooltip precision bug
kpyszkowski Nov 5, 2024
c047222
Update `zIndex` value for sidebar
r-czajkowski Nov 6, 2024
8b364a0
Update `tryRequest` fn in custom bitcoin provider
r-czajkowski Nov 6, 2024
b7804f2
Rename const value
r-czajkowski Nov 6, 2024
a2599fa
Update Ledger Live manifests
r-czajkowski Nov 6, 2024
eab2c8e
Merge branch 'main' into ledger-live-updates
r-czajkowski Nov 6, 2024
9d13616
Refactor tooltip balance value
kpyszkowski Nov 6, 2024
3ce27f4
Revert mock activities
kpyszkowski Nov 6, 2024
eab5455
Revert "Revert mock activities"
kpyszkowski Nov 6, 2024
5f45ead
Revert mock activities
kpyszkowski Nov 6, 2024
51e1772
Save the bitcoin address in the redux store
r-czajkowski Nov 6, 2024
49c77ea
Update Ledger manifest configs
r-czajkowski Nov 6, 2024
7a8935b
Remove unnecessary commented code
r-czajkowski Nov 6, 2024
5ddc866
Update `getBalance` conditions
kpyszkowski Nov 6, 2024
408415c
dApp: Tooltip updates (#825)
kkosiorowska Nov 6, 2024
5f0d436
Merge branch 'main' into ledger-live-updates
r-czajkowski Nov 6, 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
5 changes: 5 additions & 0 deletions dapp/config/development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "acre-dev",
"name": "Acre [dev]",
"url": "http://localhost:5173/"
}
5 changes: 5 additions & 0 deletions dapp/config/mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "acre",
"name": "Acre",
"url": "https://bitcoin.acre.fi/"
}
5 changes: 5 additions & 0 deletions dapp/config/testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "acre-testnet",
"name": "Acre [testnet]",
"url": "https://bitcoin.test.acre.fi/"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "acre-dev",
"name": "Acre [dev]",
"url": "http://localhost:5173/",
"homepageUrl": "http://localhost:5173/",
"url": "http://localhost:5173/?embed=ledger-live",
"homepageUrl": "https:/acre.fi/",
"icon": "http://localhost:5173/acre.svg",
"platforms": "desktop",
"apiVersion": "^2.0.0",
Expand All @@ -21,10 +21,10 @@
"permissions": [
"account.request",
"account.list",
"message.sign",
"transaction.sign",
"transaction.signAndBroadcast",
"bitcoin.getXPub"
"bitcoin.getAddress",
"bitcoin.getPublicKey",
"custom.acre.messageSign",
"custom.acre.transactionSignAndBroadcast"
],
"domains": ["http://*"],
"type": "walletApp"
Expand Down
31 changes: 31 additions & 0 deletions dapp/manifests/ledger-live/ledger-live-manifest-mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "acre",
"name": "Acre",
"url": "https://bitcoin.acre.fi/?embed=ledger-live",
"homepageUrl": "https:/acre.fi/",
"icon": "https://bitcoin.acre.fi/acre.svg",
"platforms": "desktop",
"apiVersion": "^2.0.0",
"manifestVersion": "2",
"branch": "stable",
"categories": ["staking"],
"currencies": ["bitcoin", "bitcoin_testnet"],
"content": {
"shortDescription": {
"en": "Bitcoin Liquid Staking"
},
"description": {
"en": "Bitcoin Liquid Staking"
}
},
"permissions": [
"account.request",
"account.list",
"bitcoin.getAddress",
"bitcoin.getPublicKey",
"custom.acre.messageSign",
"custom.acre.transactionSignAndBroadcast"
],
"domains": ["http://*"],
"type": "walletApp"
}
31 changes: 31 additions & 0 deletions dapp/manifests/ledger-live/ledger-live-manifest-testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "acre-testnet",
"name": "Acre [testnet]",
"url": "https://bitcoin.test.acre.fi/?embed=ledger-live",
"homepageUrl": "https:/acre.fi/",
"icon": "https://bitcoin.test.acre.fi/acre.svg",
"platforms": "desktop",
"apiVersion": "^2.0.0",
"manifestVersion": "2",
"branch": "stable",
"categories": ["staking"],
"currencies": ["bitcoin", "bitcoin_testnet"],
"content": {
"shortDescription": {
"en": "Bitcoin Liquid Staking"
},
"description": {
"en": "Bitcoin Liquid Staking"
}
},
"permissions": [
"account.request",
"account.list",
"bitcoin.getAddress",
"bitcoin.getPublicKey",
"custom.acre.messageSign",
"custom.acre.transactionSignAndBroadcast"
],
"domains": ["http://*"],
"type": "walletApp"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "acre-test",
"name": "Acre [test]",
"url": "https://dapp.test.acre.fi/",
"id": "{{id}}",
"name": "{{name}}",
"url": "{{{url}}}?embed=ledger-live",
"homepageUrl": "https:/acre.fi/",
"icon": "https://dapp.test.acre.fi/acre.svg",
"icon": "{{{url}}}acre.svg",
"platforms": "desktop",
"apiVersion": "^2.0.0",
"manifestVersion": "2",
Expand All @@ -21,10 +21,10 @@
"permissions": [
"account.request",
"account.list",
"message.sign",
"transaction.sign",
"transaction.signAndBroadcast",
"bitcoin.getXPub"
"bitcoin.getAddress",
"bitcoin.getPublicKey",
"custom.acre.messageSign",
"custom.acre.transactionSignAndBroadcast"
],
"domains": ["http://*"],
"type": "walletApp"
Expand Down
9 changes: 7 additions & 2 deletions dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
"lint:js:fix": "eslint . --fix",
"lint:config": "prettier -c '**/*.@(json|yaml|toml)'",
"lint:config:fix": "prettier -w '**/*.@(json|yaml|toml)'",
"test": "vitest"
"test": "vitest --reporter=verbose",
"generate:manifests": "for env in development testnet mainnet; do mustache config/$env.json ./manifests/ledger-live/ledger-manifest-template.json > ./manifests/ledger-live/ledger-live-manifest-$env.json; done"
},
"dependencies": {
"@acre-btc/sdk": "workspace:*",
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@orangekit/react": "1.0.0-beta.32",
"@ledgerhq/wallet-api-acre-module": "0.1.0",
"@ledgerhq/wallet-api-client": "1.6.0",
"@orangekit/react": "1.0.0-beta.33",
"@orangekit/sign-in-with-wallet": "1.0.0-beta.6",
"@reduxjs/toolkit": "^2.2.0",
"@rehooks/local-storage": "^2.4.5",
Expand All @@ -31,9 +34,11 @@
"@tanstack/react-query": "^5.40.1",
"@tanstack/react-query-devtools": "^5.49.2",
"axios": "^1.6.7",
"bignumber.js": "^9.1.2",
"ethers": "^6.10.0",
"formik": "^2.4.5",
"framer-motion": "^10.16.5",
"mustache": "^4.2.0",
"react": "^18.2.0",
"react-confetti-explosion": "^2.1.2",
"react-dom": "^18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions dapp/src/acre-react/contexts/AcreSdkContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useCallback, useMemo, useState } from "react"
import { Acre } from "@acre-btc/sdk"
import { BitcoinProvider } from "@acre-btc/sdk/dist/src/lib/bitcoin/providers"
import { Acre, AcreBitcoinProvider } from "@acre-btc/sdk"
import { BITCOIN_NETWORK, env } from "#/constants"

const { TBTC_API_ENDPOINT, SUBGRAPH_API_KEY } = env
Expand All @@ -9,7 +8,7 @@ const GELATO_API_KEY = env.GELATO_RELAY_API_KEY

type AcreSdkContextValue = {
acre?: Acre
init: (bitcoinProvider?: BitcoinProvider) => Promise<void>
init: (bitcoinProvider?: AcreBitcoinProvider) => Promise<void>
isInitialized: boolean
isConnected: boolean
}
Expand All @@ -27,7 +26,7 @@ export function AcreSdkProvider({ children }: { children: React.ReactNode }) {
const [isConnected, setIsConnected] = useState(false)

const init = useCallback<AcreSdkContextValue["init"]>(
async (bitcoinProvider?: BitcoinProvider) => {
async (bitcoinProvider?: AcreBitcoinProvider) => {
let sdk = await Acre.initialize(
BITCOIN_NETWORK,
TBTC_API_ENDPOINT,
Expand All @@ -37,6 +36,7 @@ export function AcreSdkProvider({ children }: { children: React.ReactNode }) {
)

if (bitcoinProvider) {
setIsConnected(false)
sdk = await sdk.connect(bitcoinProvider)
setIsConnected(true)
} else {
Expand Down
39 changes: 29 additions & 10 deletions dapp/src/components/ConnectWalletModal/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useCallback, useState } from "react"
import React, { useCallback, useEffect, useRef, useState } from "react"
import { CONNECTION_ERRORS, ONE_SEC_IN_MILLISECONDS } from "#/constants"
import {
useAppDispatch,
useIsEmbed,
useModal,
useSignMessageAndCreateSession,
useWallet,
Expand Down Expand Up @@ -34,6 +35,7 @@ type ConnectWalletButtonProps = {
isSelected: boolean
connector: OrangeKitConnector & { isDisabled: boolean }
onSuccess?: OnSuccessCallback
isReconnecting?: boolean
}

const iconStyles: Record<string, ImageProps> = {
Expand All @@ -53,7 +55,9 @@ export default function ConnectWalletButton({
isSelected,
connector,
onSuccess,
isReconnecting,
}: ConnectWalletButtonProps) {
const { isEmbed } = useIsEmbed()
const {
address,
onConnect,
Expand All @@ -66,13 +70,14 @@ export default function ConnectWalletButton({
useWalletConnectionError()
const { closeModal } = useModal()
const dispatch = useAppDispatch()
const isMounted = useRef(false)

const [isLoading, setIsLoading] = useState<boolean>(false)

const hasConnectionError = connectionError || connectionStatus === "error"
const hasSignMessageStatus = signMessageStatus === "error"
const showStatuses = isSelected && !hasConnectionError
const showRetryButton = address && hasSignMessageStatus
const hasSignMessageErrorStatus = signMessageStatus === "error"
const shouldShowStatuses = isSelected && !hasConnectionError
const shouldShowRetryButton = address && hasSignMessageErrorStatus

const onSuccessSignMessage = useCallback(() => {
closeModal()
Expand Down Expand Up @@ -118,6 +123,7 @@ export default function ConnectWalletButton({

const handleConnection = useCallback(() => {
onConnect(connector, {
isReconnecting,
onSuccess: () => {
logPromiseFailure(onSuccessConnection(connector))
},
Expand All @@ -126,7 +132,13 @@ export default function ConnectWalletButton({
setConnectionError(errorData)
},
})
}, [onConnect, connector, onSuccessConnection, setConnectionError])
}, [
onConnect,
connector,
onSuccessConnection,
setConnectionError,
isReconnecting,
])

const handleRedirectUser = useCallback(() => {
setIsLoading(true)
Expand All @@ -144,9 +156,9 @@ export default function ConnectWalletButton({

const handleButtonClick = () => {
// Do not trigger action again when wallet connection is in progress
if (showStatuses) return
if (shouldShowStatuses) return

onDisconnect()
if (!isReconnecting) onDisconnect()
resetConnectionError()
resetMessageStatus()

Expand All @@ -161,6 +173,13 @@ export default function ConnectWalletButton({
handleConnection()
}

useEffect(() => {
if (!isMounted.current && isEmbed && isSelected) {
isMounted.current = true
handleConnection()
}
}, [handleConnection, isEmbed, isSelected])

return (
<Card
key={connector.id}
Expand Down Expand Up @@ -206,7 +225,7 @@ export default function ConnectWalletButton({
</CardHeader>

<AnimatePresence initial={false}>
{showStatuses && (
{shouldShowStatuses && (
<CardBody
as={motion.div}
variants={collapseVariants}
Expand All @@ -231,13 +250,13 @@ export default function ConnectWalletButton({
</TextMd>
<ConnectWalletStatusLabel
status={connectionStatus}
label="Connect wallet"
label={`Connect ${isEmbed ? "account" : "wallet"}`}
/>
<ConnectWalletStatusLabel
status={signMessageStatus}
label="Sign message"
/>
{showRetryButton && (
{shouldShowRetryButton && (
<Button
mt={4}
size="lg"
Expand Down
34 changes: 30 additions & 4 deletions dapp/src/components/ConnectWalletModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { useState } from "react"
import React, { useEffect, useState } from "react"
import { ModalBody, ModalHeader, ModalCloseButton } from "@chakra-ui/react"
import { useConnectors, useWalletConnectionError } from "#/hooks"
import {
useConnectors,
useIsEmbed,
useIsSignedMessage,
useWallet,
useWalletConnectionError,
} from "#/hooks"
import { OrangeKitConnector, BaseModalProps, OnSuccessCallback } from "#/types"
import { wallets } from "#/constants"
import withBaseModal from "../ModalRoot/withBaseModal"
Expand All @@ -10,9 +16,13 @@ import ConnectWalletErrorAlert from "./ConnectWalletErrorAlert"
export function ConnectWalletModalBase({
onSuccess,
withCloseButton = true,
isReconnecting,
}: {
onSuccess?: OnSuccessCallback
isReconnecting?: boolean
} & BaseModalProps) {
const { isEmbed } = useIsEmbed()
const { onDisconnect } = useWallet()
const connectors = useConnectors()
const enabledConnectors = connectors.map((connector) => ({
...connector,
Expand All @@ -21,17 +31,32 @@ export function ConnectWalletModalBase({

const [selectedConnectorId, setSelectedConnectorId] = useState<string>()
const { connectionError, resetConnectionError } = useWalletConnectionError()
const isSignedMessage = useIsSignedMessage()

const handleButtonOnClick = (connector: OrangeKitConnector) => {
setSelectedConnectorId(connector.id)
}

useEffect(() => {
if (!isEmbed) return

setSelectedConnectorId(enabledConnectors[0].id)
}, [enabledConnectors, isEmbed])

return (
<>
{withCloseButton && (
<ModalCloseButton onClick={() => resetConnectionError()} />
<ModalCloseButton
onClick={() => {
resetConnectionError()

if (!isSignedMessage) {
onDisconnect()
}
}}
/>
)}
<ModalHeader>Select your wallet</ModalHeader>
<ModalHeader>{`Select your ${isEmbed ? "account" : "wallet"}`}</ModalHeader>

<ModalBody gap={0}>
<ConnectWalletErrorAlert {...connectionError} />
Expand All @@ -44,6 +69,7 @@ export function ConnectWalletModalBase({
onClick={() => handleButtonOnClick(connector)}
isSelected={selectedConnectorId === connector.id}
onSuccess={onSuccess}
isReconnecting={isReconnecting}
/>
))}
</ModalBody>
Expand Down
Loading
Loading