Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default defineConfig({
runMode: 9, // Retries failing tests 2 times in CI mode
openMode: 0 // No retries in interactive mode
},
viewportHeight: 768,
viewportWidth: 1366,
},
component: {
devServer: {
Expand Down
48 changes: 22 additions & 26 deletions cypress/e2e/connectWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,35 @@ describe('Connect Wallet', () => {
getPublicKey: () =>
Promise.resolve('GCHR5WWPDFF3U3HP2NA6TI6FCQPYEWS3UOPIPJKZLAAFM57CEG4ZYBWP'),
signTransaction: () => Promise.resolve('signedTransaction'),
connect: () => console.log("GG"),
getAddress: () => console.log("GG"),
requestAccess: () => console.log("GG")
// Add other methods as needed
};

// Create a spy on console.log
cy.spy(win.console, 'log').as('consoleLog');
},
});
cy.get('[data-testid="primary-button"]').click();
cy.contains('Detected');
cy.contains('Freighter Wallet').click();
cy.get('@consoleLog').should('have.been.calledWithMatch', 'wallet');
cy.get('@consoleLog').should('have.been.calledWithMatch', 'Changing connector to ');

// Click the wallet button to open the modal
cy.get('[data-testid="wallet-button"]').click();

// Get the shadow root of the stellar-wallets-modal
cy.get('stellar-wallets-modal')
.shadow()
.find('dialog.dialog-modal')
.should('be.visible');

// Get the window object
cy.window().then((win: any) => {
// Get the spy from the window object
const consoleLog = win.console.log;
var logs = [];
for (let i = 0; i < consoleLog.callCount; i++) {
// Get the i-th call to the spy
const call = consoleLog.getCall(i);

// Get the arguments of the call
const callArgs = call.args;

// Log the arguments using cy.log()
cy.log(`Call ${i} args: ${JSON.stringify(callArgs)}`);
console.log(`Call ${i} args: ${JSON.stringify(callArgs)}`);
logs.push(`Call ${i} args: ${JSON.stringify(callArgs)}`);
}
//write logs to a file on cypress/logs/logs.txt
cy.writeFile('cypress/logs/logs.txt', logs.join('\n'));
});
// cy.contains('Public Key: publicKey')
// Find and click the Freighter wallet option inside the shadow DOM
cy.get('stellar-wallets-modal')
.shadow()
.find('.wallets-body__item')
.contains('Freighter')
.should('be.visible')
.click();

// // Verify the console logs
// cy.get('@consoleLog').should('have.been.calledWithMatch', 'wallet');
});
});
39 changes: 19 additions & 20 deletions src/components/Buttons/WalletButton.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { AppContext } from 'contexts';
import { useSorobanReact } from "stellar-react";
import React, { useContext } from 'react';
import { useSorobanReact } from 'stellar-react';
import React, { useContext, useEffect } from 'react';
import { ButtonLight, ButtonPrimary } from './Button';

export function WalletButton({ style, light }: { style?: React.CSSProperties; light?: boolean }) {
const { address, disconnect, connect } = useSorobanReact();

export function WalletButton({ style, light }: { style?: React.CSSProperties; light?: boolean}) {
const { address, disconnect, connect } = useSorobanReact();

const ButtonComponent = light ? ButtonLight : ButtonPrimary;
const handleClick = () => {
if (address) {
disconnect();
} else {
connect();
}
};
return (
<>
<ButtonComponent style={style} onClick={handleClick}>
Connect Wallet
</ButtonComponent>
</>
);
const ButtonComponent = light ? ButtonLight : ButtonPrimary;
const handleClick = () => {
if (address) {
disconnect();
} else {
connect();
}
};
return (
<>
<ButtonComponent data-testid="wallet-button" style={style} onClick={handleClick}>
Connect Wallet
</ButtonComponent>
</>
);
}
18 changes: 12 additions & 6 deletions src/components/Layout/ProfileSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,17 @@ export const ActiveChainHeaderChip = ({ isMobile }: { isMobile?: boolean }) => {
const activeChainName = passphraseToBackendNetworkName[activeChain!].toLowerCase();
const [chainName, setChainName] = React.useState(activeChainName);
useEffect(() => {
const formattedActiveChainName = activeChainName.charAt(0).toUpperCase() + activeChainName.slice(1);
const formattedActiveChainName =
activeChainName.charAt(0).toUpperCase() + activeChainName.slice(1);
setChainName(formattedActiveChainName);
}, [activeChain]);

return (
<>
{activeChain && address ? (
<HeaderChip
label={chainName}
isSmall={isMobile}
/>
<HeaderChip label={chainName} isSmall={isMobile} />
) : (
<HeaderChip label={chainName} isSmall={isMobile} />
<HeaderChip label={chainName} isSmall={isMobile} />
)}
</>
);
Expand All @@ -219,6 +217,14 @@ export default function ProfileSection() {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(1220));

useEffect(() => {
if (sorobanContext.address) {
console.log('wallet:', sorobanContext.address);
} else {
console.log('Disconnected from wallet');
}
}, [sorobanContext.address]);

return (
<Box display="flex" gap="8px">
{!isMobile && <ActiveChainHeaderChip />}
Expand Down
Loading