Skip to content

Commit

Permalink
Merge branch 'main' into query-api
Browse files Browse the repository at this point in the history
  • Loading branch information
hieronx authored Feb 13, 2024
2 parents 48cfede + 1324a21 commit 137a7bc
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useTinlakeTransaction } from '../../utils/tinlake/useTinlakeTransaction
import { useAddress } from '../../utils/useAddress'
import { usePool, usePoolMetadata } from '../../utils/usePools'
import { InvestRedeemContext } from './InvestRedeemProvider'
import { InvestRedeemAction, InvestRedeemActions, InvestRedeemProviderProps as Props, InvestRedeemState } from './types'
import { InvestRedeemAction, InvestRedeemActions, InvestRedeemState, InvestRedeemProviderProps as Props } from './types'

export function InvestRedeemTinlakeProvider({ poolId, trancheId, children }: Props) {
const address = useAddress('evm')
Expand Down Expand Up @@ -123,7 +123,7 @@ export function InvestRedeemTinlakeProvider({ poolId, trancheId, children }: Pro
remainingRedeemToken: disburse?.remainingRedeemToken || Dec(0),
},
collectAmount,
collectType: disburse?.payoutCurrencyAmount.isZero() ? 'invest' : 'redeem',
collectType: !disburse?.payoutCurrencyAmount.isZero() ? 'redeem' : !disburse?.payoutTokenAmount.isZero() ? 'invest' : null,
needsToCollectBeforeOrder: !collectAmount.isZero(),
needsPoolCurrencyApproval: () => !!trancheInvestment?.poolCurrencyAllowance.isZero(),
needsTrancheTokenApproval: () => !!trancheInvestment?.tokenAllowance.isZero(),
Expand Down
16 changes: 14 additions & 2 deletions centrifuge-app/src/pages/IssuerPool/Configuration/Admins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Tooltips } from '../../../components/Tooltips'
import { usePoolPermissions, useSuitableAccounts } from '../../../utils/usePermissions'
import { AddAddressInput } from './AddAddressInput'

type AdminRole = 'PoolAdmin' | 'Borrower' | 'PricingAdmin' | 'LiquidityAdmin' | 'InvestorAdmin' | 'LoanAdmin'
type AdminRole = 'PoolAdmin' | 'Borrower' | 'PricingAdmin' | 'LiquidityAdmin' | 'InvestorAdmin' | 'LoanAdmin' | "PODReadAccess"

type Admin = {
address: string
Expand Down Expand Up @@ -186,6 +186,18 @@ export function Admins({ poolId }: { poolId: string }) {
/>
),
},
{
align: 'center',
header: "Investor access",
cell: (row: Row) => (
<Field
name={`admins.${row.index}.roles.PODReadAccess`}
as={Checkbox}
type="checkbox"
disabled={!isEditing || isLoading}
/>
),
},
{
header: '',
cell: (row: Row) =>
Expand Down Expand Up @@ -218,7 +230,7 @@ export function Admins({ poolId }: { poolId: string }) {
)
}

const roles = ['PoolAdmin', 'Borrower', 'PricingAdmin', 'LiquidityAdmin', 'InvestorAdmin', 'LoanAdmin']
const roles = ['PoolAdmin', 'Borrower', 'PricingAdmin', 'LiquidityAdmin', 'InvestorAdmin', 'LoanAdmin', 'PODReadAccess']

export function diffPermissions(storedValues: Admin[], formValues: Admin[], rolesToCheck = roles) {
const storedObj = Object.fromEntries(storedValues.map((admin) => [admin.address, admin.roles]))
Expand Down
10 changes: 5 additions & 5 deletions centrifuge-app/src/pages/Loan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ function FinanceButton({ loan }: { loan: LoanType }) {
}

function Loan() {
const { pid: poolId, aid: assetId } = useParams<{ pid: string; aid: string }>()
const { pid: poolId, aid: loanId } = useParams<{ pid: string; aid: string }>()
const isTinlakePool = poolId.startsWith('0x')
const basePath = useRouteMatch(['/pools', '/issuer'])?.path || ''
const pool = usePool(poolId)
const loan = useLoan(poolId, assetId)
const loan = useLoan(poolId, loanId)
const { data: poolMetadata, isLoading: poolMetadataIsLoading } = usePoolMetadata(pool)
const nft = useCentNFT(loan?.asset.collectionId, loan?.asset.nftId, false)
const { data: nftMetadata, isLoading: nftMetadataIsLoading } = useMetadata(nft?.metadataUri, nftMetadataSchema)
const metadataIsLoading = poolMetadataIsLoading || nftMetadataIsLoading
const address = useAddress()
const canOraclePrice = useCanSetOraclePrice(address)
const borrowerAssetTransactions = useBorrowerAssetTransactions(poolId, assetId)
const borrowerAssetTransactions = useBorrowerAssetTransactions(poolId, loanId)
const [oraclePriceShown, setOraclePriceShown] = React.useState(false)

const currentFace =
Expand All @@ -121,7 +121,7 @@ function Loan() {
)

const documentId = useNftDocumentId(nft?.collectionId, nft?.id)
const { data: document } = usePodDocument(poolId, documentId)
const { data: document } = usePodDocument(poolId, loanId, documentId)

const publicData = nftMetadata?.properties
? Object.fromEntries(Object.entries(nftMetadata.properties).map(([key, obj]: any) => [key, obj]))
Expand Down Expand Up @@ -343,7 +343,7 @@ function Loan() {
{isTinlakePool && loan && 'owner' in loan ? (
<PageSection title={<Box>NFT</Box>}>
<Shelf gap={6}>
<LabelValueStack label={<Tooltips variant="secondary" type="id" />} value={assetId} />
<LabelValueStack label={<Tooltips variant="secondary" type="id" />} value={loanId} />
<LabelValueStack
label="Owner"
value={
Expand Down
10 changes: 6 additions & 4 deletions centrifuge-app/src/utils/usePodAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { usePodUrl } from './usePools'
export function usePodAuth(poolId: string, accountOverride?: CombinedSubstrateAccount) {
const { selectedCombinedAccount } = useWallet().substrate
const podUrl = usePodUrl(poolId)
const suitableAccounts = useSuitableAccounts({ poolId, poolRole: ['Borrower'], proxyType: ['PodAuth'] }).filter(
(acc) => acc.proxies?.length === 1
const suitableAccounts = useSuitableAccounts({ poolId, poolRole: ['Borrower', 'PODReadAccess'], proxyType: ['PodAuth'] })
.filter(
(acc) => !acc.proxies || acc.proxies.length === 1
)
const account = accountOverride || selectedCombinedAccount || suitableAccounts[0]
const cent = useCentrifuge()
Expand Down Expand Up @@ -71,7 +72,7 @@ export function usePodAuth(poolId: string, accountOverride?: CombinedSubstrateAc
isLoading: isAuthing,
isSuccess: isAuthed,
} = useQuery(['podAccount', podUrl, authToken], () => cent.pod.getSelf([podUrl!, authToken]), {
enabled: !!podUrl && !!authToken,
enabled: !!podUrl && !!authToken && account?.proxies?.length === 1,
staleTime: Infinity,
retry: 1,
refetchOnWindowFocus: false,
Expand All @@ -80,9 +81,10 @@ export function usePodAuth(poolId: string, accountOverride?: CombinedSubstrateAc
return {
isSigning,
login,
account,
token: session?.signed,
payload: session?.payload,
isAuthed,
isAuthed: isAuthed || (account && account.proxies?.length !== 1),
isAuthing: isSigning || isAuthing,
authError,
}
Expand Down
6 changes: 3 additions & 3 deletions centrifuge-app/src/utils/usePodDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { useQuery } from 'react-query'
import { usePodAuth } from './usePodAuth'
import { usePodUrl } from './usePools'

export function usePodDocument(poolId: string, documentId: string | undefined) {
export function usePodDocument(poolId: string, loanId: string, documentId: string | undefined) {
const cent = useCentrifuge()
const podUrl = usePodUrl(poolId)
const { token } = usePodAuth(poolId)
const { token, account } = usePodAuth(poolId)

const query = useQuery(
['podDocument', podUrl, documentId, token],
() => cent.pod.getCommittedDocument([podUrl!, token, documentId!]),
() => account.proxies?.length === 1 ? cent.pod.getCommittedDocument([podUrl!, token, documentId!]) : cent.pod.getInvestorAccess([podUrl!, token, documentId!, poolId!, loanId!]),
{
enabled: !!podUrl && !!documentId && !!token,
}
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@centrifuge/centrifuge-js",
"version": "0.6.0",
"version": "0.7.0",
"description": "",
"homepage": "https://github.com/centrifuge/apps/tree/main/centrifuge-js#readme",
"author": "",
Expand Down
14 changes: 13 additions & 1 deletion centrifuge-js/src/modules/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,20 @@ export function getPodModule() {
return res
}

async function getInvestorAccess(args: [podUrl: string, token: string, documentId: string, poolId: string, loanId: string]) {
const [podUrl, token, asset_id, pool_id, loan_id] = args
const params = new URLSearchParams({
pool_id,
loan_id,
asset_id,
})
const res = await callPod<CommitedDocumentResponse>(podUrl, `/v3/investor/assets?${params}`, 'get', token)
return res
}

async function getSelf(args: [podUrl: string, token: string]) {
const [podUrl, token] = args
const res = await callPod<CommitedDocumentResponse>(podUrl, `v2/accounts/self`, 'get', token)
const res = await callPod(podUrl, `v2/accounts/self`, 'get', token)
return res
}

Expand All @@ -218,6 +229,7 @@ export function getPodModule() {
commitDocumentAndMintNft,
getPendingDocument,
getCommittedDocument,
getInvestorAccess,
awaitJob,
getSelf,
}
Expand Down

0 comments on commit 137a7bc

Please sign in to comment.