Skip to content

Commit

Permalink
Refresh balances when ibc transfer complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunnini committed Jul 27, 2023
1 parent 3141b87 commit 781f6a4
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,45 @@ import { VerticalCollapseTransition } from "../../../../components/transition/ve
export const IbcHistoryView: FunctionComponent<{
isNotReady: boolean;
}> = observer(({ isNotReady }) => {
const { queriesStore } = useStore();

const [histories, setHistories] = useState<IBCTransferHistory[]>([]);
useLayoutEffectOnce(() => {
let count = 0;
const alreadyCompletedHistoryMap = new Map<string, boolean>();

const fn = () => {
const requester = new InExtensionMessageRequester();
const msg = new GetIBCTransferHistories();
requester.sendMessage(BACKGROUND_PORT, msg).then((newHistories) => {
setHistories((histories) => {
if (JSON.stringify(histories) !== JSON.stringify(newHistories)) {
count++;

// Currently there is no elegant way to automatically refresh when an ibc transfer is complete.
// For now, deal with it here
const newCompletes = newHistories.filter((history) => {
if (alreadyCompletedHistoryMap.get(history.id)) {
return false;
}
return !!(
history.txFulfilled &&
!history.ibcHistory.some((h) => !h.completed)
);
});
if (count > 1) {
// There is no need to refresh balance if first time.
for (const newComplete of newCompletes) {
queriesStore
.get(newComplete.destinationChainId)
.queryBalances.getQueryBech32Address(newComplete.recipient)
.fetch();
}
}
for (const newComplete of newCompletes) {
alreadyCompletedHistoryMap.set(newComplete.id, true);
}

return newHistories;
}
return histories;
Expand Down

0 comments on commit 781f6a4

Please sign in to comment.