Skip to content

Commit

Permalink
Merge branch 'pending-changes' of ssh://github.com/centrifuge/apps in…
Browse files Browse the repository at this point in the history
…to pending-changes
  • Loading branch information
onnovisser committed Oct 10, 2023
2 parents 1ea812d + ea1de81 commit e10e0b7
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 153 deletions.
5 changes: 0 additions & 5 deletions .github/actions/prepare-deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ runs:
echo "function_name=${{ inputs.app_base_name }}-demo" >> $GITHUB_OUTPUT
echo "front_url=${{ inputs.app_base_name }}-demo.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=demo" >> $GITHUB_OUTPUT
elif ${{ contains(inputs.deploy_to, 'moonbeam-alpha') }}; then
# moonbeam-alpha
echo "function_name=${{ inputs.app_base_name }}-moonbeam-alpha" >> $GITHUB_OUTPUT
echo "front_url=${{ inputs.app_base_name }}-moonbeam-alpha.k-f.dev" >> $GITHUB_OUTPUT
echo "env_name=moonbeam-alpha" >> $GITHUB_OUTPUT
elif ${{ github.ref == 'refs/heads/main' }}; then
# DEV
echo "function_name=${{ inputs.app_base_name }}-dev" >> $GITHUB_OUTPUT
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/moonbeam-alpha-deploy.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ yarn-error.log
!.env.demo
!.env.catalyst
!.env.production
!.env.moonbeam-alpha
6 changes: 3 additions & 3 deletions centrifuge-app/.env-config/.env.demo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
REACT_APP_COLLATOR_WSS_URL=wss://fullnode.algol.cntrfg.com/public-ws
REACT_APP_DEFAULT_NODE_URL=https://pod.algol.k-f.dev
REACT_APP_COLLATOR_WSS_URL=wss://fullnode.moonbase-dev.cntrfg.com/public-ws
REACT_APP_DEFAULT_NODE_URL=https://pod.moonbeam-alpha.k-f.dev
REACT_APP_DEFAULT_UNLIST_POOLS=true
REACT_APP_FAUCET_URL=https://europe-central2-peak-vista-185616.cloudfunctions.net/faucet-api-demo
REACT_APP_IPFS_GATEWAY=https://centrifuge.mypinata.cloud/
REACT_APP_IS_DEMO=true
REACT_APP_ONBOARDING_API_URL=https://europe-central2-peak-vista-185616.cloudfunctions.net/onboarding-api-demo
REACT_APP_PINNING_API_URL=https://europe-central2-peak-vista-185616.cloudfunctions.net/pinning-api-demo
REACT_APP_POOL_CREATION_TYPE=immediate
REACT_APP_RELAY_WSS_URL=wss://fullnode-relay.algol.cntrfg.com/public-ws
REACT_APP_RELAY_WSS_URL=wss://frag-moonbase-relay-rpc-ws.g.moonbase.moonbeam.network
REACT_APP_SUBQUERY_URL=https://api.subquery.network/sq/centrifuge/pools-demo
REACT_APP_SUBSCAN_URL=
REACT_APP_TINLAKE_NETWORK=goerli
Expand Down
20 changes: 0 additions & 20 deletions centrifuge-app/.env-config/.env.moonbeam-alpha

This file was deleted.

24 changes: 4 additions & 20 deletions centrifuge-app/src/pages/Onboarding/queries/useSignRemark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const useSignRemark = (
{
txHash: string
blockNumber: string
isEvmOnSubstrate?: boolean
chainId: Network
},
unknown
Expand All @@ -52,29 +51,13 @@ export const useSignRemark = (
const substrateMutation = useCentrifugeTransaction('Sign remark', (cent) => cent.remark.signRemark, {
onSuccess: async (_, result) => {
try {
let txHash: string
let blockNumber: string
// @ts-expect-error
if (isEvmOnSubstrate && result?.[0]?.wait) {
// @ts-expect-error
const evmResult = await result[0].wait()
txHash = evmResult?.transactionHash
blockNumber = evmResult?.blockNumber.toString()
} else {
txHash = result.txHash.toHex()
// @ts-expect-error
blockNumber = result.blockNumber.toString()
}
const chainId = connectedNetwork === 'centrifuge' ? await centrifuge.getChainId() : connectedNetwork

await sendDocumentsToIssuer({
txHash,
blockNumber,
isEvmOnSubstrate,
txHash: result.txHash,
blockNumber: result.blockNumber.toString(),
chainId: chainId || 136,
})
setIsSubstrateTxLoading(false)
} catch (e) {
} finally {
setIsSubstrateTxLoading(false)
}
},
Expand Down Expand Up @@ -151,6 +134,7 @@ export const useSignRemark = (
}
}
executePaymentInfo()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [centrifuge, selectedAccount])

const signEvmRemark = async (args: [message: string]) => {
Expand Down
3 changes: 2 additions & 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.5.0",
"version": "0.6.0",
"description": "",
"homepage": "https://github.com/centrifuge/apps/tree/main/centrifuge-js#readme",
"author": "",
Expand All @@ -18,6 +18,7 @@
"start": "run-p -l start:esbuild start:types",
"start:esbuild": "node ./esbuild watch",
"start:types": "tsc --watch --emitDeclarationOnly --outDir dist",
"prepare": "yarn build",
"build": "yarn clean && yarn build:esbuild && yarn build:types",
"build:esbuild": "node ./esbuild",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
Expand Down
71 changes: 42 additions & 29 deletions centrifuge-js/src/CentrifugeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
throwError,
} from 'rxjs'
import { fromFetch } from 'rxjs/fetch'
import { TransactionOptions } from './types'
import { TransactionErrorResult, TransactionOptions, TransactionResult } from './types'
import { computeMultisig, evmToSubstrateAddress, isSameAddress } from './utils'
import { CurrencyBalance } from './utils/BN'
import { getPolkadotApi } from './utils/web3'
Expand Down Expand Up @@ -293,7 +293,7 @@ export class CentrifugeBase {

try {
const $paymentInfo = submittable.paymentInfo(signingAddress)
const $balances = api.query.system.account(signingAddress)
const $balances = api.query.system.account(this.getSignerAddress())

if (options?.paymentInfo) {
return $paymentInfo.pipe(
Expand Down Expand Up @@ -334,11 +334,7 @@ export class CentrifugeBase {
switchMap(() => actualSubmittable.signAndSend(signingAddress, { signer, era: options?.era }))
)
).pipe(
tap((result) => {
options?.onStatusChange?.(result)
if (result.status.isInBlock) this.getTxCompletedEvents().next(result.events)
}),
takeWhile((result) => {
map((result) => {
const errors = result.events.filter(({ event }) => {
const possibleProxyErr = event.data[0]?.toHuman()
return (
Expand All @@ -352,9 +348,21 @@ export class CentrifugeBase {
if (errors.length && this.config.debug) {
console.log('🚨 error', JSON.stringify(errors))
}
const hasError = !!(result.dispatchError || errors.length)

return !result.status.isInBlock && !hasError
return {
data: result,
events: result.events,
status: result.status.type,
error: result.dispatchError || errors[0],
txHash: result.txHash.toHuman() as string,
blockNumber: (result as any).blockNumber ? Number((result as any).blockNumber?.toString()) : undefined,
}
}),
tap((result) => {
options?.onStatusChange?.(result)
if (result.status === 'InBlock') this.getTxCompletedEvents().next(result.events)
}),
takeWhile((result) => {
return result.status !== 'InBlock' && !result.error
}, true)
)
} catch (e) {
Expand Down Expand Up @@ -387,26 +395,31 @@ export class CentrifugeBase {
return from(response.wait()).pipe(
map((receipt) => [response, receipt] as const),
startWith([response, null] as const),
catchError(() => of([{ ...response, error: new Error('failed') }] as const)),
tap(([result, receipt]) => {
if ('error' in result || receipt?.status === 0) {
options?.onStatusChange?.({
events: [],
dispatchError: {},
status: {
hash: { toHex: () => result.hash as any },
},
} as any)
} else {
options?.onStatusChange?.({
events: [],
status: {
isInBlock: receipt?.status === 1,
isFinalized: receipt?.status === 1,
hash: { toHex: () => result.hash as any },
},
} as any)
map(([response, receipt]) => {
const result: TransactionResult = {
data: { response, receipt: receipt ?? undefined },
// TODO: Events
events: [],
status: receipt ? 'InBlock' : 'Broadcast',
error: receipt?.status === 0 ? new Error('failed') : undefined,
txHash: response.hash,
blockNumber: receipt?.blockNumber,
}
return result
}),
catchError(() => {
const result: TransactionErrorResult = {
data: { response, receipt: undefined },
events: [],
status: 'Invalid',
error: new Error('failed'),
txHash: response.hash,
blockNumber: undefined,
}
return of(result)
}),
tap((result) => {
options?.onStatusChange?.(result)
})
)
})
Expand Down
25 changes: 24 additions & 1 deletion centrifuge-js/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
import {
TransactionReceipt as EvmTransactionReceipt,
TransactionResponse as EvmTransactionResponse,
} from '@ethersproject/providers'
import { AddressOrPair } from '@polkadot/api/types'
import { ISubmittableResult } from '@polkadot/types/types'
import { HexString } from '@polkadot/util/types'
import BN from 'bn.js'
import { Config } from '../CentrifugeBase'

type EvmTransactionResult = {
response: EvmTransactionResponse
receipt?: EvmTransactionReceipt
}

type TransactionResultBase = {
data: ISubmittableResult | EvmTransactionResult
events: ISubmittableResult['events']
status: ISubmittableResult['status']['type']
txHash: string
blockNumber?: number
error: any
}

export type TransactionPendingResult = TransactionResultBase & { error: null; blockNumber: undefined }
export type TransactionSuccessResult = TransactionResultBase & { error: null; blockNumber: number }
export type TransactionErrorResult = TransactionResultBase & { error: any; blockNumber: undefined }
export type TransactionResult = TransactionPendingResult | TransactionSuccessResult | TransactionErrorResult

export type TransactionOptions = {
batch?: boolean
signOnly?: boolean
sendOnly?: boolean
era?: number
paymentInfo?: AddressOrPair
onStatusChange?: (result: ISubmittableResult) => void
onStatusChange?: (result: TransactionResult) => void
createType?: 'immediate' | 'propose' | 'notePreimage'
dryRun?: boolean
proxies?: Config['proxies']
Expand Down
18 changes: 18 additions & 0 deletions centrifuge-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 0.2.0 (2023-10-03)


### ⚠ BREAKING CHANGES

* **centrifuge-js:** Centrifuge->getChainId() now returns a Promise

### Features

* implement global onboarding status endpoint ([#1364](https://github.com/centrifuge/apps/issues/1364)) ([b64db29](https://github.com/centrifuge/apps/commit/b64db2904ad670aa012bb9a69396bf28ab31d5d7))


### Bug Fixes

* autoconnect wallet when visiting through gnosis safe app ([#1375](https://github.com/centrifuge/apps/issues/1375)) ([0991b30](https://github.com/centrifuge/apps/commit/0991b30ee0ffead4b1799496f49a7401c6371a14))
* **centrifuge-js:** Get chain ID from chain ([#1535](https://github.com/centrifuge/apps/issues/1535)) ([e36462f](https://github.com/centrifuge/apps/commit/e36462fcc58589830f9fb9a68e0ba11302b1eb6e))
* **centrifuge-react:** Add useBalances hook ([#1092](https://github.com/centrifuge/apps/issues/1092)) ([2eef4e1](https://github.com/centrifuge/apps/commit/2eef4e133cac560f62b6db0023b23875563e03cf))

### [0.1.1](https://github.com/centrifuge/apps/compare/centrifuge-react/v0.1.0...centrifuge-react/v0.1.1) (2023-09-28)


Expand Down
5 changes: 3 additions & 2 deletions centrifuge-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@centrifuge/centrifuge-react",
"version": "0.1.1",
"version": "0.2.0",
"description": "Centrifuge React Library",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
Expand All @@ -9,7 +9,8 @@
],
"scripts": {
"build": "tsc",
"prepare": "yarn build",
"build:deps": "cd ../centrifuge-js && yarn build && cd ../fabric && yarn build && cd ../centrifuge-react",
"prepare": "yarn build:deps && yarn build",
"bump": "standard-version --sign",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
Expand Down
Loading

0 comments on commit e10e0b7

Please sign in to comment.