-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show user balance of EXT token and update the user balance after mint…
… (#95) * soroban-cli command is just 'soroban' * Add npm install instructions * not use optimizing builds * use SorobanContext name following web3-react standard * Revert "not use optimizing builds" This reverts commit 840e69aa2d95b4381b9bade1e05b7ad02799b78d. * fix: use SorobanContext * use soroban-react folder * change WalletProvider to SorobanReactProvider inside soroban-react folder * use useSorobanReact() instead of React.useContext(SorobanContext) * use ProviderExample in _app.tsx * move Wallet.tsx to types * use connector instead of wallet * React.Node type for children * delete components/WalletProvider.tsx as using soroban-react/SorobanReactProvider.tsx * use getDefaultConnectors instead of getDefaultWallets * realtime react for wallet address or network changes * use @soroban-react library * use @soroban-react/core v1.02 * use @soroban-react/core v1.0.2 * Delete yarn.lock Trying to only have package-lock.json with npm for simplicity of the example repo. * Update wallet/hooks/useNetwork.tsx * handle error when wallets are not funded * feat(user-balance): Add user's token balance section * feat(user-balance): reconects, and hence upload balance after mint transactions * Use early return when not having balance in wallet * Fix an import * Fixing a bunch of typos and compilation errors --------- Co-authored-by: Paul Bellamy <[email protected]> Co-authored-by: Paul Bellamy <[email protected]>
- Loading branch information
1 parent
ff0e4d2
commit 87e2bbe
Showing
10 changed files
with
361 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
|
||
export interface WalletChain { | ||
id: string; | ||
name?: string; | ||
networkPassphrase: string; | ||
iconBackground?: string; | ||
iconUrl?: string | null; | ||
// TODO: Use this to indicate which chains a dapp supports | ||
unsupported?: boolean; | ||
}; | ||
|
||
export const WalletChainContext = React.createContext<WalletChain[]>([]); | ||
|
||
export const useWalletChains = () => React.useContext(WalletChainContext); | ||
|
||
export const useWalletChainsById = () => { | ||
const walletChains = useWalletChains(); | ||
|
||
return React.useMemo(() => { | ||
const walletChainsById: Record<string, WalletChain> = {}; | ||
|
||
walletChains.forEach(rkChain => { | ||
walletChainsById[rkChain.id] = rkChain; | ||
}); | ||
|
||
return walletChainsById; | ||
}, [walletChains]); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | ||
import freighterApi from "@stellar/freighter-api"; | ||
import { WalletChain } from '../../WalletChainContext'; | ||
import { NetworkDetails, Connector } from '../../types'; | ||
|
||
export interface FreighterOptions { | ||
appName?: string; | ||
chains: WalletChain[]; | ||
} | ||
|
||
export function freighter(_: FreighterOptions): Connector { | ||
return { | ||
id: 'freighter', | ||
name: 'Freighter', | ||
iconUrl: async () => '', | ||
// iconUrl: async () => (await import('./freighter.svg')).default, | ||
iconBackground: '#fff', | ||
// TODO: Check this | ||
installed: true, | ||
downloadUrls: { | ||
browserExtension: | ||
'https://chrome.google.com/webstore/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk?hl=en', | ||
}, | ||
isConnected(): boolean { | ||
return !!freighterApi?.isConnected() | ||
}, | ||
getNetworkDetails(): Promise<NetworkDetails> { | ||
return freighterApi.getNetworkDetails() | ||
}, | ||
getPublicKey(): Promise<string> { | ||
return freighterApi.getPublicKey() | ||
}, | ||
signTransaction(xdr: string, opts?: { network?: string; networkPassphrase?: string; accountToSign?: string }): Promise<string> { | ||
return freighterApi.signTransaction(xdr, opts) | ||
}, | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./freighter"; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { WalletChain } from './WalletChainContext'; | ||
import { ConnectorList } from './types'; | ||
import { freighter } from './connectors'; | ||
|
||
export const getDefaultConnectors = ( | ||
{appName,chains,}: {appName: string; chains: WalletChain[];}) | ||
: { | ||
|
||
connectors: ConnectorList;} => { | ||
const connectors: ConnectorList = [ | ||
{ | ||
groupName: 'Popular', | ||
connectors: [ | ||
freighter({ appName, chains }), | ||
], | ||
}, | ||
]; | ||
|
||
return { | ||
connectors, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, {createContext} from "react"; | ||
import * as SorobanClient from "soroban-client"; | ||
import { ChainMetadata } from "@soroban-react/types"; | ||
import { Connector, ConnectorList } from "../types"; | ||
|
||
export const defaultSorobanContext: SorobanContextType = { | ||
appName: undefined, | ||
chains: [], | ||
connectors: [], | ||
server: new SorobanClient.Server("https://soroban-rpc.stellar.org"), | ||
async connect() {}, | ||
async disconnect() {}, | ||
}; | ||
|
||
export interface SorobanContextType { | ||
autoconnect?: boolean; | ||
appName?: string; | ||
chains: ChainMetadata[]; | ||
connectors: ConnectorList; | ||
activeChain?: ChainMetadata; | ||
address?: string; | ||
activeWallet?: Connector; | ||
server?: SorobanClient.Server; | ||
connect: () => Promise<void>; | ||
disconnect: () => Promise<void>; | ||
} | ||
|
||
export const SorobanContext = createContext<SorobanContextType | undefined>(undefined) |
Oops, something went wrong.