Skip to content

Commit

Permalink
Merge pull request #70 from Giveth/hotfix/token-disto-balance-user-re…
Browse files Browse the repository at this point in the history
…lation

Hotfix in TokenDistroBalance
  • Loading branch information
aminlatifi authored Mar 8, 2024
2 parents c10889a + aa7fd80 commit 3e9895b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/mappings/tokenDistro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,10 @@ export function handleChangeAddress(event: ChangeAddress): void {
event.address.toHex(),
event.params.oldAddress.toHex(),
);
if (!oldBalance) {
log.debug('Change Address oldAddress {} balance is null!', [
event.params.oldAddress.toHex(),
]);
return;
}
let newBalance = getTokenDistroBalance(
const newBalance = getTokenDistroBalance(
event.address.toHex(),
event.params.newAddress.toHex(),
);
if (!newBalance) {
newBalance = new TokenDistroBalance(event.params.newAddress.toHex());
}

// New Address allocatedTokens amount should be zero
newBalance.allocatedTokens = newBalance.allocatedTokens.plus(
Expand Down
3 changes: 3 additions & 0 deletions src/utils/tokenDistroHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../types/schema';
import { Address, BigInt, log } from '@graphprotocol/graph-ts';
import { TokenDistro as TokenDistroContract } from '../types/TokenDistro/TokenDistro';
import { getUserEntity } from './misc';
export function saveTokenAllocation(
recipient: string,
txHash: string,
Expand Down Expand Up @@ -39,6 +40,8 @@ export function getTokenDistroBalance(
const id = tokenDistro + '-' + userAddress;
let tokenDistroBalance = TokenDistroBalance.load(id);

getUserEntity(Address.fromString(userAddress));

if (!tokenDistroBalance) {
tokenDistroBalance = new TokenDistroBalance(id);
tokenDistroBalance.user = userAddress;
Expand Down

0 comments on commit 3e9895b

Please sign in to comment.