Skip to content

Commit

Permalink
Clean code, remove ./wallet folder (#111)
Browse files Browse the repository at this point in the history
* use contractTransaction from @soroban-react

* remove unused useWalletChainsById and useWalletChains function

* remove unused getDefaultConnectors file

* remove unused connectors folder

* remove unused wallet/soroban-react folder

* remove unused types and provideWalletChains

* Use same version of @soroban-react packages

* remove unused WalletChainContext, isNotNullish and useNetwork hook

* Move ./wallet/hooks to ./hooks

* fix bug

* update package-lock
  • Loading branch information
esteblock committed May 22, 2023
1 parent 9697fca commit 864074f
Show file tree
Hide file tree
Showing 23 changed files with 3,890 additions and 1,128 deletions.
51 changes: 14 additions & 37 deletions components/molecules/form-pledge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { AmountInput, Button, Checkbox } from '../../atoms'
import { TransactionModal } from '../../molecules/transaction-modal'
import { Utils } from '../../../shared/utils'
import styles from './style.module.css'
import { useSendTransaction, useContractValue } from '@soroban-react/contracts'
import { useSendTransaction, useContractValue, contractTransaction } from '@soroban-react/contracts'
import { useSorobanReact } from '@soroban-react/core'
import {
useNetwork,
} from '../../../wallet'
import * as SorobanClient from 'soroban-client'
import BigNumber from 'bignumber.js'
import * as convert from '../../../convert'
Expand Down Expand Up @@ -72,7 +69,7 @@ const FormPledge: FunctionComponent<IFormPledgeProps> = props => {
const [resultSubmit, setResultSubmit] = useState<IResultSubmit | undefined>()
const [input, setInput] = useState('')
const [isSubmitting, setSubmitting] = useState(false)
const { server } = useNetwork()
const { server } = sorobanContext

const parsedAmount = BigNumber(amount || 0)

Expand Down Expand Up @@ -100,17 +97,15 @@ const FormPledge: FunctionComponent<IFormPledgeProps> = props => {

try {
// Deposit the tokens
let result = await sendTransaction(
contractTransaction(
props.networkPassphrase,
source,
props.crowdfundId,
'deposit',
new SorobanClient.Address(props.account).toScVal(),
amountScVal
),
{sorobanContext}
)
let tx = contractTransaction({
source,
networkPassphrase: props.networkPassphrase,
contractId: props.crowdfundId,
method: 'deposit',
params: [new SorobanClient.Address(props.account).toScVal(), amountScVal]
})
let result = await sendTransaction(tx, {sorobanContext})

setResultSubmit({
status: 'success',
scVal: result,
Expand All @@ -133,25 +128,6 @@ const FormPledge: FunctionComponent<IFormPledgeProps> = props => {
}
}

// Small helper to build a contract invokation transaction
function contractTransaction(
networkPassphrase: string,
source: SorobanClient.Account,
contractId: string,
method: string,
...params: SorobanClient.xdr.ScVal[]
): SorobanClient.Transaction {
const contract = new SorobanClient.Contract(contractId)
return new SorobanClient.TransactionBuilder(source, {
// TODO: Figure out the fee
fee: '100',
networkPassphrase,
})
.addOperation(contract.call(method, ...params))
.setTimeout(SorobanClient.TimeoutInfinite)
.build()
}

return (
<div>
<h6>Choose Amount</h6>
Expand Down Expand Up @@ -232,8 +208,9 @@ const FormPledge: FunctionComponent<IFormPledgeProps> = props => {
symbol: string
}) {
const [isSubmitting, setSubmitting] = useState(false)
const { activeChain, server } = useNetwork()
const networkPassphrase = activeChain?.networkPassphrase ?? ''
const server = sorobanContext.server
const networkPassphrase = sorobanContext.activeChain?.networkPassphrase


const { sendTransaction } = useSendTransaction()
const amount = BigNumber(100)
Expand Down
7 changes: 4 additions & 3 deletions components/molecules/wallet-data/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { DropdownSvg } from '../../../assets/icons'
import { useAccount, useIsMounted, useNetwork } from '../../../wallet'
import { useSorobanReact } from '@soroban-react/core'
import { useAccount, useIsMounted} from '../../../hooks'
import { ConnectButton } from '../../atoms'
import styles from './style.module.css'
import Image from 'next/image'
Expand All @@ -11,7 +11,8 @@ export function WalletData() {

const { data: account } = useAccount()

const { activeChain: chain, chains } = useNetwork()
const { activeChain: chain, chains } = useSorobanReact()


const unsupportedChain = chain?.unsupported

Expand Down
10 changes: 5 additions & 5 deletions components/organisms/pledge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import styles from './style.module.css'
import { Spacer } from '../../atoms/spacer'
import { Utils } from '../../../shared/utils'
import {
useAccount,
useNetwork,
} from '../../../wallet'
useAccount
} from '../../../hooks'
import { useContractValue } from '@soroban-react/contracts'
import * as SorobanClient from 'soroban-client'
import { Deposits, FormPledge } from '../../molecules'
Expand All @@ -17,11 +16,12 @@ let xdr = SorobanClient.xdr

const Pledge: FunctionComponent = () => {
const { data: account } = useAccount()
const { activeChain } = useNetwork()
const sorobanContext = useSorobanReact()

const { activeChain } = sorobanContext

const networkPassphrase = activeChain?.networkPassphrase ?? ''

const sorobanContext = useSorobanReact()
// Call the contract rpcs to fetch values
const useLoadToken = (): any => {
return {
Expand Down
2 changes: 2 additions & 0 deletions hooks/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./useAccount";
export * from "./useIsMounted";
1 change: 0 additions & 1 deletion wallet/hooks/useAccount.tsx → hooks/useAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React, {useContext} from 'react';
import { useSorobanReact } from "@soroban-react/core";
export function useAccount() {
const {address} = useSorobanReact()
Expand Down
File renamed without changes.
Loading

0 comments on commit 864074f

Please sign in to comment.