Improve address equality checking

This commit is contained in:
Alexis Sellier
2021-06-11 12:00:53 +02:00
parent 00a0df938c
commit a600f04107
3 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -45,7 +45,7 @@
$: label = name && parseEnsLabel(name, config);
$: isOwner = (org: Org): boolean => {
return org.owner === ($session && $session.address);
return $session ? utils.isAddressEqual(org.owner, $session.address) : false;
};
</script>
+2 -1
View File
@@ -10,6 +10,7 @@
import type { Field } from '@app/Form.svelte';
import { assert } from '@app/error';
import Error from '@app/Error.svelte';
import { isAddressEqual } from '@app/utils';
import { getRegistration } from './registrar';
import type { EnsRecord } from './resolver';
@@ -78,7 +79,7 @@
};
$: isOwner = (registration: Registration): boolean => {
return registration.owner === ($session && $session.address);
return $session ? isAddressEqual(registration.owner, $session.address) : false;
};
</script>
+5 -1
View File
@@ -18,12 +18,16 @@ export interface Safe {
threshold: number;
}
export function isAddressEqual(left: string, right: string): boolean {
return left.toLowerCase() === right.toLowerCase();
}
export function formatBalance(n: BigNumber): string {
return ethers.utils.commify(parseFloat(ethers.utils.formatUnits(n)).toFixed(2));
}
export function formatAddress(addr: string): string {
return formatHash(addr);
return formatHash(ethers.utils.getAddress(addr));
}
export function formatHash(hash: string): string {