It is legal, in that if you and the seller both agree to it, such a clause is permissible and enforceable. Whether it is "realistic" is another story: it is difficult to see why the seller would agree to make the sale dependent on visa approval, when that is something so far beyond his control and where he can't even set any realistic time frame on it. But if the seller does agree, this is legal.