-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet-data): everything commented
- Loading branch information
Showing
4 changed files
with
118 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
import { ConnectButton } from '@soroban-react/connect-button' | ||
import { SorobanContextType } from '@soroban-react/core' | ||
import React from 'react' | ||
|
||
import { useNetwork } from './useNetwork' | ||
|
||
export interface WalletDataProps { | ||
sorobanContext: SorobanContextType | ||
} | ||
|
||
// TODO: Eliminate flash of unconnected content on loading | ||
export function WalletData({ sorobanContext }: WalletDataProps) { | ||
const useAccount = () => { | ||
const { address } = sorobanContext | ||
|
||
if (!address) { | ||
return {} | ||
} | ||
|
||
return { | ||
data: { | ||
address, | ||
displayName: `${address.slice(0, 4)}...${address.slice(-4)}`, | ||
}, | ||
} | ||
} | ||
|
||
const { data: account } = useAccount() | ||
|
||
const { activeChain: chain, chains } = useNetwork(sorobanContext) | ||
|
||
const unsupportedChain = chain?.unsupported | ||
|
||
const styleDisplayData: any = { display: 'flex' } | ||
|
||
return ( | ||
<> | ||
{account ? ( | ||
<div className={styleDisplayData}> | ||
{chain && (chains.length > 1 || unsupportedChain) && ( | ||
<div> | ||
{chain.iconUrl} | ||
{chain.name ?? chain.id} | ||
</div> | ||
)} | ||
<div>{account.displayName}</div> | ||
</div> | ||
) : ( | ||
<ConnectButton label="Connect Wallet" sorobanContext={sorobanContext} /> | ||
)} | ||
</> | ||
) | ||
} | ||
// import { ConnectButton } from '@soroban-react/connect-button' | ||
// import { SorobanContextType } from '@soroban-react/core' | ||
// import React from 'react' | ||
|
||
// import { useNetwork } from './useNetwork' | ||
|
||
// export interface WalletDataProps { | ||
// sorobanContext: SorobanContextType | ||
// } | ||
|
||
// // TODO: Eliminate flash of unconnected content on loading | ||
// export function WalletData({ sorobanContext }: WalletDataProps) { | ||
// const useAccount = () => { | ||
// const { address } = sorobanContext | ||
|
||
// if (!address) { | ||
// return {} | ||
// } | ||
|
||
// return { | ||
// data: { | ||
// address, | ||
// displayName: `${address.slice(0, 4)}...${address.slice(-4)}`, | ||
// }, | ||
// } | ||
// } | ||
|
||
// const { data: account } = useAccount() | ||
|
||
// const { activeChain: chain, chains } = useNetwork(sorobanContext) | ||
|
||
// const unsupportedChain = chain?.unsupported | ||
|
||
// const styleDisplayData: any = { display: 'flex' } | ||
|
||
// return ( | ||
// <> | ||
// {account ? ( | ||
// <div className={styleDisplayData}> | ||
// {chain && (chains.length > 1 || unsupportedChain) && ( | ||
// <div> | ||
// {chain.iconUrl} | ||
// {chain.name ?? chain.id} | ||
// </div> | ||
// )} | ||
// <div>{account.displayName}</div> | ||
// </div> | ||
// ) : ( | ||
// <ConnectButton label="Connect Wallet" sorobanContext={sorobanContext} /> | ||
// )} | ||
// </> | ||
// ) | ||
// } |
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,41 +1,41 @@ | ||
import type { WalletChain, ChainName } from '@soroban-react/types' | ||
// import type { WalletChain, ChainName } from '@soroban-react/types' | ||
|
||
// Sourced from https://github.com/tmm/wagmi/blob/main/packages/core/src/constants/chains.ts | ||
// This is just so we can clearly see which of wagmi's first-class chains we provide metadata for | ||
export const WalletChainByName: Record<ChainName, WalletChain> = { | ||
public: { | ||
id: 'public', | ||
name: 'Public', | ||
networkPassphrase: 'Public Global Stellar Network ; September 2015', | ||
iconBackground: '#e84141', | ||
// iconUrl: async () => (await import('./chainIcons/public.svg')).default, | ||
}, | ||
testnet: { | ||
id: 'testnet', | ||
name: 'Testnet', | ||
networkPassphrase: 'Test SDF Network ; September 2015', | ||
iconBackground: '#484c50', | ||
// iconUrl: async () => (await import('./chainIcons/testnet.svg')).default, | ||
}, | ||
futurenet: { | ||
id: 'futurenet', | ||
name: 'Futurenet', | ||
networkPassphrase: 'Test SDF Future Network ; October 2022', | ||
iconBackground: '#96bedc', | ||
// iconUrl: async () => (await import('./chainIcons/futurenet.svg')).default, | ||
}, | ||
sandbox: { | ||
id: 'sandbox', | ||
name: 'Sandbox', | ||
networkPassphrase: 'Local Sandbox Stellar Network ; September 2022', | ||
iconBackground: '#dac695', | ||
// iconUrl: async () => (await import('./chainIcons/futurenet.svg')).default, | ||
}, | ||
standalone: { | ||
id: 'standalone', | ||
name: 'Standalone', | ||
networkPassphrase: 'Standalone Network ; February 2017', | ||
iconBackground: '#dac695', | ||
// iconUrl: async () => (await import('./chainIcons/futurenet.svg')).default, | ||
}, | ||
} | ||
// // Sourced from https://github.com/tmm/wagmi/blob/main/packages/core/src/constants/chains.ts | ||
// // This is just so we can clearly see which of wagmi's first-class chains we provide metadata for | ||
// export const WalletChainByName: Record<ChainName, WalletChain> = { | ||
// public: { | ||
// id: 'public', | ||
// name: 'Public', | ||
// networkPassphrase: 'Public Global Stellar Network ; September 2015', | ||
// iconBackground: '#e84141', | ||
// // iconUrl: async () => (await import('./chainIcons/public.svg')).default, | ||
// }, | ||
// testnet: { | ||
// id: 'testnet', | ||
// name: 'Testnet', | ||
// networkPassphrase: 'Test SDF Network ; September 2015', | ||
// iconBackground: '#484c50', | ||
// // iconUrl: async () => (await import('./chainIcons/testnet.svg')).default, | ||
// }, | ||
// futurenet: { | ||
// id: 'futurenet', | ||
// name: 'Futurenet', | ||
// networkPassphrase: 'Test SDF Future Network ; October 2022', | ||
// iconBackground: '#96bedc', | ||
// // iconUrl: async () => (await import('./chainIcons/futurenet.svg')).default, | ||
// }, | ||
// sandbox: { | ||
// id: 'sandbox', | ||
// name: 'Sandbox', | ||
// networkPassphrase: 'Local Sandbox Stellar Network ; September 2022', | ||
// iconBackground: '#dac695', | ||
// // iconUrl: async () => (await import('./chainIcons/futurenet.svg')).default, | ||
// }, | ||
// standalone: { | ||
// id: 'standalone', | ||
// name: 'Standalone', | ||
// networkPassphrase: 'Standalone Network ; February 2017', | ||
// iconBackground: '#dac695', | ||
// // iconUrl: async () => (await import('./chainIcons/futurenet.svg')).default, | ||
// }, | ||
// } |
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,8 +1,8 @@ | ||
import React from 'react' | ||
// import React from 'react' | ||
|
||
export function useIsMounted() { | ||
const reducer = () => true | ||
const [mounted, setMounted] = React.useReducer(reducer, false) | ||
React.useEffect(setMounted, [setMounted]) | ||
return mounted | ||
} | ||
// export function useIsMounted() { | ||
// const reducer = () => true | ||
// const [mounted, setMounted] = React.useReducer(reducer, false) | ||
// React.useEffect(setMounted, [setMounted]) | ||
// return mounted | ||
// } |
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,22 +1,22 @@ | ||
import { SorobanContextType } from '@soroban-react/core' | ||
import { WalletChain } from '@soroban-react/types' | ||
import React from 'react' | ||
// import { SorobanContextType } from '@soroban-react/core' | ||
// import { WalletChain } from '@soroban-react/types' | ||
// import React from 'react' | ||
|
||
import * as SorobanClient from 'soroban-client' | ||
// import * as SorobanClient from 'soroban-client' | ||
|
||
import { WalletChainByName } from './provideWalletChains' | ||
// import { WalletChainByName } from './provideWalletChains' | ||
|
||
export type NetworkConfig = { | ||
activeChain?: WalletChain | ||
server?: SorobanClient.Server | ||
chains: Array<WalletChain> | ||
} | ||
// export type NetworkConfig = { | ||
// activeChain?: WalletChain | ||
// server?: SorobanClient.Server | ||
// chains: Array<WalletChain> | ||
// } | ||
|
||
export function useNetwork(sorobanContext: SorobanContextType): NetworkConfig { | ||
const { activeChain, server } = sorobanContext | ||
return { | ||
activeChain, | ||
server, | ||
chains: Object.values(WalletChainByName), | ||
} | ||
} | ||
// export function useNetwork(sorobanContext: SorobanContextType): NetworkConfig { | ||
// const { activeChain, server } = sorobanContext | ||
// return { | ||
// activeChain, | ||
// server, | ||
// chains: Object.values(WalletChainByName), | ||
// } | ||
// } |
1920eef
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.
@chopan123 What's the point of commenting everything? Do we want to remove this package eventually? For now the comments are making the code break when there were imports of the module (e.g Multichain Dapp)