Skip to content

Commit

Permalink
Merge pull request #629 from Syn-McJ/fix/large-qr-logo
Browse files Browse the repository at this point in the history
fix: QR isn't recognized
  • Loading branch information
Syn-McJ authored Dec 5, 2023
2 parents ebd0dc8 + db28d99 commit 3a97d65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 44 deletions.
55 changes: 12 additions & 43 deletions DashWallet/Sources/UI/Payments/Receive/Models/DWBaseReceiveModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,9 @@ static CGSize QRCodeSizeRequestAmount(void) {
}
}

static CGSize HoleSize(BOOL hasAmount) {
if (IS_IPAD) {
return CGSizeMake(84.0, 84.0); // 2 + 80(logo size) + 2
}
else if (IS_IPHONE_5_OR_LESS) {
return CGSizeMake(48.0, 48.0);
}
else {
if (hasAmount) {
return CGSizeMake(58.0, 58.0);
}
else {
return CGSizeMake(84.0, 84.0);
}
}
}

static CGSize const LOGO_SMALL_SIZE = {54.0, 54.0};

static BOOL ShouldResizeLogoToSmall(BOOL hasAmount) {
if (IS_IPAD) {
return NO;
}
if (IS_IPHONE_5_OR_LESS) {
return YES;
}
else {
return hasAmount;
}
}

@interface DWBaseReceiveModel ()

@property (readonly, nonatomic, assign) CGSize holeSize;
@property (readonly, nonatomic, assign) CGSize logoSize;

@end

Expand All @@ -106,7 +75,9 @@ - (instancetype)initWithAmount:(uint64_t)amount {
else {
_qrCodeSize = QRCodeSizeBasic();
}
_holeSize = HoleSize(hasAmount);

CGFloat logoSize = _qrCodeSize.height * 0.22;
_logoSize = CGSizeMake(logoSize, logoSize);
}
return self;
}
Expand All @@ -123,15 +94,13 @@ - (UIImage *)qrCodeImageWithRawQRImage:(UIImage *)rawQRImage hasAmount:(BOOL)has
#endif

const BOOL shouldDrawUser = username != nil;

if (ShouldResizeLogoToSmall(hasAmount)) {
if (shouldDrawUser) {
size = LOGO_SMALL_SIZE;
}
else {
overlayImage = [overlayImage dw_resize:LOGO_SMALL_SIZE
withInterpolationQuality:kCGInterpolationHigh];
}

if (shouldDrawUser) {
size = _logoSize;
}
else {
overlayImage = [overlayImage dw_resize:_logoSize
withInterpolationQuality:kCGInterpolationHigh];
}

if (shouldDrawUser) {
Expand Down Expand Up @@ -181,7 +150,7 @@ - (UIImage *)qrCodeImageWithRawQRImage:(UIImage *)rawQRImage hasAmount:(BOOL)has
}

UIImage *resizedImage = [rawQRImage dw_resize:self.qrCodeSize withInterpolationQuality:kCGInterpolationNone];
resizedImage = [resizedImage dw_imageByCuttingHoleInCenterWithSize:self.holeSize];
resizedImage = [resizedImage dw_imageByCuttingHoleInCenterWithSize:self.logoSize];

UIImage *qrCodeImage = [resizedImage dw_imageByMergingWithImage:overlayImage];

Expand Down
2 changes: 1 addition & 1 deletion Shared/Sources/UIImage+Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ + (instancetype)dw_imageWithQRCodeData:(NSData *)data color:(CIColor *)color {
*filter = colorFilter;

[qrFilter setValue:data forKey:@"inputMessage"];
[qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"];
[qrFilter setValue:@"Q" forKey:@"inputCorrectionLevel"];

if (color.alpha > DBL_EPSILON) {
[invertFilter setValue:qrFilter.outputImage forKey:@"inputImage"];
Expand Down

0 comments on commit 3a97d65

Please sign in to comment.