Skip to content

Commit

Permalink
fix: can have successful callback when get balance (#1)
Browse files Browse the repository at this point in the history
* fix: can have successful callback when get balance

* feat: update readme file
  • Loading branch information
winar-jin authored and en committed Sep 22, 2019
1 parent 675af5d commit 2c41d48
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Superfluid Platform

![](https://github.com/polkaworld-org/superfluid/raw/master/apps/packages/app-superfluid/src/images/logo.jpg)
By Team Pacman
## Descriptions
Expand All @@ -17,7 +18,7 @@ By Team Pacman
$ cd pwc-node
$ cargo build --release
$ cargo build -p market-making-tool --release
$ ./target/release/pwc-node--dev
$ ./target/release/pwc-node --dev
$ ./target/release/market-making-tool run --addr 127.0.0.1:9944
$ cd apps
$ yarn
Expand Down
20 changes: 19 additions & 1 deletion apps/packages/app-superfluid/src/componments/Selection/Pool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class Pool extends TxComponent<Props, State> {
params={[assetId, inherentAmount, assetAmount, minLiquidity]}
tx='superfluid.addLiquidity'
ref={this.button}
onSuccess={this.onSuccess}

/> :
<TxButton
accountId={accountId}
Expand All @@ -230,6 +232,7 @@ class Pool extends TxComponent<Props, State> {
params={[assetId, minLiquidity, inherentAmount, assetAmount]}
tx='superfluid.removeLiquidity'
ref={this.button}
onSuccess={this.onSuccess}
/>}
</Button.Group>

Expand All @@ -255,7 +258,7 @@ class Pool extends TxComponent<Props, State> {
const {accountId, api} = this.props
const {inherentAssetId} = this.state
const res = await api.query.superfluid.accountLiquidities([assetId, accountId])

const addRes = await api.query.superfluid.exchangeAccounts(assetId)
const address = addRes.toString()

Expand All @@ -272,6 +275,21 @@ class Pool extends TxComponent<Props, State> {
_.delay(() => this.calcRate('input'), 100)
}

private onSuccess = async (result: any) => {
console.log(result, '===============1===============')
const {api} = this.props
const {inherentAssetId, assetId} = this.state
const addRes = await api.query.superfluid.exchangeAccounts(assetId)
const address = addRes.toString()

const poolAssetBalance = await api.query.superfluid.balances([assetId, address])
const poolInherentBalance = await api.query.superfluid.balances([inherentAssetId, address])
this.setState({
poolAssetBalance: poolAssetBalance.toString(),
poolInherentBalance: poolInherentBalance.toString()
})
}


private onChangeInherentAmount = (e: any): void => {
let inherentAmount = e.target.value
Expand Down
26 changes: 24 additions & 2 deletions apps/packages/app-superfluid/src/componments/Selection/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ const defaultState = {
class Swap extends TxComponent<Props, State> {
public state: State = defaultState

async componentDidMount() {
async componentWillMount() {
const {api} = this.props
let res = await api.query.superfluid.inherentAsset()
const inherentAssetId: number = Number(res.toString())

this.setState({inherentAssetId})
// this.setState({ outputAmount: new BN(0) })
_.delay(async ()=>{
let banlance = await api.query.superfluid.balances([inherentAssetId, this.props.accountId])
let inputBalance = banlance.toString()
console.log(inputBalance,'============')
this.setState({
inputBalance
})
},500)
}

componentWillReceiveProps(nextProps: Props) {
Expand Down Expand Up @@ -142,6 +150,7 @@ class Swap extends TxComponent<Props, State> {
params={[accountId, inputAsset, outputAsset, inputAmount, outputAmount]}
tx='superfluid.swapAssetsWithExactInput'
ref={this.button}
onSuccess={this.onSuccess}
/>
</Button.Group>
</div>
Expand All @@ -150,6 +159,19 @@ class Swap extends TxComponent<Props, State> {
);
}

private onSuccess = async (result: any) => {
// console.log(result)
const {accountId, api} = this.props
const {outputAsset, inputAsset} = this.state
let inputRes = await api.query.superfluid.balances([inputAsset, accountId])
let outputRes = await api.query.superfluid.balances([outputAsset, accountId])
this.setState({
outputBalance:outputRes,
inputBalance:inputRes,

})
}

// 获得费率
private calcRate = async (inputAssetId?: number, outputAssetId?: number, type?: string) => {
let {inherentAssetId, inputAmount = -1, outputAmount = -1} = this.state;
Expand Down

0 comments on commit 2c41d48

Please sign in to comment.