-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
--- | ||
"@coinbase/onchainkit": minor | ||
--- | ||
|
||
- **feat**: Moved the `onError` and `onSuccess` lifecycle listeners from the `<SwapButton>` component to the `<Swap>` component. By @zizzamia #1139 | ||
|
||
Breaking Changes | ||
OnchainKit standardizes lifecycle listeners with three callbacks: `onError`, `onSuccess`, and `onStatus`. The `onError` and `onSuccess` callbacks handle only the `error` and `success` states, respectively. In contrast, the `onStatus` callback provides more granular phases of each component's experience. | ||
|
||
Before, we used `onError` and `onSuccess` in the `<SwapButton />` component. | ||
```ts | ||
const handleOnError = useCallback((error) => { | ||
console.log(error); | ||
}, []); | ||
|
||
const handleOnSuccess = useCallback((response) => { | ||
console.log(response); | ||
}, []); | ||
|
||
... | ||
|
||
<Swap address={address}> | ||
<SwapAmountInput | ||
label="Sell" | ||
swappableTokens={swappableTokens} | ||
token={ETHToken} | ||
type="from" | ||
/> | ||
<SwapToggleButton /> | ||
<SwapAmountInput | ||
label="Buy" | ||
swappableTokens={swappableTokens} | ||
token={USDCToken} | ||
type="to" | ||
/> | ||
<SwapButton | ||
onError={handleOnError} | ||
onSuccess={handleOnSuccess} | ||
/> | ||
<SwapMessage /> | ||
</Swap> | ||
``` | ||
|
||
After, we use `onStatus` in the `<Swap />` component. | ||
```ts | ||
const handleOnStatus = useCallback((lifeCycleStatus: LifeCycleStatus) => { | ||
console.log('Status:', lifeCycleStatus); | ||
}, []); | ||
|
||
... | ||
|
||
<Swap | ||
address={address} | ||
onStatus={handleOnStatus} | ||
> | ||
<SwapAmountInput | ||
label="Sell" | ||
swappableTokens={swappableTokens} | ||
token={ETHToken} | ||
type="from" | ||
/> | ||
<SwapToggleButton /> | ||
<SwapAmountInput | ||
label="Buy" | ||
swappableTokens={swappableTokens} | ||
token={USDCToken} | ||
type="to" | ||
/> | ||
<SwapButton /> | ||
<SwapMessage /> | ||
</Swap> | ||
``` | ||
|
||
The `onStatus` callback will expose | ||
```ts | ||
export type LifeCycleStatus = | ||
| { | ||
statusName: 'init'; | ||
statusData: null; | ||
} | ||
| { | ||
statusName: 'error'; | ||
statusData: SwapError; | ||
} | ||
| { | ||
statusName: 'amountChange'; | ||
statusData: null; | ||
} | ||
| { | ||
statusName: 'transactionPending'; | ||
statusData: null; | ||
} | ||
| { | ||
statusName: 'transactionApproved'; | ||
statusData: { | ||
transactionHash: Hex; | ||
transactionType: 'ERC20' | 'Permit2'; | ||
}; | ||
} | ||
| { | ||
statusName: 'success'; | ||
statusData: { | ||
transactionReceipt: TransactionReceipt; | ||
}; | ||
}; | ||
``` |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1 +1 @@ | ||
export const version = '0.29.5'; | ||
export const version = '0.30.0'; |